| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
o |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
use MediaWiki\Config\ServiceOptions; |
| 9 |
use MediaWiki\HookContainer\HookContainer; |
| 10 |
use MediaWiki\Linker\LinkTarget; |
| 11 |
use MediaWiki\MainConfigNames; |
| 12 |
use MediaWiki\Title\NamespaceInfo; |
| 13 |
use MediaWiki\Title\Title; |
| 14 |
use MediaWiki\Title\TitleValue; |
| 15 |
|
| 16 |
class NamespaceInfoTest extends MediaWikiIntegrationTestCase { |
| 17 |
use TestAllServiceOptionsUsed; |
| 18 |
|
| 19 |
private const TEST_EXT_NAMESPACES = [ NS_MAIN => 'No effect', NS_TALK => 'No effect', 12345 => 'Extended' ]; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
private const DEFAULT_OPTIONS = [ |
| 27 |
MainConfigNames::CanonicalNamespaceNames => [ |
| 28 |
NS_TALK => 'Talk', |
| 29 |
NS_USER => 'User', |
| 30 |
NS_USER_TALK => 'User_talk', |
| 31 |
NS_SPECIAL => 'Special', |
| 32 |
NS_MEDIA => 'Media', |
| 33 |
], |
| 34 |
MainConfigNames::CapitalLinkOverrides => [], |
| 35 |
MainConfigNames::CapitalLinks => true, |
| 36 |
MainConfigNames::ContentNamespaces => [ NS_MAIN ], |
| 37 |
MainConfigNames::ExtraNamespaces => [], |
| 38 |
MainConfigNames::ExtraSignatureNamespaces => [], |
| 39 |
MainConfigNames::NamespaceContentModels => [], |
| 40 |
MainConfigNames::NamespacesWithSubpages => [ |
| 41 |
NS_TALK => true, |
| 42 |
NS_USER => true, |
| 43 |
NS_USER_TALK => true, |
| 44 |
], |
| 45 |
MainConfigNames::NonincludableNamespaces => [], |
| 46 |
]; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
private function getHookContainer() { |
| 52 |
return $this->getServiceContainer()->getHookContainer(); |
| 53 |
} |
| 54 |
|
| 55 |
private function newObj( array $options = [], array $extensionNamespaces = [] ): NamespaceInfo { |
| 56 |
return new NamespaceInfo( |
| 57 |
new LoggedServiceOptions( |
| 58 |
self::$serviceOptionsAccessLog, |
| 59 |
NamespaceInfo::CONSTRUCTOR_OPTIONS, |
| 60 |
$options, self::DEFAULT_OPTIONS |
| 61 |
), |
| 62 |
$this->getHookContainer(), |
| 63 |
$extensionNamespaces, |
| 64 |
[] |
| 65 |
); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public function testConstructor( ServiceOptions $options, $expectedExceptionText = null ) { |
| 82 |
if ( $expectedExceptionText !== null ) { |
| 83 |
$this->expectException( \Wikimedia\Assert\PreconditionException::class ); |
| 84 |
$this->expectExceptionMessage( $expectedExceptionText ); |
| 85 |
} |
| 86 |
new NamespaceInfo( $options, $this->getHookContainer(), [], [] ); |
| 87 |
$this->assertTrue( true ); |
| 88 |
} |
| 89 |
|
| 90 |
public static function provideConstructor() { |
| 91 |
return [ |
| 92 |
[ new ServiceOptions( NamespaceInfo::CONSTRUCTOR_OPTIONS, self::DEFAULT_OPTIONS ) ], |
| 93 |
[ new ServiceOptions( [], [] ), 'Required options missing: ' ], |
| 94 |
[ new ServiceOptions( |
| 95 |
array_merge( NamespaceInfo::CONSTRUCTOR_OPTIONS, [ 'invalid' ] ), |
| 96 |
self::DEFAULT_OPTIONS, |
| 97 |
[ 'invalid' => '' ] |
| 98 |
), 'Unsupported options passed: invalid' ], |
| 99 |
]; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public function testIsMovable( $expected, $ns ) { |
| 110 |
$obj = $this->newObj(); |
| 111 |
$this->assertSame( $expected, $obj->isMovable( $ns ) ); |
| 112 |
} |
| 113 |
|
| 114 |
public static function provideIsMovable() { |
| 115 |
return [ |
| 116 |
'Main' => [ true, NS_MAIN ], |
| 117 |
'Talk' => [ true, NS_TALK ], |
| 118 |
'Special' => [ false, NS_SPECIAL ], |
| 119 |
'Nonexistent even namespace' => [ true, 1234 ], |
| 120 |
'Nonexistent odd namespace' => [ true, 12345 ], |
| 121 |
|
| 122 |
'Media' => [ false, NS_MEDIA ], |
| 123 |
'File' => [ true, NS_FILE ], |
| 124 |
]; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public function testIsSubject( $ns, $expected ) { |
| 134 |
$this->assertSame( $expected, $this->newObj()->isSubject( $ns ) ); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
public function testIsTalk( $ns, $expected ) { |
| 144 |
$this->assertSame( !$expected, $this->newObj()->isTalk( $ns ) ); |
| 145 |
} |
| 146 |
|
| 147 |
public static function provideIsSubject() { |
| 148 |
return [ |
| 149 |
|
| 150 |
[ NS_MEDIA, true ], |
| 151 |
[ NS_SPECIAL, true ], |
| 152 |
|
| 153 |
|
| 154 |
[ NS_MAIN, true ], |
| 155 |
[ NS_USER, true ], |
| 156 |
[ 100, true ], |
| 157 |
|
| 158 |
|
| 159 |
[ NS_TALK, false ], |
| 160 |
[ NS_USER_TALK, false ], |
| 161 |
[ 101, false ], |
| 162 |
]; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public function testExists( $ns, $expected ) { |
| 172 |
$this->assertSame( $expected, $this->newObj()->exists( $ns ) ); |
| 173 |
} |
| 174 |
|
| 175 |
public static function provideExists() { |
| 176 |
return [ |
| 177 |
'Main' => [ NS_MAIN, true ], |
| 178 |
'Talk' => [ NS_TALK, true ], |
| 179 |
'Media' => [ NS_MEDIA, true ], |
| 180 |
'Special' => [ NS_SPECIAL, true ], |
| 181 |
'Nonexistent' => [ 12345, false ], |
| 182 |
'Negative nonexistent' => [ -12345, false ], |
| 183 |
]; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
public function testEquals() { |
| 193 |
$obj = $this->newObj(); |
| 194 |
$this->assertTrue( $obj->equals( NS_MAIN, NS_MAIN ) ); |
| 195 |
$this->assertTrue( $obj->equals( NS_MAIN, 0 ) ); |
| 196 |
$this->assertTrue( $obj->equals( NS_USER, NS_USER ) ); |
| 197 |
$this->assertTrue( $obj->equals( NS_USER, 2 ) ); |
| 198 |
$this->assertTrue( $obj->equals( NS_USER_TALK, NS_USER_TALK ) ); |
| 199 |
$this->assertTrue( $obj->equals( NS_SPECIAL, NS_SPECIAL ) ); |
| 200 |
$this->assertFalse( $obj->equals( NS_MAIN, NS_TALK ) ); |
| 201 |
$this->assertFalse( $obj->equals( NS_USER, NS_USER_TALK ) ); |
| 202 |
$this->assertFalse( $obj->equals( NS_PROJECT, NS_TEMPLATE ) ); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
public function testSubjectEquals( $ns1, $ns2, $expected ) { |
| 213 |
$this->assertSame( $expected, $this->newObj()->subjectEquals( $ns1, $ns2 ) ); |
| 214 |
} |
| 215 |
|
| 216 |
public static function provideSubjectEquals() { |
| 217 |
return [ |
| 218 |
[ NS_MAIN, NS_MAIN, true ], |
| 219 |
|
| 220 |
[ NS_MAIN, 0, true ], |
| 221 |
[ NS_USER, NS_USER, true ], |
| 222 |
[ NS_USER, 2, true ], |
| 223 |
[ NS_USER_TALK, NS_USER_TALK, true ], |
| 224 |
[ NS_SPECIAL, NS_SPECIAL, true ], |
| 225 |
[ NS_MAIN, NS_TALK, true ], |
| 226 |
[ NS_USER, NS_USER_TALK, true ], |
| 227 |
|
| 228 |
[ NS_PROJECT, NS_TEMPLATE, false ], |
| 229 |
[ NS_SPECIAL, NS_MAIN, false ], |
| 230 |
[ NS_MEDIA, NS_SPECIAL, false ], |
| 231 |
[ NS_SPECIAL, NS_MEDIA, false ], |
| 232 |
]; |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
public function testHasTalkNamespace( $ns, $expected ) { |
| 243 |
$this->assertSame( $expected, $this->newObj()->hasTalkNamespace( $ns ) ); |
| 244 |
} |
| 245 |
|
| 246 |
public static function provideHasTalkNamespace() { |
| 247 |
return [ |
| 248 |
[ NS_MEDIA, false ], |
| 249 |
[ NS_SPECIAL, false ], |
| 250 |
|
| 251 |
[ NS_MAIN, true ], |
| 252 |
[ NS_TALK, true ], |
| 253 |
[ NS_USER, true ], |
| 254 |
[ NS_USER_TALK, true ], |
| 255 |
|
| 256 |
[ 100, true ], |
| 257 |
[ 101, true ], |
| 258 |
]; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
public function testIsContent( $ns, $expected, $contentNamespaces = [ NS_MAIN ] ) { |
| 269 |
$obj = $this->newObj( [ MainConfigNames::ContentNamespaces => $contentNamespaces ] ); |
| 270 |
$this->assertSame( $expected, $obj->isContent( $ns ) ); |
| 271 |
} |
| 272 |
|
| 273 |
public static function provideIsContent() { |
| 274 |
return [ |
| 275 |
[ NS_MAIN, true ], |
| 276 |
[ NS_MEDIA, false ], |
| 277 |
[ NS_SPECIAL, false ], |
| 278 |
[ NS_TALK, false ], |
| 279 |
[ NS_USER, false ], |
| 280 |
[ NS_CATEGORY, false ], |
| 281 |
[ 100, false ], |
| 282 |
[ 100, true, [ NS_MAIN, 100, 252 ] ], |
| 283 |
[ 252, true, [ NS_MAIN, 100, 252 ] ], |
| 284 |
[ NS_MAIN, true, [ NS_MAIN, 100, 252 ] ], |
| 285 |
|
| 286 |
[ NS_MAIN, true, [] ], |
| 287 |
]; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
public function testWantSignatures( $index, $expected ) { |
| 298 |
$this->assertSame( $expected, $this->newObj()->wantSignatures( $index ) ); |
| 299 |
} |
| 300 |
|
| 301 |
public static function provideWantSignatures() { |
| 302 |
return [ |
| 303 |
'Main' => [ NS_MAIN, false ], |
| 304 |
'Talk' => [ NS_TALK, true ], |
| 305 |
'User' => [ NS_USER, false ], |
| 306 |
'User talk' => [ NS_USER_TALK, true ], |
| 307 |
'Special' => [ NS_SPECIAL, false ], |
| 308 |
'Media' => [ NS_MEDIA, false ], |
| 309 |
'Nonexistent talk' => [ 12345, true ], |
| 310 |
'Nonexistent subject' => [ 123456, false ], |
| 311 |
'Nonexistent negative odd' => [ -12345, false ], |
| 312 |
]; |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
public function testWantSignatures_ExtraSignatureNamespaces( $index, $expected ) { |
| 323 |
$obj = $this->newObj( [ MainConfigNames::ExtraSignatureNamespaces => |
| 324 |
[ NS_MAIN, NS_USER, NS_SPECIAL, NS_MEDIA, 123456, -12345 ] ] ); |
| 325 |
$this->assertSame( $expected, $obj->wantSignatures( $index ) ); |
| 326 |
} |
| 327 |
|
| 328 |
public function provideWantSignatures_ExtraSignatureNamespaces() { |
| 329 |
$ret = array_map( |
| 330 |
static function ( $arr ) { |
| 331 |
|
| 332 |
return [ $arr[0], true ]; |
| 333 |
}, |
| 334 |
$this->provideWantSignatures() |
| 335 |
); |
| 336 |
|
| 337 |
|
| 338 |
$ret['Another nonexistent subject'] = [ 12345678, false ]; |
| 339 |
return $ret; |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
public function testIsWatchable( $ns, $expected ) { |
| 349 |
$this->assertSame( $expected, $this->newObj()->isWatchable( $ns ) ); |
| 350 |
} |
| 351 |
|
| 352 |
public static function provideIsWatchable() { |
| 353 |
return [ |
| 354 |
|
| 355 |
[ NS_MEDIA, false ], |
| 356 |
[ NS_SPECIAL, false ], |
| 357 |
|
| 358 |
|
| 359 |
[ NS_MAIN, true ], |
| 360 |
[ NS_TALK, true ], |
| 361 |
|
| 362 |
|
| 363 |
[ 100, true ], |
| 364 |
[ 101, true ], |
| 365 |
]; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
public function testHasSubpages( $ns, $expected, ?array $namespacesWithSubpages = null ) { |
| 376 |
$obj = $this->newObj( $namespacesWithSubpages |
| 377 |
? [ MainConfigNames::NamespacesWithSubpages => $namespacesWithSubpages ] |
| 378 |
: [] ); |
| 379 |
$this->assertSame( $expected, $obj->hasSubpages( $ns ) ); |
| 380 |
} |
| 381 |
|
| 382 |
public static function provideHasSubpages() { |
| 383 |
return [ |
| 384 |
|
| 385 |
[ NS_MEDIA, false ], |
| 386 |
[ NS_SPECIAL, false ], |
| 387 |
|
| 388 |
|
| 389 |
[ NS_MAIN, false ], |
| 390 |
[ NS_MAIN, true, [ NS_MAIN => true ] ], |
| 391 |
[ NS_MAIN, false, [ NS_MAIN => false ] ], |
| 392 |
|
| 393 |
|
| 394 |
[ NS_TALK, true ], |
| 395 |
[ NS_USER, true ], |
| 396 |
[ NS_USER_TALK, true ], |
| 397 |
]; |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
public function testGetContentNamespaces( $contentNamespaces, array $expected ) { |
| 405 |
$obj = $this->newObj( [ MainConfigNames::ContentNamespaces => $contentNamespaces ] ); |
| 406 |
$this->assertSame( $expected, $obj->getContentNamespaces() ); |
| 407 |
} |
| 408 |
|
| 409 |
public static function provideGetContentNamespaces() { |
| 410 |
return [ |
| 411 |
|
| 412 |
[ '', [ NS_MAIN ] ], |
| 413 |
[ false, [ NS_MAIN ] ], |
| 414 |
[ null, [ NS_MAIN ] ], |
| 415 |
[ 5, [ NS_MAIN ] ], |
| 416 |
|
| 417 |
|
| 418 |
[ [], [ NS_MAIN ] ], |
| 419 |
|
| 420 |
|
| 421 |
[ [ NS_USER, NS_CATEGORY ], [ NS_MAIN, NS_USER, NS_CATEGORY ] ], |
| 422 |
|
| 423 |
|
| 424 |
[ [ NS_MAIN ], [ NS_MAIN ] ], |
| 425 |
[ [ NS_MAIN, NS_USER, NS_CATEGORY ], [ NS_MAIN, NS_USER, NS_CATEGORY ] ], |
| 426 |
]; |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
public function testGetSubjectNamespaces() { |
| 433 |
$subjectsNS = $this->newObj()->getSubjectNamespaces(); |
| 434 |
$this->assertContains( NS_MAIN, $subjectsNS, |
| 435 |
"Talk namespaces should have NS_MAIN" ); |
| 436 |
$this->assertNotContains( NS_TALK, $subjectsNS, |
| 437 |
"Talk namespaces should have NS_TALK" ); |
| 438 |
|
| 439 |
$this->assertNotContains( NS_MEDIA, $subjectsNS, |
| 440 |
"Talk namespaces should not have NS_MEDIA" ); |
| 441 |
$this->assertNotContains( NS_SPECIAL, $subjectsNS, |
| 442 |
"Talk namespaces should not have NS_SPECIAL" ); |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
public function testGetTalkNamespaces() { |
| 449 |
$talkNS = $this->newObj()->getTalkNamespaces(); |
| 450 |
$this->assertContains( NS_TALK, $talkNS, |
| 451 |
"Subject namespaces should have NS_TALK" ); |
| 452 |
$this->assertNotContains( NS_MAIN, $talkNS, |
| 453 |
"Subject namespaces should not have NS_MAIN" ); |
| 454 |
|
| 455 |
$this->assertNotContains( NS_MEDIA, $talkNS, |
| 456 |
"Subject namespaces should not have NS_MEDIA" ); |
| 457 |
$this->assertNotContains( NS_SPECIAL, $talkNS, |
| 458 |
"Subject namespaces should not have NS_SPECIAL" ); |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
public function testIsCapitalized( |
| 470 |
$ns, $expected, $capitalLinks = true, array $capitalLinkOverrides = [] |
| 471 |
) { |
| 472 |
$obj = $this->newObj( [ |
| 473 |
MainConfigNames::CapitalLinks => $capitalLinks, |
| 474 |
MainConfigNames::CapitalLinkOverrides => $capitalLinkOverrides, |
| 475 |
] ); |
| 476 |
$this->assertSame( $expected, $obj->isCapitalized( $ns ) ); |
| 477 |
} |
| 478 |
|
| 479 |
public static function provideIsCapitalized() { |
| 480 |
return [ |
| 481 |
|
| 482 |
[ NS_PROJECT, true ], |
| 483 |
[ NS_PROJECT_TALK, true ], |
| 484 |
[ NS_MEDIA, true ], |
| 485 |
[ NS_FILE, true ], |
| 486 |
|
| 487 |
|
| 488 |
[ NS_SPECIAL, true, false ], |
| 489 |
[ NS_USER, true, false ], |
| 490 |
[ NS_MEDIAWIKI, true, false ], |
| 491 |
|
| 492 |
|
| 493 |
[ NS_SPECIAL, true, false, [ NS_SPECIAL => false ] ], |
| 494 |
[ NS_USER, true, false, [ NS_USER => false ] ], |
| 495 |
[ NS_MEDIAWIKI, true, false, [ NS_MEDIAWIKI => false ] ], |
| 496 |
|
| 497 |
|
| 498 |
[ NS_PROJECT, false, true, [ NS_PROJECT => false ] ], |
| 499 |
[ NS_PROJECT, true, false, [ NS_PROJECT => true ] ], |
| 500 |
|
| 501 |
|
| 502 |
[ NS_MEDIA, false, true, [ NS_FILE => false, NS_MEDIA => true ] ], |
| 503 |
[ NS_MEDIA, true, false, [ NS_FILE => true, NS_MEDIA => false ] ], |
| 504 |
[ NS_FILE, false, true, [ NS_FILE => false, NS_MEDIA => true ] ], |
| 505 |
[ NS_FILE, true, false, [ NS_FILE => true, NS_MEDIA => false ] ], |
| 506 |
]; |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
public function testHasGenderDistinction() { |
| 513 |
$obj = $this->newObj(); |
| 514 |
|
| 515 |
|
| 516 |
$this->assertTrue( $obj->hasGenderDistinction( NS_USER ) ); |
| 517 |
$this->assertTrue( $obj->hasGenderDistinction( NS_USER_TALK ) ); |
| 518 |
|
| 519 |
|
| 520 |
$this->assertFalse( $obj->hasGenderDistinction( NS_MEDIA ) ); |
| 521 |
$this->assertFalse( $obj->hasGenderDistinction( NS_SPECIAL ) ); |
| 522 |
$this->assertFalse( $obj->hasGenderDistinction( NS_MAIN ) ); |
| 523 |
$this->assertFalse( $obj->hasGenderDistinction( NS_TALK ) ); |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
public function testIsNonincludable() { |
| 530 |
$obj = $this->newObj( [ MainConfigNames::NonincludableNamespaces => [ NS_USER ] ] ); |
| 531 |
$this->assertTrue( $obj->isNonincludable( NS_USER ) ); |
| 532 |
$this->assertFalse( $obj->isNonincludable( NS_TEMPLATE ) ); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
public function testGetNamespaceContentModel( $ns, $expected ) { |
| 543 |
$obj = $this->newObj( [ MainConfigNames::NamespaceContentModels => |
| 544 |
[ NS_USER => CONTENT_MODEL_WIKITEXT, 123 => CONTENT_MODEL_JSON, 1234 => 'abcdef' ], |
| 545 |
] ); |
| 546 |
$this->assertSame( $expected, $obj->getNamespaceContentModel( $ns ) ); |
| 547 |
} |
| 548 |
|
| 549 |
public static function provideGetNamespaceContentModel() { |
| 550 |
return [ |
| 551 |
[ NS_MAIN, null ], |
| 552 |
[ NS_TALK, null ], |
| 553 |
[ NS_USER, CONTENT_MODEL_WIKITEXT ], |
| 554 |
[ NS_USER_TALK, null ], |
| 555 |
[ NS_SPECIAL, null ], |
| 556 |
[ 122, null ], |
| 557 |
[ 123, CONTENT_MODEL_JSON ], |
| 558 |
[ 1234, 'abcdef' ], |
| 559 |
[ 1235, null ], |
| 560 |
]; |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
public function testGetCategoryLinkType( $ns, $expected ) { |
| 571 |
$this->assertSame( $expected, $this->newObj()->getCategoryLinkType( $ns ) ); |
| 572 |
} |
| 573 |
|
| 574 |
public static function provideGetCategoryLinkType() { |
| 575 |
return [ |
| 576 |
[ NS_MAIN, 'page' ], |
| 577 |
[ NS_TALK, 'page' ], |
| 578 |
[ NS_USER, 'page' ], |
| 579 |
[ NS_USER_TALK, 'page' ], |
| 580 |
|
| 581 |
[ NS_FILE, 'file' ], |
| 582 |
[ NS_FILE_TALK, 'page' ], |
| 583 |
|
| 584 |
[ NS_CATEGORY, 'subcat' ], |
| 585 |
[ NS_CATEGORY_TALK, 'page' ], |
| 586 |
|
| 587 |
[ 100, 'page' ], |
| 588 |
[ 101, 'page' ], |
| 589 |
]; |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
public function testGetSubject( $subject, $talk ) { |
| 610 |
$obj = $this->newObj(); |
| 611 |
$this->assertSame( $subject, $obj->getSubject( $subject ) ); |
| 612 |
$this->assertSame( $subject, $obj->getSubject( $talk ) ); |
| 613 |
|
| 614 |
$subjectTitleVal = new TitleValue( $subject, 'A' ); |
| 615 |
$talkTitleVal = new TitleValue( $talk, 'A' ); |
| 616 |
|
| 617 |
|
| 618 |
$this->assertSame( $subjectTitleVal, $obj->getSubjectPage( $subjectTitleVal ) ); |
| 619 |
$this->assertEquals( $subjectTitleVal, $obj->getSubjectPage( $talkTitleVal ) ); |
| 620 |
|
| 621 |
$subjectTitle = Title::makeTitle( $subject, 'A' ); |
| 622 |
$talkTitle = Title::makeTitle( $talk, 'A' ); |
| 623 |
$this->assertSame( $subjectTitle, $subjectTitle->getSubjectPage() ); |
| 624 |
$this->assertEquals( $subjectTitle, $talkTitle->getSubjectPage() ); |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
public function testGetSubject_special( $ns ) { |
| 635 |
$obj = $this->newObj(); |
| 636 |
$this->assertSame( $ns, $obj->getSubject( $ns ) ); |
| 637 |
|
| 638 |
$title = new TitleValue( $ns, 'A' ); |
| 639 |
$this->assertSame( $title, $obj->getSubjectPage( $title ) ); |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
public function testGetTalk( $subject, $talk ) { |
| 653 |
$obj = $this->newObj(); |
| 654 |
$this->assertSame( $talk, $obj->getTalk( $subject ) ); |
| 655 |
$this->assertSame( $talk, $obj->getTalk( $talk ) ); |
| 656 |
|
| 657 |
$subjectTitleVal = new TitleValue( $subject, 'A' ); |
| 658 |
$talkTitleVal = new TitleValue( $talk, 'A' ); |
| 659 |
|
| 660 |
|
| 661 |
$this->assertEquals( $talkTitleVal, $obj->getTalkPage( $subjectTitleVal ) ); |
| 662 |
$this->assertSame( $talkTitleVal, $obj->getTalkPage( $talkTitleVal ) ); |
| 663 |
|
| 664 |
$subjectTitle = Title::makeTitle( $subject, 'A' ); |
| 665 |
$talkTitle = Title::makeTitle( $talk, 'A' ); |
| 666 |
$this->assertEquals( $talkTitle, $subjectTitle->getTalkPage() ); |
| 667 |
$this->assertSame( $talkTitle, $talkTitle->getTalkPage() ); |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
public function testGetTalk_special( $ns ) { |
| 678 |
$this->expectException( MWException::class ); |
| 679 |
$this->expectExceptionMessage( |
| 680 |
"NamespaceInfo::getTalk does not make any sense for given namespace $ns" |
| 681 |
); |
| 682 |
$this->newObj()->getTalk( $ns ); |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
public function testGetAssociated_special( $ns ) { |
| 693 |
$this->expectException( MWException::class ); |
| 694 |
$this->expectExceptionMessage( |
| 695 |
"NamespaceInfo::getAssociated does not make any sense for given namespace $ns" |
| 696 |
); |
| 697 |
$this->newObj()->getAssociated( $ns ); |
| 698 |
} |
| 699 |
|
| 700 |
public static function provideCanHaveTalkPage() { |
| 701 |
return [ |
| 702 |
[ new TitleValue( NS_MAIN, 'Test' ), true ], |
| 703 |
[ new TitleValue( NS_TALK, 'Test' ), true ], |
| 704 |
[ new TitleValue( NS_USER, 'Test' ), true ], |
| 705 |
[ new TitleValue( NS_SPECIAL, 'Test' ), false ], |
| 706 |
[ new TitleValue( NS_MEDIA, 'Test' ), false ], |
| 707 |
[ new TitleValue( NS_MAIN, '', 'Kittens' ), false ], |
| 708 |
[ new TitleValue( NS_MAIN, 'Kittens', '', 'acme' ), false ], |
| 709 |
]; |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
public function testCanHaveTalkPage( LinkTarget $t, $expected ) { |
| 717 |
$actual = $this->newObj()->canHaveTalkPage( $t ); |
| 718 |
$this->assertEquals( $expected, $actual, $t->getDBkey() ); |
| 719 |
} |
| 720 |
|
| 721 |
public static function provideGetTalkPage_good() { |
| 722 |
return [ |
| 723 |
[ new TitleValue( NS_MAIN, 'Test' ), new TitleValue( NS_TALK, 'Test' ) ], |
| 724 |
[ new TitleValue( NS_TALK, 'Test' ), new TitleValue( NS_TALK, 'Test' ) ], |
| 725 |
[ new TitleValue( NS_USER, 'Test' ), new TitleValue( NS_USER_TALK, 'Test' ) ], |
| 726 |
]; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
public function testGetTalkPage_good( LinkTarget $t, LinkTarget $expected ) { |
| 736 |
$actual = $this->newObj()->getTalkPage( $t ); |
| 737 |
$this->assertEquals( $expected, $actual, $t->getDBkey() ); |
| 738 |
} |
| 739 |
|
| 740 |
public static function provideGetTalkPage_bad() { |
| 741 |
return [ |
| 742 |
[ new TitleValue( NS_SPECIAL, 'Test' ) ], |
| 743 |
[ new TitleValue( NS_MEDIA, 'Test' ) ], |
| 744 |
[ new TitleValue( NS_MAIN, '', 'Kittens' ) ], |
| 745 |
[ new TitleValue( NS_MAIN, 'Kittens', '', 'acme' ) ], |
| 746 |
]; |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
public function testGetTalkPage_bad( LinkTarget $t ) { |
| 756 |
$this->expectException( MWException::class ); |
| 757 |
$this->newObj()->getTalkPage( $t ); |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
public function testGetAssociatedPage_bad( LinkTarget $t ) { |
| 767 |
$this->expectException( MWException::class ); |
| 768 |
$this->newObj()->getAssociatedPage( $t ); |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
public function testGetAssociated( $subject, $talk ) { |
| 781 |
$obj = $this->newObj(); |
| 782 |
$this->assertSame( $talk, $obj->getAssociated( $subject ) ); |
| 783 |
$this->assertSame( $subject, $obj->getAssociated( $talk ) ); |
| 784 |
|
| 785 |
$subjectTitle = new TitleValue( $subject, 'A' ); |
| 786 |
$talkTitle = new TitleValue( $talk, 'A' ); |
| 787 |
|
| 788 |
$this->assertEquals( $talkTitle, $obj->getAssociatedPage( $subjectTitle ) ); |
| 789 |
$this->assertEquals( $subjectTitle, $obj->getAssociatedPage( $talkTitle ) ); |
| 790 |
|
| 791 |
$subjectTitle = Title::makeTitle( $subject, 'A' ); |
| 792 |
$talkTitle = Title::makeTitle( $talk, 'A' ); |
| 793 |
$this->assertEquals( $talkTitle, $subjectTitle->getOtherPage() ); |
| 794 |
$this->assertEquals( $subjectTitle, $talkTitle->getOtherPage() ); |
| 795 |
} |
| 796 |
|
| 797 |
public static function provideSubjectTalk() { |
| 798 |
return [ |
| 799 |
|
| 800 |
'Main/talk' => [ NS_MAIN, NS_TALK ], |
| 801 |
'User/user talk' => [ NS_USER, NS_USER_TALK ], |
| 802 |
'Unknown namespaces also supported' => [ 106, 107 ], |
| 803 |
]; |
| 804 |
} |
| 805 |
|
| 806 |
public static function provideSpecialNamespaces() { |
| 807 |
return [ |
| 808 |
'Special' => [ NS_SPECIAL ], |
| 809 |
'Media' => [ NS_MEDIA ], |
| 810 |
'Unknown negative index' => [ -613 ], |
| 811 |
]; |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
private function getDefaultNamespaces() { |
| 824 |
return [ NS_MAIN => '' ] + self::DEFAULT_OPTIONS['CanonicalNamespaceNames']; |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
public function testGetCanonicalNamespaces() { |
| 831 |
$this->assertSame( |
| 832 |
$this->getDefaultNamespaces(), |
| 833 |
$this->newObj()->getCanonicalNamespaces() |
| 834 |
); |
| 835 |
} |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
public function testGetCanonicalName( $index, $expected ) { |
| 845 |
$this->assertSame( $expected, $this->newObj()->getCanonicalName( $index ) ); |
| 846 |
} |
| 847 |
|
| 848 |
public static function provideGetCanonicalName() { |
| 849 |
return [ |
| 850 |
'Main' => [ NS_MAIN, '' ], |
| 851 |
'Talk' => [ NS_TALK, 'Talk' ], |
| 852 |
'With underscore not space' => [ NS_USER_TALK, 'User_talk' ], |
| 853 |
'Special' => [ NS_SPECIAL, 'Special' ], |
| 854 |
'Nonexistent' => [ 12345, false ], |
| 855 |
'Nonexistent negative' => [ -12345, false ], |
| 856 |
]; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
public function testGetCanonicalIndex( $name, $expected ) { |
| 867 |
$this->assertSame( $expected, $this->newObj()->getCanonicalIndex( $name ) ); |
| 868 |
} |
| 869 |
|
| 870 |
public static function provideGetCanonicalIndex() { |
| 871 |
return [ |
| 872 |
'Main' => [ '', NS_MAIN ], |
| 873 |
'Talk' => [ 'talk', NS_TALK ], |
| 874 |
'Not lowercase' => [ 'Talk', null ], |
| 875 |
'With underscore' => [ 'user_talk', NS_USER_TALK ], |
| 876 |
'Space is not recognized for underscore' => [ 'user talk', null ], |
| 877 |
'0' => [ '0', null ], |
| 878 |
]; |
| 879 |
} |
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
public function testGetValidNamespaces() { |
| 885 |
$this->assertSame( |
| 886 |
[ NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK ], |
| 887 |
$this->newObj()->getValidNamespaces() |
| 888 |
); |
| 889 |
} |
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
public function testGetCanonicalNamespaces_NoCanonicalNamespaceNames() { |
| 900 |
$obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] ); |
| 901 |
|
| 902 |
$this->assertSame( [ NS_MAIN => '' ], $obj->getCanonicalNamespaces() ); |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
public function testGetCanonicalName_NoCanonicalNamespaceNames() { |
| 909 |
$obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] ); |
| 910 |
|
| 911 |
$this->assertSame( '', $obj->getCanonicalName( NS_MAIN ) ); |
| 912 |
$this->assertFalse( $obj->getCanonicalName( NS_TALK ) ); |
| 913 |
} |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
public function testGetCanonicalIndex_NoCanonicalNamespaceNames() { |
| 919 |
$obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] ); |
| 920 |
|
| 921 |
$this->assertSame( NS_MAIN, $obj->getCanonicalIndex( '' ) ); |
| 922 |
$this->assertNull( $obj->getCanonicalIndex( 'talk' ) ); |
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
public function testGetValidNamespaces_NoCanonicalNamespaceNames() { |
| 929 |
$obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] ); |
| 930 |
|
| 931 |
$this->assertSame( [ NS_MAIN ], $obj->getValidNamespaces() ); |
| 932 |
} |
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
public function testGetCanonicalNamespaces_ExtensionNamespaces() { |
| 943 |
$this->assertSame( |
| 944 |
$this->getDefaultNamespaces() + [ 12345 => 'Extended' ], |
| 945 |
$this->newObj( [], self::TEST_EXT_NAMESPACES )->getCanonicalNamespaces() |
| 946 |
); |
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
public function testGetCanonicalName_ExtensionNamespaces() { |
| 953 |
$obj = $this->newObj( [], self::TEST_EXT_NAMESPACES ); |
| 954 |
|
| 955 |
$this->assertSame( '', $obj->getCanonicalName( NS_MAIN ) ); |
| 956 |
$this->assertSame( 'Talk', $obj->getCanonicalName( NS_TALK ) ); |
| 957 |
$this->assertSame( 'Extended', $obj->getCanonicalName( 12345 ) ); |
| 958 |
} |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
public function testGetCanonicalIndex_ExtensionNamespaces() { |
| 964 |
$obj = $this->newObj( [], self::TEST_EXT_NAMESPACES ); |
| 965 |
|
| 966 |
$this->assertSame( NS_MAIN, $obj->getCanonicalIndex( '' ) ); |
| 967 |
$this->assertSame( NS_TALK, $obj->getCanonicalIndex( 'talk' ) ); |
| 968 |
$this->assertSame( 12345, $obj->getCanonicalIndex( 'extended' ) ); |
| 969 |
} |
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
public function testGetValidNamespaces_ExtensionNamespaces() { |
| 975 |
$this->assertSame( |
| 976 |
[ NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK, 12345 ], |
| 977 |
$this->newObj( [], self::TEST_EXT_NAMESPACES )->getValidNamespaces() |
| 978 |
); |
| 979 |
} |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
private function setupHookNamespaces() { |
| 990 |
$callback = |
| 991 |
static function ( &$canonicalNamespaces ) { |
| 992 |
$canonicalNamespaces[NS_MAIN] = 'Main'; |
| 993 |
unset( $canonicalNamespaces[NS_MEDIA] ); |
| 994 |
$canonicalNamespaces[123456] = 'Hooked'; |
| 995 |
}; |
| 996 |
$this->setTemporaryHook( 'CanonicalNamespaces', $callback ); |
| 997 |
$expected = $this->getDefaultNamespaces(); |
| 998 |
( $callback )( $expected ); |
| 999 |
return $expected; |
| 1000 |
} |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
public function testGetCanonicalNamespaces_HookNamespaces() { |
| 1006 |
$expected = $this->setupHookNamespaces(); |
| 1007 |
|
| 1008 |
$this->assertSame( $expected, $this->newObj()->getCanonicalNamespaces() ); |
| 1009 |
} |
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
public function testGetCanonicalName_HookNamespaces() { |
| 1015 |
$this->setupHookNamespaces(); |
| 1016 |
$obj = $this->newObj(); |
| 1017 |
|
| 1018 |
$this->assertSame( 'Main', $obj->getCanonicalName( NS_MAIN ) ); |
| 1019 |
$this->assertFalse( $obj->getCanonicalName( NS_MEDIA ) ); |
| 1020 |
$this->assertSame( 'Hooked', $obj->getCanonicalName( 123456 ) ); |
| 1021 |
} |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
public function testGetCanonicalIndex_HookNamespaces() { |
| 1027 |
$this->setupHookNamespaces(); |
| 1028 |
$obj = $this->newObj(); |
| 1029 |
|
| 1030 |
$this->assertSame( NS_MAIN, $obj->getCanonicalIndex( 'main' ) ); |
| 1031 |
$this->assertNull( $obj->getCanonicalIndex( 'media' ) ); |
| 1032 |
$this->assertSame( 123456, $obj->getCanonicalIndex( 'hooked' ) ); |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
public function testGetValidNamespaces_HookNamespaces() { |
| 1039 |
$this->setupHookNamespaces(); |
| 1040 |
|
| 1041 |
$this->assertSame( |
| 1042 |
[ NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK, 123456 ], |
| 1043 |
$this->newObj()->getValidNamespaces() |
| 1044 |
); |
| 1045 |
} |
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
private function setupExtraNamespaces() { |
| 1056 |
return $this->newObj( [ MainConfigNames::ExtraNamespaces => |
| 1057 |
[ NS_MAIN => 'No effect', NS_TALK => 'No effect', 1234567 => 'Extra' ] |
| 1058 |
] ); |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
public function testGetCanonicalNamespaces_ExtraNamespaces() { |
| 1065 |
$this->assertSame( |
| 1066 |
$this->getDefaultNamespaces() + [ 1234567 => 'Extra' ], |
| 1067 |
$this->setupExtraNamespaces()->getCanonicalNamespaces() |
| 1068 |
); |
| 1069 |
} |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
public function testGetCanonicalName_ExtraNamespaces() { |
| 1075 |
$obj = $this->setupExtraNamespaces(); |
| 1076 |
|
| 1077 |
$this->assertSame( '', $obj->getCanonicalName( NS_MAIN ) ); |
| 1078 |
$this->assertSame( 'Talk', $obj->getCanonicalName( NS_TALK ) ); |
| 1079 |
$this->assertSame( 'Extra', $obj->getCanonicalName( 1234567 ) ); |
| 1080 |
} |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
public function testGetCanonicalIndex_ExtraNamespaces() { |
| 1086 |
$obj = $this->setupExtraNamespaces(); |
| 1087 |
|
| 1088 |
$this->assertNull( $obj->getCanonicalIndex( 'no effect' ) ); |
| 1089 |
$this->assertNull( $obj->getCanonicalIndex( 'no_effect' ) ); |
| 1090 |
$this->assertSame( 1234567, $obj->getCanonicalIndex( 'extra' ) ); |
| 1091 |
} |
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
public function testGetValidNamespaces_ExtraNamespaces() { |
| 1097 |
$this->assertSame( |
| 1098 |
[ NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK, 1234567 ], |
| 1099 |
$this->setupExtraNamespaces()->getValidNamespaces() |
| 1100 |
); |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
public function testGetCanonicalNamespaces_caching() { |
| 1112 |
$obj = $this->newObj(); |
| 1113 |
|
| 1114 |
|
| 1115 |
$obj->getCanonicalNamespaces(); |
| 1116 |
|
| 1117 |
|
| 1118 |
$this->setupHookNamespaces(); |
| 1119 |
|
| 1120 |
|
| 1121 |
$this->assertSame( $this->getDefaultNamespaces(), $obj->getCanonicalNamespaces() ); |
| 1122 |
} |
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
public function testGetCanonicalName_caching() { |
| 1128 |
$obj = $this->newObj(); |
| 1129 |
|
| 1130 |
|
| 1131 |
$obj->getCanonicalName( NS_MAIN ); |
| 1132 |
|
| 1133 |
|
| 1134 |
$this->setupHookNamespaces(); |
| 1135 |
|
| 1136 |
|
| 1137 |
$this->assertSame( '', $obj->getCanonicalName( NS_MAIN ) ); |
| 1138 |
$this->assertSame( 'Media', $obj->getCanonicalName( NS_MEDIA ) ); |
| 1139 |
$this->assertFalse( $obj->getCanonicalName( 12345 ) ); |
| 1140 |
$this->assertFalse( $obj->getCanonicalName( 123456 ) ); |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
public function testGetCanonicalIndex_caching() { |
| 1147 |
$obj = $this->newObj(); |
| 1148 |
|
| 1149 |
|
| 1150 |
$obj->getCanonicalIndex( '' ); |
| 1151 |
|
| 1152 |
|
| 1153 |
$this->setupHookNamespaces(); |
| 1154 |
|
| 1155 |
|
| 1156 |
$this->assertSame( NS_MAIN, $obj->getCanonicalIndex( '' ) ); |
| 1157 |
$this->assertSame( NS_MEDIA, $obj->getCanonicalIndex( 'media' ) ); |
| 1158 |
$this->assertNull( $obj->getCanonicalIndex( 'extended' ) ); |
| 1159 |
$this->assertNull( $obj->getCanonicalIndex( 'hooked' ) ); |
| 1160 |
} |
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
public function testGetValidNamespaces_caching() { |
| 1166 |
$obj = $this->newObj(); |
| 1167 |
|
| 1168 |
|
| 1169 |
$obj->getValidNamespaces(); |
| 1170 |
|
| 1171 |
|
| 1172 |
$this->setupHookNamespaces(); |
| 1173 |
|
| 1174 |
|
| 1175 |
$this->assertSame( |
| 1176 |
[ NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK ], |
| 1177 |
$obj->getValidNamespaces() |
| 1178 |
); |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
public function testGetValidNamespaces_misc( array $namespaces, array $expected ) { |
| 1195 |
|
| 1196 |
$this->setTemporaryHook( 'CanonicalNamespaces', |
| 1197 |
static function ( &$canonicalNamespaces ) use ( $namespaces ) { |
| 1198 |
$canonicalNamespaces = array_combine( $namespaces, $namespaces ); |
| 1199 |
} |
| 1200 |
); |
| 1201 |
$this->assertSame( $expected, $this->newObj()->getValidNamespaces() ); |
| 1202 |
} |
| 1203 |
|
| 1204 |
public static function provideGetValidNamespaces_misc() { |
| 1205 |
return [ |
| 1206 |
'Out of order (T109137)' => [ [ 1, 0 ], [ 0, 1 ] ], |
| 1207 |
'Alphabetical order' => [ [ 10, 2 ], [ 2, 10 ] ], |
| 1208 |
'Negative' => [ [ -1000, -500, -2, 0 ], [ 0 ] ], |
| 1209 |
]; |
| 1210 |
} |
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
public function testAllServiceOptionsUsed() { |
| 1219 |
$this->assertAllServiceOptionsUsed(); |
| 1220 |
} |
| 1221 |
} |
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|