diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-04-01 06:11:44 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-04-01 06:11:44 +0200 |
commit | 14f74d141ab5580688bfd46d2f74c026e43ed967 (patch) | |
tree | 081b7cbfc4d246ecc42831978d080331267cf57c /extensions/LocalisationUpdate/tests/phpunit | |
parent | 4a953b6bfda28604979feb9cfbb58974d13b84bb (diff) |
Update to MediaWiki 1.24.2
Diffstat (limited to 'extensions/LocalisationUpdate/tests/phpunit')
5 files changed, 237 insertions, 0 deletions
diff --git a/extensions/LocalisationUpdate/tests/phpunit/Makefile b/extensions/LocalisationUpdate/tests/phpunit/Makefile new file mode 100644 index 00000000..e98c12ca --- /dev/null +++ b/extensions/LocalisationUpdate/tests/phpunit/Makefile @@ -0,0 +1,12 @@ +ifndef MW_INSTALL_PATH + MW_INSTALL_PATH=../../../.. +endif + +DIRS=reader + +default: + php ${MW_INSTALL_PATH}/tests/phpunit/phpunit.php . + +.PHONY: *Test.php $(DIRS) +*Test.php $(DIRS): + php ${MW_INSTALL_PATH}/tests/phpunit/phpunit.php $@ diff --git a/extensions/LocalisationUpdate/tests/phpunit/UpdaterTest.php b/extensions/LocalisationUpdate/tests/phpunit/UpdaterTest.php new file mode 100644 index 00000000..ce742cba --- /dev/null +++ b/extensions/LocalisationUpdate/tests/phpunit/UpdaterTest.php @@ -0,0 +1,80 @@ +<?php +/** + * @file + * @author Niklas Laxström + * @license GPL-2.0+ + */ + +class LU_UpdaterTest extends MediaWikiTestCase { + public function testIsDirectory() { + $updater = new LU_Updater(); + + $this->assertTrue( + $updater->isDirectory( '/IP/extensions/Translate/i18n/*.json' ), + 'Extension json files are a file pattern' + ); + + $this->assertFalse( + $updater->isDirectory( '/IP/extensions/Translate/Translate.i18n.php' ), + 'Extension php file is not a pattern' + ); + } + + public function testExpandRemotePath() { + $updater = new LU_Updater(); + $repos = array( 'main' => 'file:///repos/%NAME%/%SOME-VAR%' ); + + $info = array( + 'repo' => 'main', + 'name' => 'product', + 'some-var' => 'file', + ); + $this->assertEquals( + 'file:///repos/product/file', + $updater->expandRemotePath( $info, $repos ), + 'Variables are expanded correctly' + ); + } + + public function testReadMessages() { + $updater = $updater = new LU_Updater(); + + $input = array( 'file' => 'Hello World!' ); + $output = array( 'en' => array( 'key' => $input['file'] ) ); + + $reader = $this->getMock( 'LU_Reader' ); + $reader + ->expects( $this->once() ) + ->method( 'parse' ) + ->will( $this->returnValue( $output ) ); + + $factory = $this->getMock( 'LU_ReaderFactory' ); + $factory + ->expects( $this->once() ) + ->method( 'getReader' ) + ->will( $this->returnValue( $reader ) ); + + $observed = $updater->readMessages( $factory, $input ); + $this->assertEquals( $output, $observed, 'Tries to parse given file' ); + } + + public function testFindChangedTranslations() { + $updater = $updater = new LU_Updater(); + + $origin = array( + 'A' => '1', + 'C' => '3', + 'D' => '4', + ); + $remote = array( + 'A' => '1', // No change key + 'B' => '2', // New key + 'C' => '33', // Changed key + 'D' => '44', // Blacklisted key + ); + $blacklist = array( 'D' => 0 ); + $expected = array( 'B' => '2', 'C' => '33' ); + $observed = $updater->findChangedTranslations( $origin, $remote, $blacklist ); + $this->assertEquals( $expected, $observed, 'Changed and new keys returned' ); + } +} diff --git a/extensions/LocalisationUpdate/tests/phpunit/finder/FinderTest.php b/extensions/LocalisationUpdate/tests/phpunit/finder/FinderTest.php new file mode 100644 index 00000000..8cc0f7d7 --- /dev/null +++ b/extensions/LocalisationUpdate/tests/phpunit/finder/FinderTest.php @@ -0,0 +1,70 @@ +<?php +/** + * @file + * @author Niklas Laxström + * @license GPL-2.0+ + */ + +class LU_FinderTest extends MediaWikiTestCase { + public function testGetComponents() { + $finder = new LU_Finder( + array( + 'TranslateSearch' => '/IP/extensions/Translate/TranslateSearch.i18n.php', + 'Babel' => '/IP/extensions/Babel/Babel.i18n.php', + ), + array( + 'Babel' => '/IP/extensions/Babel/i18n', + 'Door' => array( + 'core' => '/IP/extensions/Door/i18n/core', + 'extra' => '/IP/extensions/Door/i18n/extra', + ), + ), + '/IP' + ); + $observed = $finder->getComponents(); + + $expected = array( + 'repo' => 'mediawiki', + 'orig' => "file:///IP/languages/messages/Messages*.php", + 'path' => 'languages/messages/Messages*.php', + ); + $this->assertArrayHasKey( 'core', $observed ); + $this->assertSame( $expected, $observed['core'], 'Core php file' ); + + $expected = array( + 'repo' => 'extension', + 'name' => 'Translate', + 'orig' => 'file:///IP/extensions/Translate/TranslateSearch.i18n.php', + 'path' => 'TranslateSearch.i18n.php' + ); + $this->assertArrayHasKey( 'TranslateSearch', $observed ); + $this->assertSame( $expected, $observed['TranslateSearch'], 'PHP only extension' ); + + $expected = array( + 'repo' => 'extension', + 'name' => 'Babel', + 'orig' => 'file:///IP/extensions/Babel/i18n/*.json', + 'path' => 'i18n/*.json' + ); + $this->assertArrayHasKey( 'Babel-0', $observed ); + $this->assertSame( $expected, $observed['Babel-0'], 'PHP&JSON extension' ); + + $expected = array( + 'repo' => 'extension', + 'name' => 'Door', + 'orig' => 'file:///IP/extensions/Door/i18n/core/*.json', + 'path' => 'i18n/core/*.json' + ); + $this->assertArrayHasKey( 'Door-core', $observed ); + $this->assertSame( $expected, $observed['Door-core'], 'Multidir json extension' ); + + $expected = array( + 'repo' => 'extension', + 'name' => 'Door', + 'orig' => 'file:///IP/extensions/Door/i18n/extra/*.json', + 'path' => 'i18n/extra/*.json' + ); + $this->assertArrayHasKey( 'Door-extra', $observed ); + $this->assertSame( $expected, $observed['Door-extra'], 'Multidir json extension' ); + } +} diff --git a/extensions/LocalisationUpdate/tests/phpunit/reader/JSONReaderTest.php b/extensions/LocalisationUpdate/tests/phpunit/reader/JSONReaderTest.php new file mode 100644 index 00000000..4bb53af9 --- /dev/null +++ b/extensions/LocalisationUpdate/tests/phpunit/reader/JSONReaderTest.php @@ -0,0 +1,37 @@ +<?php +/** + * @file + * @author Niklas Laxström + * @license GPL-2.0+ + */ + +class LU_JSONReaderTest extends MediaWikiTestCase { + /** + * @dataProvider parseProvider + */ + public function testParse( $input, $expected, $comment ) { + $reader = new LU_JSONReader( 'xx' ); + $observed = $reader->parse( $input ); + $this->assertEquals( $expected, $observed['xx'], $comment ); + } + + public function parseProvider() { + return array( + array( + '{}', + array(), + 'empty file', + ), + array( + '{"key":"value"}', + array( 'key' => 'value' ), + 'file with one string', + ), + array( + '{"@metadata":{"authors":["Nike"]},"key":"value2"}', + array( 'key' => 'value2' ), + '@metadata is ignored', + ) + ); + } +} diff --git a/extensions/LocalisationUpdate/tests/phpunit/reader/ReaderFactoryTest.php b/extensions/LocalisationUpdate/tests/phpunit/reader/ReaderFactoryTest.php new file mode 100644 index 00000000..ee155b3a --- /dev/null +++ b/extensions/LocalisationUpdate/tests/phpunit/reader/ReaderFactoryTest.php @@ -0,0 +1,38 @@ +<?php +/** + * @file + * @author Niklas Laxström + * @license GPL-2.0+ + */ + +class LU_ReaderFactoryTest extends MediaWikiTestCase { + /** + * @dataProvider getReaderProvider + */ + public function testGetReader( $input, $expected, $comment ) { + $factory = new LU_ReaderFactory(); + $reader = $factory->getReader( $input ); + $observed = get_class( $reader ); + $this->assertEquals( $expected, $observed, $comment ); + } + + public function getReaderProvider() { + return array( + array( + 'languages/messages/MessagesFi.php', + 'LU_PHPReader', + 'core php file', + ), + array( + 'extensions/Translate/Translate.i18n.php', + 'LU_PHPReader', + 'extension php file', + ), + array( + 'extension/Translate/i18n/core/de.json', + 'LU_JSONReader', + 'extension json file', + ), + ); + } +} |