X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/extensions/LocalisationUpdate/tests/phpunit/UpdaterTest.php diff --git a/extensions/LocalisationUpdate/tests/phpunit/UpdaterTest.php b/extensions/LocalisationUpdate/tests/phpunit/UpdaterTest.php new file mode 100644 index 00000000..d3154033 --- /dev/null +++ b/extensions/LocalisationUpdate/tests/phpunit/UpdaterTest.php @@ -0,0 +1,82 @@ +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 Updater(); + $repos = [ 'main' => 'file:///repos/%NAME%/%SOME-VAR%' ]; + + $info = [ + '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 Updater(); + + $input = [ 'file' => 'Hello World!' ]; + $output = [ 'en' => [ 'key' => $input['file'] ] ]; + + $reader = $this->getMock( 'LocalisationUpdate\Reader' ); + $reader + ->expects( $this->once() ) + ->method( 'parse' ) + ->will( $this->returnValue( $output ) ); + + $factory = $this->getMock( 'LocalisationUpdate\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 Updater(); + + $origin = [ + 'A' => '1', + 'C' => '3', + 'D' => '4', + ]; + $remote = [ + 'A' => '1', // No change key + 'B' => '2', // New key + 'C' => '33', // Changed key + 'D' => '44', // Blacklisted key + ]; + $blacklist = [ 'D' => 0 ]; + $expected = [ 'B' => '2', 'C' => '33' ]; + $observed = $updater->findChangedTranslations( $origin, $remote, $blacklist ); + $this->assertEquals( $expected, $observed, 'Changed and new keys returned' ); + } +}