(bug 17602) fix Monobook action tabs not quite touching the page body
[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 $this->assertTrue( is_integer( $site->getInternalId() ) );
80 $this->assertTrue( $site->getInternalId() >= 0 );
81
82 $site = $store->getSite( 'sdfhxujgkfpth' );
83 $this->assertInstanceOf( 'Site', $site );
84 $this->assertEquals( 'nl', $site->getLanguageCode() );
85 $this->assertTrue( is_integer( $site->getInternalId() ) );
86 $this->assertTrue( $site->getInternalId() >= 0 );
87 }
88
89 public function testReset() {
90 $store1 = SiteSQLStore::newInstance();
91 $store2 = SiteSQLStore::newInstance();
92
93 // initialize internal cache
94 $this->assertGreaterThan( 0, $store1->getSites()->count() );
95 $this->assertGreaterThan( 0, $store2->getSites()->count() );
96
97 // Clear actual data. Will purge the external cache and reset the internal
98 // cache in $store1, but not the internal cache in store2.
99 $this->assertTrue( $store1->clear() );
100
101 // sanity check: $store2 should have a stale cache now
102 $this->assertNotNull( $store2->getSite( 'enwiki' ) );
103
104 // purge cache
105 $store2->reset();
106
107 // ...now the internal cache of $store2 should be updated and thus empty.
108 $site = $store2->getSite( 'enwiki' );
109 $this->assertNull( $site );
110 }
111
112 public function testClear() {
113 $store = SiteSQLStore::newInstance();
114 $this->assertTrue( $store->clear() );
115
116 $site = $store->getSite( 'enwiki' );
117 $this->assertNull( $site );
118
119 $sites = $store->getSites();
120 $this->assertEquals( 0, $sites->count() );
121 }
122
123 }