MediaWiki  1.30.0
CachingSiteStoreTest.php
Go to the documentation of this file.
1 <?php
2 
31 
35  public function testGetSites() {
36  $testSites = TestSites::getSites();
37 
38  $store = new CachingSiteStore(
39  $this->getHashSiteStore( $testSites ),
41  );
42 
43  $sites = $store->getSites();
44 
45  $this->assertInstanceOf( 'SiteList', $sites );
46 
50  foreach ( $sites as $site ) {
51  $this->assertInstanceOf( 'Site', $site );
52  }
53 
54  foreach ( $testSites as $site ) {
55  if ( $site->getGlobalId() !== null ) {
56  $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
57  }
58  }
59  }
60 
64  public function testSaveSites() {
65  $store = new CachingSiteStore( new HashSiteStore(), wfGetMainCache() );
66 
67  $sites = [];
68 
69  $site = new Site();
70  $site->setGlobalId( 'ertrywuutr' );
71  $site->setLanguageCode( 'en' );
72  $sites[] = $site;
73 
74  $site = new MediaWikiSite();
75  $site->setGlobalId( 'sdfhxujgkfpth' );
76  $site->setLanguageCode( 'nl' );
77  $sites[] = $site;
78 
79  $this->assertTrue( $store->saveSites( $sites ) );
80 
81  $site = $store->getSite( 'ertrywuutr' );
82  $this->assertInstanceOf( 'Site', $site );
83  $this->assertEquals( 'en', $site->getLanguageCode() );
84 
85  $site = $store->getSite( 'sdfhxujgkfpth' );
86  $this->assertInstanceOf( 'Site', $site );
87  $this->assertEquals( 'nl', $site->getLanguageCode() );
88  }
89 
93  public function testReset() {
94  $dbSiteStore = $this->getMockBuilder( 'SiteStore' )
95  ->disableOriginalConstructor()
96  ->getMock();
97 
98  $dbSiteStore->expects( $this->any() )
99  ->method( 'getSite' )
100  ->will( $this->returnValue( $this->getTestSite() ) );
101 
102  $dbSiteStore->expects( $this->any() )
103  ->method( 'getSites' )
104  ->will( $this->returnCallback( function () {
105  $siteList = new SiteList();
106  $siteList->setSite( $this->getTestSite() );
107 
108  return $siteList;
109  } ) );
110 
111  $store = new CachingSiteStore( $dbSiteStore, wfGetMainCache() );
112 
113  // initialize internal cache
114  $this->assertGreaterThan( 0, $store->getSites()->count(), 'count sites' );
115 
116  $store->getSite( 'enwiki' )->setLanguageCode( 'en-ca' );
117 
118  // sanity check: $store should have the new language code for 'enwiki'
119  $this->assertEquals( 'en-ca', $store->getSite( 'enwiki' )->getLanguageCode(), 'sanity check' );
120 
121  // purge cache
122  $store->reset();
123 
124  // the internal cache of $store should be updated, and now pulling
125  // the site from the 'fallback' DBSiteStore with the original language code.
126  $this->assertEquals( 'en', $store->getSite( 'enwiki' )->getLanguageCode(), 'reset' );
127  }
128 
129  public function getTestSite() {
130  $enwiki = new MediaWikiSite();
131  $enwiki->setGlobalId( 'enwiki' );
132  $enwiki->setLanguageCode( 'en' );
133 
134  return $enwiki;
135  }
136 
140  public function testClear() {
141  $store = new CachingSiteStore( new HashSiteStore(), wfGetMainCache() );
142  $this->assertTrue( $store->clear() );
143 
144  $site = $store->getSite( 'enwiki' );
145  $this->assertNull( $site );
146 
147  $sites = $store->getSites();
148  $this->assertEquals( 0, $sites->count() );
149  }
150 
156  private function getHashSiteStore( array $sites ) {
157  $siteStore = new HashSiteStore();
158  $siteStore->saveSites( $sites );
159 
160  return $siteStore;
161  }
162 
163 }
TestSites\getSites
static getSites()
Definition: TestSites.php:38
CachingSiteStoreTest\testSaveSites
testSaveSites()
CachingSiteStore::saveSites.
Definition: CachingSiteStoreTest.php:64
CachingSiteStore
Definition: CachingSiteStore.php:31
CachingSiteStoreTest\testGetSites
testGetSites()
CachingSiteStore::getSites.
Definition: CachingSiteStoreTest.php:35
CachingSiteStoreTest\getHashSiteStore
getHashSiteStore(array $sites)
Definition: CachingSiteStoreTest.php:156
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
CachingSiteStoreTest\testClear
testClear()
CachingSiteStore::clear.
Definition: CachingSiteStoreTest.php:140
CachingSiteStoreTest\getTestSite
getTestSite()
Definition: CachingSiteStoreTest.php:129
wfGetMainCache
wfGetMainCache()
Get the main cache object.
Definition: GlobalFunctions.php:3204
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
SiteList
Definition: SiteList.php:29
CachingSiteStoreTest\testReset
testReset()
CachingSiteStore::reset.
Definition: CachingSiteStoreTest.php:93
HashSiteStore
In-memory SiteStore implementation, storing sites in an associative array.
Definition: HashSiteStore.php:32
Site
Definition: Site.php:29
CachingSiteStoreTest
Definition: CachingSiteStoreTest.php:30
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
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MediaWikiSite
Class representing a MediaWiki site.
Definition: MediaWikiSite.php:38
array
the array() calling protocol came about after MediaWiki 1.4rc1.