MediaWiki  REL1_22
SiteListTest.php
Go to the documentation of this file.
00001 <?php
00002 
00032 class SiteListTest extends MediaWikiTestCase {
00033 
00038     public function siteListProvider() {
00039         $sitesArrays = $this->siteArrayProvider();
00040 
00041         $listInstances = array();
00042 
00043         foreach ( $sitesArrays as $sitesArray ) {
00044             $listInstances[] = new SiteList( $sitesArray[0] );
00045         }
00046 
00047         return $this->arrayWrap( $listInstances );
00048     }
00049 
00054     public function siteArrayProvider() {
00055         $sites = TestSites::getSites();
00056 
00057         $siteArrays = array();
00058 
00059         $siteArrays[] = $sites;
00060 
00061         $siteArrays[] = array( array_shift( $sites ) );
00062 
00063         $siteArrays[] = array( array_shift( $sites ), array_shift( $sites ) );
00064 
00065         return $this->arrayWrap( $siteArrays );
00066     }
00067 
00073     public function testIsEmpty( SiteList $sites ) {
00074         $this->assertEquals( count( $sites ) === 0, $sites->isEmpty() );
00075     }
00076 
00082     public function testGetSiteByGlobalId( SiteList $sites ) {
00083         if ( $sites->isEmpty() ) {
00084             $this->assertTrue( true );
00085         } else {
00089             foreach ( $sites as $site ) {
00090                 $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) );
00091             }
00092         }
00093     }
00094 
00100     public function testGetSiteByInternalId( $sites ) {
00104         foreach ( $sites as $site ) {
00105             if ( is_integer( $site->getInternalId() ) ) {
00106                 $this->assertEquals( $site, $sites->getSiteByInternalId( $site->getInternalId() ) );
00107             }
00108         }
00109 
00110         $this->assertTrue( true );
00111     }
00112 
00118     public function testHasGlobalId( $sites ) {
00119         $this->assertFalse( $sites->hasSite( 'non-existing-global-id' ) );
00120         $this->assertFalse( $sites->hasInternalId( 720101010 ) );
00121 
00122         if ( !$sites->isEmpty() ) {
00126             foreach ( $sites as $site ) {
00127                 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
00128             }
00129         }
00130     }
00131 
00137     public function testHasInternallId( $sites ) {
00141         foreach ( $sites as $site ) {
00142             if ( is_integer( $site->getInternalId() ) ) {
00143                 $this->assertTrue( $site, $sites->hasInternalId( $site->getInternalId() ) );
00144             }
00145         }
00146 
00147         $this->assertFalse( $sites->hasInternalId( -1 ) );
00148     }
00149 
00155     public function testGetGlobalIdentifiers( SiteList $sites ) {
00156         $identifiers = $sites->getGlobalIdentifiers();
00157 
00158         $this->assertTrue( is_array( $identifiers ) );
00159 
00160         $expected = array();
00161 
00165         foreach ( $sites as $site ) {
00166             $expected[] = $site->getGlobalId();
00167         }
00168 
00169         $this->assertArrayEquals( $expected, $identifiers );
00170     }
00171 
00181     public function testSerialization( SiteList $list ) {
00182         $serialization = serialize( $list );
00186         $copy = unserialize( $serialization );
00187 
00188         $this->assertArrayEquals( $list->getGlobalIdentifiers(), $copy->getGlobalIdentifiers() );
00189 
00193         foreach ( $list as $site ) {
00194             $this->assertTrue( $copy->hasInternalId( $site->getInternalId() ) );
00195         }
00196     }
00197 }