MediaWiki  1.28.1
FileBasedSiteLookupTest.php
Go to the documentation of this file.
1 <?php
2 
30 class FileBasedSiteLookupTest 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 testGetSites() {
41  $sites = $this->getSites();
42  $cacheBuilder = $this->newSitesCacheFileBuilder( $sites );
43  $cacheBuilder->build();
44 
45  $cache = new FileBasedSiteLookup( $this->cacheFile );
46  $this->assertEquals( $sites, $cache->getSites() );
47  }
48 
49  public function testGetSite() {
50  $sites = $this->getSites();
51  $cacheBuilder = $this->newSitesCacheFileBuilder( $sites );
52  $cacheBuilder->build();
53 
54  $cache = new FileBasedSiteLookup( $this->cacheFile );
55 
56  $this->assertEquals( $sites->getSite( 'enwiktionary' ), $cache->getSite( 'enwiktionary' ) );
57  }
58 
59  private function newSitesCacheFileBuilder( SiteList $sites ) {
60  return new SitesCacheFileBuilder(
61  $this->getSiteLookup( $sites ),
62  $this->cacheFile
63  );
64  }
65 
66  private function getSiteLookup( SiteList $sites ) {
67  $siteLookup = $this->getMockBuilder( 'SiteLookup' )
68  ->disableOriginalConstructor()
69  ->getMock();
70 
71  $siteLookup->expects( $this->any() )
72  ->method( 'getSites' )
73  ->will( $this->returnValue( $sites ) );
74 
75  return $siteLookup;
76  }
77 
78  private function getSites() {
79  $sites = [];
80 
81  $site = new Site();
82  $site->setGlobalId( 'foobar' );
83  $sites[] = $site;
84 
85  $site = new MediaWikiSite();
86  $site->setGlobalId( 'enwiktionary' );
87  $site->setGroup( 'wiktionary' );
88  $site->setLanguageCode( 'en' );
89  $site->addNavigationId( 'enwiktionary' );
90  $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
91  $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
92  $sites[] = $site;
93 
94  return new SiteList( $sites );
95  }
96 
97  private function getCacheFile() {
98  return tempnam( sys_get_temp_dir(), 'mw-test-sitelist' );
99  }
100 
101 }
newSitesCacheFileBuilder(SiteList $sites)
Class representing a MediaWiki site.
$cache
Definition: mcc.php:33
Provides a file-based cache of a SiteStore.
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