MediaWiki
REL1_21
|
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 00072 public function testIsEmpty( SiteList $sites ) { 00073 $this->assertEquals( count( $sites ) === 0, $sites->isEmpty() ); 00074 } 00075 00080 public function testGetSiteByGlobalId( SiteList $sites ) { 00081 if ( $sites->isEmpty() ) { 00082 $this->assertTrue( true ); 00083 } else { 00087 foreach ( $sites as $site ) { 00088 $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) ); 00089 } 00090 } 00091 } 00092 00097 public function testGetSiteByInternalId( $sites ) { 00101 foreach ( $sites as $site ) { 00102 if ( is_integer( $site->getInternalId() ) ) { 00103 $this->assertEquals( $site, $sites->getSiteByInternalId( $site->getInternalId() ) ); 00104 } 00105 } 00106 00107 $this->assertTrue( true ); 00108 } 00109 00114 public function testHasGlobalId( $sites ) { 00115 $this->assertFalse( $sites->hasSite( 'non-existing-global-id' ) ); 00116 $this->assertFalse( $sites->hasInternalId( 720101010 ) ); 00117 00118 if ( !$sites->isEmpty() ) { 00122 foreach ( $sites as $site ) { 00123 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) ); 00124 } 00125 } 00126 } 00127 00132 public function testHasInternallId( $sites ) { 00136 foreach ( $sites as $site ) { 00137 if ( is_integer( $site->getInternalId() ) ) { 00138 $this->assertTrue( $site, $sites->hasInternalId( $site->getInternalId() ) ); 00139 } 00140 } 00141 00142 $this->assertFalse( $sites->hasInternalId( -1 ) ); 00143 } 00144 00149 public function testGetGlobalIdentifiers( SiteList $sites ) { 00150 $identifiers = $sites->getGlobalIdentifiers(); 00151 00152 $this->assertTrue( is_array( $identifiers ) ); 00153 00154 $expected = array(); 00155 00159 foreach ( $sites as $site ) { 00160 $expected[] = $site->getGlobalId(); 00161 } 00162 00163 $this->assertArrayEquals( $expected, $identifiers ); 00164 } 00165 00173 public function testSerialization( SiteList $list ) { 00174 $serialization = serialize( $list ); 00178 $copy = unserialize( $serialization ); 00179 00180 $this->assertArrayEquals( $list->getGlobalIdentifiers(), $copy->getGlobalIdentifiers() ); 00181 00185 foreach ( $list as $site ) { 00186 $this->assertTrue( $copy->hasInternalId( $site->getInternalId() ) ); 00187 } 00188 } 00189 00190 }