MediaWiki REL1_33
UpdaterTest.php
Go to the documentation of this file.
1<?php
8namespace LocalisationUpdate;
9
10use PHPUnit4And6Compat;
11
15class UpdaterTest extends \PHPUnit\Framework\TestCase {
16 use PHPUnit4And6Compat;
17
18 public function testIsDirectory() {
19 $updater = new Updater();
20
21 $this->assertTrue(
22 $updater->isDirectory( '/IP/extensions/Translate/i18n/*.json' ),
23 'Extension json files are a file pattern'
24 );
25
26 $this->assertFalse(
27 $updater->isDirectory( '/IP/extensions/Translate/Translate.i18n.php' ),
28 'Extension php file is not a pattern'
29 );
30 }
31
32 public function testExpandRemotePath() {
33 $updater = new Updater();
34 $repos = [ 'main' => 'file:///repos/%NAME%/%SOME-VAR%' ];
35
36 $info = [
37 'repo' => 'main',
38 'name' => 'product',
39 'some-var' => 'file',
40 ];
41 $this->assertEquals(
42 'file:///repos/product/file',
43 $updater->expandRemotePath( $info, $repos ),
44 'Variables are expanded correctly'
45 );
46 }
47
48 public function testReadMessages() {
49 $updater = $updater = new Updater();
50
51 $input = [ 'file' => 'Hello World!' ];
52 $output = [ 'en' => [ 'key' => $input['file'] ] ];
53
54 $reader = $this->getMock( 'LocalisationUpdate\Reader' );
55 $reader
56 ->expects( $this->once() )
57 ->method( 'parse' )
58 ->will( $this->returnValue( $output ) );
59
60 $factory = $this->getMock( 'LocalisationUpdate\ReaderFactory' );
61 $factory
62 ->expects( $this->once() )
63 ->method( 'getReader' )
64 ->will( $this->returnValue( $reader ) );
65
66 $observed = $updater->readMessages( $factory, $input );
67 $this->assertEquals( $output, $observed, 'Tries to parse given file' );
68 }
69
70 public function testFindChangedTranslations() {
71 $updater = $updater = new Updater();
72
73 $origin = [
74 'A' => '1',
75 'C' => '3',
76 'D' => '4',
77 ];
78 $remote = [
79 'A' => '1', // No change key
80 'B' => '2', // New key
81 'C' => '33', // Changed key
82 'D' => '44', // Blacklisted key
83 ];
84 $blacklist = [ 'D' => 0 ];
85 $expected = [ 'B' => '2', 'C' => '33' ];
86 $observed = $updater->findChangedTranslations( $origin, $remote, $blacklist );
87 $this->assertEquals( $expected, $observed, 'Changed and new keys returned' );
88 }
89}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
\LocalisationUpdate\Updater
Executes the localisation update.
Definition Updater.php:13
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2272
$page->newPageUpdater($user) $updater
if(is_array($mode)) switch( $mode) $input