MediaWiki  1.28.0
SitesCacheFileBuilderTest.php
Go to the documentation of this file.
1 <?php
2 
30 class SitesCacheFileBuilderTest extends PHPUnit_Framework_TestCase {
31 
32  protected function setUp() {
33  $this->cacheFile = $this->getCacheFile();
34  }
35 
36  protected function tearDown() {
37  unlink( $this->cacheFile );
38  }
39 
40  public function testBuild() {
41  $cacheBuilder = $this->newSitesCacheFileBuilder( $this->getSites() );
42  $cacheBuilder->build();
43 
44  $contents = file_get_contents( $this->cacheFile );
45  $this->assertEquals( json_encode( $this->getExpectedData() ), $contents );
46  }
47 
48  private function getExpectedData() {
49  return [
50  'sites' => [
51  'foobar' => [
52  'globalid' => 'foobar',
53  'type' => 'unknown',
54  'group' => 'none',
55  'source' => 'local',
56  'language' => null,
57  'localids' => [],
58  'config' => [],
59  'data' => [],
60  'forward' => false,
61  'internalid' => null,
62  'identifiers' => []
63  ],
64  'enwiktionary' => [
65  'globalid' => 'enwiktionary',
66  'type' => 'mediawiki',
67  'group' => 'wiktionary',
68  'source' => 'local',
69  'language' => 'en',
70  'localids' => [
71  'equivalent' => [ 'enwiktionary' ]
72  ],
73  'config' => [],
74  'data' => [
75  'paths' => [
76  'page_path' => 'https://en.wiktionary.org/wiki/$1',
77  'file_path' => 'https://en.wiktionary.org/w/$1'
78  ]
79  ],
80  'forward' => false,
81  'internalid' => null,
82  'identifiers' => [
83  [
84  'type' => 'equivalent',
85  'key' => 'enwiktionary'
86  ]
87  ]
88  ]
89  ]
90  ];
91  }
92 
93  private function newSitesCacheFileBuilder( SiteList $sites ) {
94  return new SitesCacheFileBuilder(
95  $this->getSiteLookup( $sites ),
96  $this->cacheFile
97  );
98  }
99 
100  private function getSiteLookup( SiteList $sites ) {
101  $siteLookup = $this->getMockBuilder( 'SiteLookup' )
102  ->disableOriginalConstructor()
103  ->getMock();
104 
105  $siteLookup->expects( $this->any() )
106  ->method( 'getSites' )
107  ->will( $this->returnValue( $sites ) );
108 
109  return $siteLookup;
110  }
111 
112  private function getSites() {
113  $sites = [];
114 
115  $site = new Site();
116  $site->setGlobalId( 'foobar' );
117  $sites[] = $site;
118 
119  $site = new MediaWikiSite();
120  $site->setGlobalId( 'enwiktionary' );
121  $site->setGroup( 'wiktionary' );
122  $site->setLanguageCode( 'en' );
123  $site->addNavigationId( 'enwiktionary' );
124  $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
125  $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
126  $sites[] = $site;
127 
128  return new SiteList( $sites );
129  }
130 
131  private function getCacheFile() {
132  return tempnam( sys_get_temp_dir(), 'mw-test-sitelist' );
133  }
134 
135 }
Class representing a MediaWiki site.
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
Definition: Site.php:29