diff options
Diffstat (limited to 'extensions/LocalisationUpdate/tests/phpunit/reader')
-rw-r--r-- | extensions/LocalisationUpdate/tests/phpunit/reader/JSONReaderTest.php | 37 | ||||
-rw-r--r-- | extensions/LocalisationUpdate/tests/phpunit/reader/ReaderFactoryTest.php | 38 |
2 files changed, 75 insertions, 0 deletions
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', + ), + ); + } +} |