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