MediaWiki REL1_33
DBSiteStoreTest.php
Go to the documentation of this file.
1<?php
2
4
33
37 private function newDBSiteStore() {
38 // NOTE: Use the real DB load balancer for now. Eventually, the test framework should
39 // provide a LoadBalancer that is safe to use in unit tests.
40 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
41 return new DBSiteStore( $lb );
42 }
43
47 public function testGetSites() {
48 $expectedSites = TestSites::getSites();
50
51 $store = $this->newDBSiteStore();
52
53 $sites = $store->getSites();
54
55 $this->assertInstanceOf( SiteList::class, $sites );
56
60 foreach ( $sites as $site ) {
61 $this->assertInstanceOf( Site::class, $site );
62 }
63
64 foreach ( $expectedSites as $site ) {
65 if ( $site->getGlobalId() !== null ) {
66 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
67 }
68 }
69 }
70
74 public function testSaveSites() {
75 $store = $this->newDBSiteStore();
76
77 $sites = [];
78
79 $site = new Site();
80 $site->setGlobalId( 'ertrywuutr' );
81 $site->setLanguageCode( 'en' );
82 $sites[] = $site;
83
84 $site = new MediaWikiSite();
85 $site->setGlobalId( 'sdfhxujgkfpth' );
86 $site->setLanguageCode( 'nl' );
87 $sites[] = $site;
88
89 $this->assertTrue( $store->saveSites( $sites ) );
90
91 $site = $store->getSite( 'ertrywuutr' );
92 $this->assertInstanceOf( Site::class, $site );
93 $this->assertEquals( 'en', $site->getLanguageCode() );
94 $this->assertTrue( is_int( $site->getInternalId() ) );
95 $this->assertTrue( $site->getInternalId() >= 0 );
96
97 $site = $store->getSite( 'sdfhxujgkfpth' );
98 $this->assertInstanceOf( Site::class, $site );
99 $this->assertEquals( 'nl', $site->getLanguageCode() );
100 $this->assertTrue( is_int( $site->getInternalId() ) );
101 $this->assertTrue( $site->getInternalId() >= 0 );
102 }
103
107 public function testReset() {
108 $store1 = $this->newDBSiteStore();
109 $store2 = $this->newDBSiteStore();
110
111 // initialize internal cache
112 $this->assertGreaterThan( 0, $store1->getSites()->count() );
113 $this->assertGreaterThan( 0, $store2->getSites()->count() );
114
115 // Clear actual data. Will purge the external cache and reset the internal
116 // cache in $store1, but not the internal cache in store2.
117 $this->assertTrue( $store1->clear() );
118
119 // sanity check: $store2 should have a stale cache now
120 $this->assertNotNull( $store2->getSite( 'enwiki' ) );
121
122 // purge cache
123 $store2->reset();
124
125 // ...now the internal cache of $store2 should be updated and thus empty.
126 $site = $store2->getSite( 'enwiki' );
127 $this->assertNull( $site );
128 }
129
133 public function testClear() {
134 $store = $this->newDBSiteStore();
135 $this->assertTrue( $store->clear() );
136
137 $site = $store->getSite( 'enwiki' );
138 $this->assertNull( $site );
139
140 $sites = $store->getSites();
141 $this->assertEquals( 0, $sites->count() );
142 }
143
147 public function testGetSitesDefaultOrder() {
148 $store = $this->newDBSiteStore();
149 $siteB = new Site();
150 $siteB->setGlobalId( 'B' );
151 $siteA = new Site();
152 $siteA->setGlobalId( 'A' );
153 $store->saveSites( [ $siteB, $siteA ] );
154
155 $sites = $store->getSites();
156 $siteIdentifiers = [];
158 foreach ( $sites as $site ) {
159 $siteIdentifiers[] = $site->getGlobalId();
160 }
161 $this->assertSame( [ 'A', 'B' ], $siteIdentifiers );
162
163 // Note: SiteList::getGlobalIdentifiers uses an other internal state. Iteration must be
164 // tested separately.
165 $this->assertSame( [ 'A', 'B' ], $sites->getGlobalIdentifiers() );
166 }
167}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
testSaveSites()
DBSiteStore::saveSites.
testGetSitesDefaultOrder()
DBSiteStore::getSites.
testReset()
DBSiteStore::reset.
testClear()
DBSiteStore::clear.
testGetSites()
DBSiteStore::getSites.
Class representing a MediaWiki site.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition Site.php:29
static getSites()
Definition TestSites.php:36
static insertIntoDb()
Inserts sites into the database for the unit tests that need them.