diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:17:42 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:17:42 -0400 |
commit | f7d4cf9ed0ae68fec630d14e8f6aade38e49f036 (patch) | |
tree | a730c57badbe0e2f0f064ca2006c82d4b6ed54ea /extensions/LocalisationUpdate/tests/phpunit/UpdaterTest.php | |
parent | aee35e4a93d105024bcae947cd8b16c962191f5c (diff) | |
parent | 5d1e7dd0ccda0984ccf3e8e3d0f88ac888b05819 (diff) |
Merge commit '5d1e7'
Diffstat (limited to 'extensions/LocalisationUpdate/tests/phpunit/UpdaterTest.php')
-rw-r--r-- | extensions/LocalisationUpdate/tests/phpunit/UpdaterTest.php | 80 |
1 files changed, 80 insertions, 0 deletions
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' ); + } +} |