MediaWiki  1.33.0
UpdaterTest.php
Go to the documentation of this file.
1 <?php
8 namespace LocalisationUpdate;
9 
10 use PHPUnit4And6Compat;
11 
15 class 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\UpdaterTest\testFindChangedTranslations
testFindChangedTranslations()
Definition: UpdaterTest.php:70
LocalisationUpdate\UpdaterTest
\LocalisationUpdate\Updater
Definition: UpdaterTest.php:15
LocalisationUpdate\UpdaterTest\testReadMessages
testReadMessages()
Definition: UpdaterTest.php:48
LocalisationUpdate\UpdaterTest\testIsDirectory
testIsDirectory()
Definition: UpdaterTest.php:18
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:141
LocalisationUpdate\Updater
Executes the localisation update.
Definition: Updater.php:13
LocalisationUpdate\UpdaterTest\testExpandRemotePath
testExpandRemotePath()
Definition: UpdaterTest.php:32
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$output
$output
Definition: SyntaxHighlight.php:334
LocalisationUpdate
Definition: Fetcher.php:8
$updater
$page->newPageUpdater($user) $updater
Definition: pageupdater.txt:63