| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Tests\Site; |
| 22 |
|
| 23 |
use MediaWiki\Site\Site; |
| 24 |
use MediaWiki\Site\SiteList; |
| 25 |
use MediaWikiIntegrationTestCase; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class SiteListTest extends MediaWikiIntegrationTestCase { |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function siteListProvider() { |
| 39 |
$sitesArrays = $this->siteArrayProvider(); |
| 40 |
|
| 41 |
$listInstances = []; |
| 42 |
|
| 43 |
foreach ( $sitesArrays as $sitesArray ) { |
| 44 |
$listInstances[] = new SiteList( $sitesArray[0] ); |
| 45 |
} |
| 46 |
|
| 47 |
return $this->arrayWrap( $listInstances ); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public function siteArrayProvider() { |
| 55 |
$sites = TestSites::getSites(); |
| 56 |
|
| 57 |
$siteArrays = []; |
| 58 |
|
| 59 |
$siteArrays[] = $sites; |
| 60 |
|
| 61 |
$siteArrays[] = [ array_shift( $sites ) ]; |
| 62 |
|
| 63 |
$siteArrays[] = [ array_shift( $sites ), array_shift( $sites ) ]; |
| 64 |
|
| 65 |
return $this->arrayWrap( $siteArrays ); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public function testIsEmpty( SiteList $sites ) { |
| 73 |
$this->assertEquals( count( $sites ) === 0, $sites->isEmpty() ); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public function testGetSiteByGlobalId( SiteList $sites ) { |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
foreach ( $sites as $site ) { |
| 85 |
$this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) ); |
| 86 |
} |
| 87 |
|
| 88 |
$this->assertTrue( true ); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public function testGetSiteByInternalId( $sites ) { |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
foreach ( $sites as $site ) { |
| 100 |
if ( is_int( $site->getInternalId() ) ) { |
| 101 |
$this->assertEquals( $site, $sites->getSiteByInternalId( $site->getInternalId() ) ); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
$this->assertTrue( true ); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public function testGetSiteByNavigationId( $sites ) { |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
foreach ( $sites as $site ) { |
| 117 |
$ids = $site->getNavigationIds(); |
| 118 |
foreach ( $ids as $navId ) { |
| 119 |
$this->assertEquals( $site, $sites->getSiteByNavigationId( $navId ) ); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
$this->assertTrue( true ); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
public function testHasGlobalId( $sites ) { |
| 131 |
$this->assertFalse( $sites->hasSite( 'non-existing-global-id' ) ); |
| 132 |
$this->assertFalse( $sites->hasInternalId( 720101010 ) ); |
| 133 |
|
| 134 |
if ( !$sites->isEmpty() ) { |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
foreach ( $sites as $site ) { |
| 139 |
$this->assertTrue( $sites->hasSite( $site->getGlobalId() ) ); |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
public function testHasInternallId( $sites ) { |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
foreach ( $sites as $site ) { |
| 153 |
if ( is_int( $site->getInternalId() ) ) { |
| 154 |
$this->assertTrue( $site, $sites->hasInternalId( $site->getInternalId() ) ); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
$this->assertFalse( $sites->hasInternalId( -1 ) ); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public function testHasNavigationId( $sites ) { |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
foreach ( $sites as $site ) { |
| 170 |
$ids = $site->getNavigationIds(); |
| 171 |
foreach ( $ids as $navId ) { |
| 172 |
$this->assertTrue( $sites->hasNavigationId( $navId ) ); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
$this->assertFalse( $sites->hasNavigationId( 'non-existing-navigation-id' ) ); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public function testGetGlobalIdentifiers( SiteList $sites ) { |
| 184 |
$identifiers = $sites->getGlobalIdentifiers(); |
| 185 |
|
| 186 |
$this->assertIsArray( $identifiers ); |
| 187 |
|
| 188 |
$expected = []; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
foreach ( $sites as $site ) { |
| 194 |
$expected[] = $site->getGlobalId(); |
| 195 |
} |
| 196 |
|
| 197 |
$this->assertArrayEquals( $expected, $identifiers ); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
public function testSerialization( SiteList $list ) { |
| 205 |
$serialization = serialize( $list ); |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
$copy = unserialize( $serialization ); |
| 210 |
|
| 211 |
$this->assertArrayEquals( $list->getGlobalIdentifiers(), $copy->getGlobalIdentifiers() ); |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
foreach ( $list as $site ) { |
| 217 |
if ( is_int( $site->getInternalId() ) ) { |
| 218 |
$this->assertTrue( $copy->hasInternalId( $site->getInternalId() ) ); |
| 219 |
} |
| 220 |
|
| 221 |
foreach ( $site->getNavigationIds() as $navId ) { |
| 222 |
$this->assertTrue( |
| 223 |
$copy->hasNavigationId( $navId ), |
| 224 |
'unserialized data expects nav id ' . $navId . ' for site ' . $site->getGlobalId() |
| 225 |
); |
| 226 |
} |
| 227 |
} |
| 228 |
} |
| 229 |
} |