MediaWiki REL1_32
DBSiteStoreTest.php
Go to the documentation of this file.
1<?php
2
4
35
39 private function newDBSiteStore() {
40 // NOTE: Use the real DB load balancer for now. Eventually, the test framework should
41 // provide a LoadBalancer that is safe to use in unit tests.
42 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
43 return new DBSiteStore( $lb );
44 }
45
49 public function testGetSites() {
50 $expectedSites = TestSites::getSites();
52
53 $store = $this->newDBSiteStore();
54
55 $sites = $store->getSites();
56
57 $this->assertInstanceOf( SiteList::class, $sites );
58
62 foreach ( $sites as $site ) {
63 $this->assertInstanceOf( Site::class, $site );
64 }
65
66 foreach ( $expectedSites as $site ) {
67 if ( $site->getGlobalId() !== null ) {
68 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
69 }
70 }
71 }
72
76 public function testSaveSites() {
77 $store = $this->newDBSiteStore();
78
79 $sites = [];
80
81 $site = new Site();
82 $site->setGlobalId( 'ertrywuutr' );
83 $site->setLanguageCode( 'en' );
84 $sites[] = $site;
85
86 $site = new MediaWikiSite();
87 $site->setGlobalId( 'sdfhxujgkfpth' );
88 $site->setLanguageCode( 'nl' );
89 $sites[] = $site;
90
91 $this->assertTrue( $store->saveSites( $sites ) );
92
93 $site = $store->getSite( 'ertrywuutr' );
94 $this->assertInstanceOf( Site::class, $site );
95 $this->assertEquals( 'en', $site->getLanguageCode() );
96 $this->assertTrue( is_int( $site->getInternalId() ) );
97 $this->assertTrue( $site->getInternalId() >= 0 );
98
99 $site = $store->getSite( 'sdfhxujgkfpth' );
100 $this->assertInstanceOf( Site::class, $site );
101 $this->assertEquals( 'nl', $site->getLanguageCode() );
102 $this->assertTrue( is_int( $site->getInternalId() ) );
103 $this->assertTrue( $site->getInternalId() >= 0 );
104 }
105
109 public function testReset() {
110 $store1 = $this->newDBSiteStore();
111 $store2 = $this->newDBSiteStore();
112
113 // initialize internal cache
114 $this->assertGreaterThan( 0, $store1->getSites()->count() );
115 $this->assertGreaterThan( 0, $store2->getSites()->count() );
116
117 // Clear actual data. Will purge the external cache and reset the internal
118 // cache in $store1, but not the internal cache in store2.
119 $this->assertTrue( $store1->clear() );
120
121 // sanity check: $store2 should have a stale cache now
122 $this->assertNotNull( $store2->getSite( 'enwiki' ) );
123
124 // purge cache
125 $store2->reset();
126
127 // ...now the internal cache of $store2 should be updated and thus empty.
128 $site = $store2->getSite( 'enwiki' );
129 $this->assertNull( $site );
130 }
131
135 public function testClear() {
136 $store = $this->newDBSiteStore();
137 $this->assertTrue( $store->clear() );
138
139 $site = $store->getSite( 'enwiki' );
140 $this->assertNull( $site );
141
142 $sites = $store->getSites();
143 $this->assertEquals( 0, $sites->count() );
144 }
145
149 public function testGetSitesDefaultOrder() {
150 $store = $this->newDBSiteStore();
151 $siteB = new Site();
152 $siteB->setGlobalId( 'B' );
153 $siteA = new Site();
154 $siteA->setGlobalId( 'A' );
155 $store->saveSites( [ $siteB, $siteA ] );
156
157 $sites = $store->getSites();
158 $siteIdentifiers = [];
160 foreach ( $sites as $site ) {
161 $siteIdentifiers[] = $site->getGlobalId();
162 }
163 $this->assertSame( [ 'A', 'B' ], $siteIdentifiers );
164
165 // Note: SiteList::getGlobalIdentifiers uses an other internal state. Iteration must be
166 // tested separately.
167 $this->assertSame( [ 'A', 'B' ], $sites->getGlobalIdentifiers() );
168 }
169}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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.
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
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:37