summaryrefslogtreecommitdiff
blob: a2dc72eb75992c730921622f80fdb9455a486c9f (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
<?php

/**
 * Test for parsing the special definition file for mediawiki-extensions
 * @author Niklas Laxström
 * @license GPL-2.0-or-later
 */
class MediaWikiExtensionsTest extends PHPUnit\Framework\TestCase {
	/**
	 * @requires function yaml_parse
	 * @covers PremadeMediawikiExtensionGroups
	 */
	public function testParsing() {
		$defs = __DIR__ . '/../data/mediawiki-extensions.txt';
		$path = '%GROUPROOT%/mediawiki-extensions/extensions';
		$foo = new PremadeMediawikiExtensionGroups( $defs, $path );
		$list = $deps = $autoload = [];
		$foo->register( $list, $deps, $autoload );

		$this->assertCount( 1, $deps, 'A dependency to definition file was added' );
		$this->assertCount( 5, $list, 'Right number of groups were created' );

		$this->assertArrayHasKey( 'ext-wikimediamessages', $list );
		$expected = TranslateYaml::load( __DIR__ . '/../data/MediaWikiExtensionTest-conf2.yaml' );
		$this->assertEquals( $expected, $list['ext-wikimediamessages']->getConfiguration() );

		$this->assertArrayHasKey( 'ext-examplejsonextension', $list );
		$expected = TranslateYaml::load( __DIR__ . '/../data/MediaWikiExtensionTest-conf3.yaml' );
		$this->assertEquals( $expected, $list['ext-examplejsonextension']->getConfiguration() );

		$this->assertArrayHasKey( 'ext-exampleextension2', $list );
		$expected = TranslateYaml::load( __DIR__ . '/../data/MediaWikiExtensionTest-conf4.yaml' );
		$this->assertEquals( $expected, $list['ext-exampleextension2']->getConfiguration() );

		$this->assertArrayHasKey( 'ext-languagesmodified', $list );
		$languages = $list['ext-languagesmodified']->getTranslatableLanguages();
		$this->assertArrayHasKey( 'foo', $languages, 'Included language is available' );
		$this->assertArrayNotHasKey( 'bar', $languages, 'Excluded language is not available' );
		$this->assertArrayHasKey( 'de', $languages, 'Default language is available' );

		$this->assertArrayHasKey( 'ext-languagesset', $list );
		$languages = $list['ext-languagesset']->getTranslatableLanguages();
		$this->assertArrayHasKey( 'foo', $languages, 'Set language is available' );
		$this->assertArrayNotHasKey( 'de', $languages, 'Unset language is not available' );
	}
}