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