MediaWiki REL1_31
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}
\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 after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2255
if(is_array($mode)) switch( $mode) $input