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
{
36 * @covers SiteSQLStore::getSites
38 public function testGetSites() {
39 $expectedSites = TestSites
::getSites();
40 TestSites
::insertIntoDb();
42 $store = SiteSQLStore
::newInstance();
44 $sites = $store->getSites();
46 $this->assertInstanceOf( 'SiteList', $sites );
51 foreach ( $sites as $site ) {
52 $this->assertInstanceOf( 'Site', $site );
55 foreach ( $expectedSites as $site ) {
56 if ( $site->getGlobalId() !== null ) {
57 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
63 * @covers SiteSQLStore::saveSites
65 public function testSaveSites() {
66 $store = SiteSQLStore
::newInstance();
71 $site->setGlobalId( 'ertrywuutr' );
72 $site->setLanguageCode( 'en' );
75 $site = new MediaWikiSite();
76 $site->setGlobalId( 'sdfhxujgkfpth' );
77 $site->setLanguageCode( 'nl' );
80 $this->assertTrue( $store->saveSites( $sites ) );
82 $site = $store->getSite( 'ertrywuutr' );
83 $this->assertInstanceOf( 'Site', $site );
84 $this->assertEquals( 'en', $site->getLanguageCode() );
85 $this->assertTrue( is_integer( $site->getInternalId() ) );
86 $this->assertTrue( $site->getInternalId() >= 0 );
88 $site = $store->getSite( 'sdfhxujgkfpth' );
89 $this->assertInstanceOf( 'Site', $site );
90 $this->assertEquals( 'nl', $site->getLanguageCode() );
91 $this->assertTrue( is_integer( $site->getInternalId() ) );
92 $this->assertTrue( $site->getInternalId() >= 0 );
96 * @covers SiteSQLStore::reset
98 public function testReset() {
99 $store1 = SiteSQLStore
::newInstance();
100 $store2 = SiteSQLStore
::newInstance();
102 // initialize internal cache
103 $this->assertGreaterThan( 0, $store1->getSites()->count() );
104 $this->assertGreaterThan( 0, $store2->getSites()->count() );
106 // Clear actual data. Will purge the external cache and reset the internal
107 // cache in $store1, but not the internal cache in store2.
108 $this->assertTrue( $store1->clear() );
110 // sanity check: $store2 should have a stale cache now
111 $this->assertNotNull( $store2->getSite( 'enwiki' ) );
116 // ...now the internal cache of $store2 should be updated and thus empty.
117 $site = $store2->getSite( 'enwiki' );
118 $this->assertNull( $site );
122 * @covers SiteSQLStore::clear
124 public function testClear() {
125 $store = SiteSQLStore
::newInstance();
126 $this->assertTrue( $store->clear() );
128 $site = $store->getSite( 'enwiki' );
129 $this->assertNull( $site );
131 $sites = $store->getSites();
132 $this->assertEquals( 0, $sites->count() );