4f7889bff17db0f2ddf6f72345c3d12545bb01ec
[lhc/web/wiklou.git] / tests / phpunit / includes / site / SiteSQLStoreTest.php
1 <?php
2
3 /**
4 * Tests for the SiteSQLStore class.
5 *
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.
10 *
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.
15 *
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
20 *
21 * @file
22 * @since 1.21
23 *
24 * @ingroup Site
25 * @ingroup Test
26 *
27 * @group Site
28 * @group Database
29 *
30 * @licence GNU GPL v2+
31 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
32 */
33 class SiteSQLStoreTest extends MediaWikiTestCase {
34
35 public function testGetSites() {
36 $expectedSites = TestSites::getSites();
37 TestSites::insertIntoDb();
38
39 $store = SiteSQLStore::newInstance();
40
41 $sites = $store->getSites();
42
43 $this->assertInstanceOf( 'SiteList', $sites );
44
45 /**
46 * @var Site $site
47 */
48 foreach ( $sites as $site ) {
49 $this->assertInstanceOf( 'Site', $site );
50 }
51
52 foreach ( $expectedSites as $site ) {
53 if ( $site->getGlobalId() !== null ) {
54 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
55 }
56 }
57 }
58
59 public function testSaveSites() {
60 $store = SiteSQLStore::newInstance();
61
62 $sites = array();
63
64 $site = new Site();
65 $site->setGlobalId( 'ertrywuutr' );
66 $site->setLanguageCode( 'en' );
67 $sites[] = $site;
68
69 $site = new MediaWikiSite();
70 $site->setGlobalId( 'sdfhxujgkfpth' );
71 $site->setLanguageCode( 'nl' );
72 $sites[] = $site;
73
74 $this->assertTrue( $store->saveSites( $sites ) );
75
76 $site = $store->getSite( 'ertrywuutr' );
77 $this->assertInstanceOf( 'Site', $site );
78 $this->assertEquals( 'en', $site->getLanguageCode() );
79
80 $site = $store->getSite( 'sdfhxujgkfpth' );
81 $this->assertInstanceOf( 'Site', $site );
82 $this->assertEquals( 'nl', $site->getLanguageCode() );
83 }
84
85 public function testReset() {
86 $store = SiteSQLStore::newInstance();
87
88 // initialize internal cache
89 $this->assertGreaterThan( 0, $store->getSites()->count() );
90
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__ );
95
96 // sanity check: $store2 should have a stale cache now
97 $this->assertNotNull( $store->getSite( 'enwiki' ) );
98
99 // purge cache
100 $store->reset();
101
102 // ...now the internal cache of $store2 should be updated and thus empty.
103 $site = $store->getSite( 'enwiki' );
104 $this->assertNull( $site );
105 }
106
107 }