summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/System/I18nMsgKeyIntegrityTest.php
blob: 8804fd41432963fa6075225fd2e9d53b3699e1b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php

namespace SMW\Tests\System;

use SMW\Tests\Utils\UtilityFactory;

/**
 * @group semantic-mediawiki
 * @group system-test
 *
 * @license GNU GPL v2+
 * @since 3.0
 *
 * @author mwjames
 */
class I18nMsgKeyIntegrityTest extends \PHPUnit_Framework_TestCase {

	/**
	 * @dataProvider mediawikiI18nFileProvider
	 */
	public function testDecKiloSeparatorMsgKeySetting( $file ) {

		$jsonFileReader = UtilityFactory::getInstance()->newJsonFileReader( $file );
		$contents = $jsonFileReader->read();

		$isComplete = true;

		if ( isset( $contents['smw_decseparator'] ) ) {
			$isComplete = isset( $contents['smw_kiloseparator'] );
		}

		if ( $isComplete && isset( $contents['smw_kiloseparator'] ) ) {
			$isComplete = isset( $contents['smw_decseparator'] );
		}

		$this->assertTrue(
			$isComplete,
			'Failed on ' . basename( $file ) . ' with an incomplete pair of smw_decseparator/smw_kiloseparator.'
		);
	}

	/**
	 * @dataProvider mediawikiI18nFileProvider
	 */
	public function testDecKiloSeparatorHasDifferentValue( $file ) {

		$jsonFileReader = UtilityFactory::getInstance()->newJsonFileReader( $file );
		$contents = $jsonFileReader->read();

		$hasDifferentSeparatorValue = true;

		// Test on whether the values are different, otherwise fail
		if ( isset( $contents['smw_kiloseparator'] ) && isset( $contents['smw_decseparator'] ) ) {
			$hasDifferentSeparatorValue = $contents['smw_kiloseparator'] != $contents['smw_decseparator'];
		}

		$this->assertTrue(
			$hasDifferentSeparatorValue,
			'Failed on ' . basename( $file ) . ' where smw_decseparator/smw_kiloseparator have the same set of values.'
		);
	}

	public function mediawikiI18nFileProvider() {
		return $this->findFilesIn( $GLOBALS['wgMessagesDirs']['SemanticMediaWiki'] );
	}

	private function findFilesIn( $location ) {

		$provider = [];

		$bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider( $location );
		$bulkFileProvider->searchByFileExtension( 'json' );

		foreach ( $bulkFileProvider->getFiles() as $id => $file ) {
			$provider[$id] = [ $file ];
		}

		return $provider;
	}

}