MediaWiki
REL1_24
|
00001 <?php 00002 00033 class SiteSQLStoreTest extends MediaWikiTestCase { 00034 00038 public function testGetSites() { 00039 $expectedSites = TestSites::getSites(); 00040 TestSites::insertIntoDb(); 00041 00042 $store = SiteSQLStore::newInstance(); 00043 00044 $sites = $store->getSites(); 00045 00046 $this->assertInstanceOf( 'SiteList', $sites ); 00047 00051 foreach ( $sites as $site ) { 00052 $this->assertInstanceOf( 'Site', $site ); 00053 } 00054 00055 foreach ( $expectedSites as $site ) { 00056 if ( $site->getGlobalId() !== null ) { 00057 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) ); 00058 } 00059 } 00060 } 00061 00065 public function testSaveSites() { 00066 $store = SiteSQLStore::newInstance(); 00067 00068 $sites = array(); 00069 00070 $site = new Site(); 00071 $site->setGlobalId( 'ertrywuutr' ); 00072 $site->setLanguageCode( 'en' ); 00073 $sites[] = $site; 00074 00075 $site = new MediaWikiSite(); 00076 $site->setGlobalId( 'sdfhxujgkfpth' ); 00077 $site->setLanguageCode( 'nl' ); 00078 $sites[] = $site; 00079 00080 $this->assertTrue( $store->saveSites( $sites ) ); 00081 00082 $site = $store->getSite( 'ertrywuutr' ); 00083 $this->assertInstanceOf( 'Site', $site ); 00084 $this->assertEquals( 'en', $site->getLanguageCode() ); 00085 $this->assertTrue( is_integer( $site->getInternalId() ) ); 00086 $this->assertTrue( $site->getInternalId() >= 0 ); 00087 00088 $site = $store->getSite( 'sdfhxujgkfpth' ); 00089 $this->assertInstanceOf( 'Site', $site ); 00090 $this->assertEquals( 'nl', $site->getLanguageCode() ); 00091 $this->assertTrue( is_integer( $site->getInternalId() ) ); 00092 $this->assertTrue( $site->getInternalId() >= 0 ); 00093 } 00094 00098 public function testReset() { 00099 $store1 = SiteSQLStore::newInstance(); 00100 $store2 = SiteSQLStore::newInstance(); 00101 00102 // initialize internal cache 00103 $this->assertGreaterThan( 0, $store1->getSites()->count() ); 00104 $this->assertGreaterThan( 0, $store2->getSites()->count() ); 00105 00106 // Clear actual data. Will purge the external cache and reset the internal 00107 // cache in $store1, but not the internal cache in store2. 00108 $this->assertTrue( $store1->clear() ); 00109 00110 // sanity check: $store2 should have a stale cache now 00111 $this->assertNotNull( $store2->getSite( 'enwiki' ) ); 00112 00113 // purge cache 00114 $store2->reset(); 00115 00116 // ...now the internal cache of $store2 should be updated and thus empty. 00117 $site = $store2->getSite( 'enwiki' ); 00118 $this->assertNull( $site ); 00119 } 00120 00124 public function testClear() { 00125 $store = SiteSQLStore::newInstance(); 00126 $this->assertTrue( $store->clear() ); 00127 00128 $site = $store->getSite( 'enwiki' ); 00129 $this->assertNull( $site ); 00130 00131 $sites = $store->getSites(); 00132 $this->assertEquals( 0, $sites->count() ); 00133 } 00134 }