4f7889bff17db0f2ddf6f72345c3d12545bb01ec
4 * Tests for the SiteSQLStore class.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
30 * @licence GNU GPL v2+
31 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
33 class SiteSQLStoreTest
extends MediaWikiTestCase
{
35 public function testGetSites() {
36 $expectedSites = TestSites
::getSites();
37 TestSites
::insertIntoDb();
39 $store = SiteSQLStore
::newInstance();
41 $sites = $store->getSites();
43 $this->assertInstanceOf( 'SiteList', $sites );
48 foreach ( $sites as $site ) {
49 $this->assertInstanceOf( 'Site', $site );
52 foreach ( $expectedSites as $site ) {
53 if ( $site->getGlobalId() !== null ) {
54 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
59 public function testSaveSites() {
60 $store = SiteSQLStore
::newInstance();
65 $site->setGlobalId( 'ertrywuutr' );
66 $site->setLanguageCode( 'en' );
69 $site = new MediaWikiSite();
70 $site->setGlobalId( 'sdfhxujgkfpth' );
71 $site->setLanguageCode( 'nl' );
74 $this->assertTrue( $store->saveSites( $sites ) );
76 $site = $store->getSite( 'ertrywuutr' );
77 $this->assertInstanceOf( 'Site', $site );
78 $this->assertEquals( 'en', $site->getLanguageCode() );
80 $site = $store->getSite( 'sdfhxujgkfpth' );
81 $this->assertInstanceOf( 'Site', $site );
82 $this->assertEquals( 'nl', $site->getLanguageCode() );
85 public function testReset() {
86 $store = SiteSQLStore
::newInstance();
88 // initialize internal cache
89 $this->assertGreaterThan( 0, $store->getSites()->count() );
91 // Clear actual data. Will not purge the internal cache in store2.
92 $dbw = wfGetDB( DB_MASTER
);
93 $dbw->delete( 'sites', '*', __METHOD__
);
94 $dbw->delete( 'site_identifiers', '*', __METHOD__
);
96 // sanity check: $store2 should have a stale cache now
97 $this->assertNotNull( $store->getSite( 'enwiki' ) );
102 // ...now the internal cache of $store2 should be updated and thus empty.
103 $site = $store->getSite( 'enwiki' );
104 $this->assertNull( $site );