| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Cache\BacklinkCache; |
| 4 |
use MediaWiki\Content\WikitextContent; |
| 5 |
use MediaWiki\Language\RawMessage; |
| 6 |
use MediaWiki\Linker\LinkTarget; |
| 7 |
use MediaWiki\MainConfigNames; |
| 8 |
use MediaWiki\Message\Message; |
| 9 |
use MediaWiki\Page\PageIdentity; |
| 10 |
use MediaWiki\Page\PageIdentityValue; |
| 11 |
use MediaWiki\Tests\Unit\DummyServicesTrait; |
| 12 |
use MediaWiki\Title\MalformedTitleException; |
| 13 |
use MediaWiki\Title\Title; |
| 14 |
use MediaWiki\Title\TitleValue; |
| 15 |
use MediaWiki\Utils\MWTimestamp; |
| 16 |
use Wikimedia\Assert\PreconditionException; |
| 17 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
class TitleTest extends MediaWikiIntegrationTestCase { |
| 24 |
use DummyServicesTrait; |
| 25 |
use LinkCacheTestTrait; |
| 26 |
|
| 27 |
protected function setUp(): void { |
| 28 |
parent::setUp(); |
| 29 |
|
| 30 |
$this->mergeMwGlobalArrayValue( |
| 31 |
'wgExtraNamespaces', |
| 32 |
[ |
| 33 |
12302 => 'TEST-JS', |
| 34 |
12303 => 'TEST-JS_TALK', |
| 35 |
] |
| 36 |
); |
| 37 |
$this->mergeMwGlobalArrayValue( |
| 38 |
'wgNamespaceContentModels', |
| 39 |
[ |
| 40 |
12302 => CONTENT_MODEL_JAVASCRIPT, |
| 41 |
] |
| 42 |
); |
| 43 |
|
| 44 |
$this->overrideConfigValues( [ |
| 45 |
MainConfigNames::AllowUserJs => false, |
| 46 |
MainConfigNames::DefaultLanguageVariant => false, |
| 47 |
MainConfigNames::MetaNamespace => 'Project', |
| 48 |
MainConfigNames::Server => 'https://example.org', |
| 49 |
MainConfigNames::CanonicalServer => 'https://example.org', |
| 50 |
MainConfigNames::ScriptPath => '/w', |
| 51 |
MainConfigNames::Script => '/w/index.php', |
| 52 |
MainConfigNames::LanguageCode => 'en', |
| 53 |
|
| 54 |
MainConfigNames::LocalInterwikis => [ 'localtestiw' ], |
| 55 |
] ); |
| 56 |
$this->setUserLang( 'en' ); |
| 57 |
|
| 58 |
|
| 59 |
$interwikiLookup = $this->getDummyInterwikiLookup( [ |
| 60 |
|
| 61 |
[ 'iw_prefix' => 'localtestiw', 'iw_url' => 'localtestiw' ], |
| 62 |
[ 'iw_prefix' => 'remotetestiw', 'iw_url' => 'remotetestiw' ], |
| 63 |
|
| 64 |
|
| 65 |
'wiki', |
| 66 |
|
| 67 |
|
| 68 |
'wikipedia', |
| 69 |
|
| 70 |
|
| 71 |
'acme', |
| 72 |
|
| 73 |
|
| 74 |
[ 'iw_prefix' => 'de', 'iw_local' => 1 ], |
| 75 |
[ 'iw_prefix' => 'zz', 'iw_local' => 0 ], |
| 76 |
|
| 77 |
|
| 78 |
[ 'iw_prefix' => 'acme', 'iw_url' => 'https://acme.test/$1' ], |
| 79 |
[ 'iw_prefix' => 'yy', 'iw_url' => 'https://yy.wiki.test/wiki/$1', 'iw_local' => true ] |
| 80 |
] ); |
| 81 |
$this->setService( 'InterwikiLookup', $interwikiLookup ); |
| 82 |
} |
| 83 |
|
| 84 |
protected function tearDown(): void { |
| 85 |
parent::tearDown(); |
| 86 |
|
| 87 |
$this->getNonexistingTestPage( 'UTest1' ); |
| 88 |
$this->getNonexistingTestPage( 'UTest2' ); |
| 89 |
} |
| 90 |
|
| 91 |
public static function provideInNamespace() { |
| 92 |
return [ |
| 93 |
[ 'Main Page', NS_MAIN, true ], |
| 94 |
[ 'Main Page', NS_TALK, false ], |
| 95 |
[ 'Main Page', NS_USER, false ], |
| 96 |
[ 'User:Foo', NS_USER, true ], |
| 97 |
[ 'User:Foo', NS_USER_TALK, false ], |
| 98 |
[ 'User:Foo', NS_TEMPLATE, false ], |
| 99 |
[ 'User_talk:Foo', NS_USER_TALK, true ], |
| 100 |
[ 'User_talk:Foo', NS_USER, false ], |
| 101 |
]; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public function testInNamespace( $title, $ns, $expectedBool ) { |
| 109 |
$title = Title::newFromText( $title ); |
| 110 |
$this->assertEquals( $expectedBool, $title->inNamespace( $ns ) ); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public function testInNamespaces() { |
| 117 |
$mainpage = Title::newFromText( 'Main Page' ); |
| 118 |
$this->assertTrue( $mainpage->inNamespaces( NS_MAIN, NS_USER ) ); |
| 119 |
$this->assertTrue( $mainpage->inNamespaces( [ NS_MAIN, NS_USER ] ) ); |
| 120 |
$this->assertTrue( $mainpage->inNamespaces( [ NS_USER, NS_MAIN ] ) ); |
| 121 |
$this->assertFalse( $mainpage->inNamespaces( [ NS_PROJECT, NS_TEMPLATE ] ) ); |
| 122 |
} |
| 123 |
|
| 124 |
public static function provideHasSubjectNamespace() { |
| 125 |
return [ |
| 126 |
[ 'Main Page', NS_MAIN, true ], |
| 127 |
[ 'Main Page', NS_TALK, true ], |
| 128 |
[ 'Main Page', NS_USER, false ], |
| 129 |
[ 'User:Foo', NS_USER, true ], |
| 130 |
[ 'User:Foo', NS_USER_TALK, true ], |
| 131 |
[ 'User:Foo', NS_TEMPLATE, false ], |
| 132 |
[ 'User_talk:Foo', NS_USER_TALK, true ], |
| 133 |
[ 'User_talk:Foo', NS_USER, true ], |
| 134 |
]; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public function testHasSubjectNamespace( $title, $ns, $expectedBool ) { |
| 142 |
$title = Title::newFromText( $title ); |
| 143 |
$this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) ); |
| 144 |
} |
| 145 |
|
| 146 |
public function dataGetContentModel() { |
| 147 |
return [ |
| 148 |
[ 'Help:Foo', CONTENT_MODEL_WIKITEXT ], |
| 149 |
[ 'Help:Foo.js', CONTENT_MODEL_WIKITEXT ], |
| 150 |
[ 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT ], |
| 151 |
[ 'User:Foo', CONTENT_MODEL_WIKITEXT ], |
| 152 |
[ 'User:Foo.js', CONTENT_MODEL_WIKITEXT ], |
| 153 |
[ 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ], |
| 154 |
[ 'User:Foo/bar.css', CONTENT_MODEL_CSS ], |
| 155 |
[ 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT ], |
| 156 |
[ 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT ], |
| 157 |
[ 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT ], |
| 158 |
[ 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT ], |
| 159 |
[ 'MediaWiki:Foo.css', CONTENT_MODEL_CSS ], |
| 160 |
[ 'MediaWiki:Foo/bar.css', CONTENT_MODEL_CSS ], |
| 161 |
[ 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT ], |
| 162 |
[ 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT ], |
| 163 |
[ 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT ], |
| 164 |
[ 'TEST-JS:Foo', CONTENT_MODEL_JAVASCRIPT ], |
| 165 |
[ 'TEST-JS:Foo.js', CONTENT_MODEL_JAVASCRIPT ], |
| 166 |
[ 'TEST-JS:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ], |
| 167 |
[ 'TEST-JS_TALK:Foo.js', CONTENT_MODEL_WIKITEXT ], |
| 168 |
]; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public function testGetContentModel( $title, $expectedModelId ) { |
| 176 |
$title = Title::newFromText( $title ); |
| 177 |
$this->assertEquals( $expectedModelId, $title->getContentModel() ); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public function testHasContentModel( $title, $expectedModelId ) { |
| 185 |
$title = Title::newFromText( $title ); |
| 186 |
$this->assertTrue( $title->hasContentModel( $expectedModelId ) ); |
| 187 |
} |
| 188 |
|
| 189 |
public static function provideIsSiteConfigPage() { |
| 190 |
return [ |
| 191 |
[ 'Help:Foo', false ], |
| 192 |
[ 'Help:Foo.js', false ], |
| 193 |
[ 'Help:Foo/bar.js', false ], |
| 194 |
[ 'User:Foo', false ], |
| 195 |
[ 'User:Foo.js', false ], |
| 196 |
[ 'User:Foo/bar.js', false ], |
| 197 |
[ 'User:Foo/bar.json', false ], |
| 198 |
[ 'User:Foo/bar.css', false ], |
| 199 |
[ 'User:Foo/bar.JS', false ], |
| 200 |
[ 'User:Foo/bar.JSON', false ], |
| 201 |
[ 'User:Foo/bar.CSS', false ], |
| 202 |
[ 'User talk:Foo/bar.css', false ], |
| 203 |
[ 'User:Foo/bar.js.xxx', false ], |
| 204 |
[ 'User:Foo/bar.xxx', false ], |
| 205 |
[ 'MediaWiki:Foo.js', 'javascript' ], |
| 206 |
[ 'MediaWiki:Foo.json', 'json' ], |
| 207 |
[ 'MediaWiki:Foo.css', 'css' ], |
| 208 |
[ 'MediaWiki:Foo.JS', false ], |
| 209 |
[ 'MediaWiki:Foo.JSON', false ], |
| 210 |
[ 'MediaWiki:Foo.CSS', false ], |
| 211 |
[ 'MediaWiki:Foo/bar.css', 'css' ], |
| 212 |
[ 'MediaWiki:Foo.css.xxx', false ], |
| 213 |
[ 'TEST-JS:Foo', false ], |
| 214 |
[ 'TEST-JS:Foo.js', false ], |
| 215 |
]; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
public function testSiteConfigPage( $title, $expected ) { |
| 226 |
$title = Title::newFromText( $title ); |
| 227 |
|
| 228 |
|
| 229 |
$this->assertSame( |
| 230 |
$expected !== false, |
| 231 |
$title->isSiteConfigPage() |
| 232 |
); |
| 233 |
$this->assertSame( |
| 234 |
$expected === 'javascript', |
| 235 |
$title->isSiteJsConfigPage() |
| 236 |
); |
| 237 |
$this->assertSame( |
| 238 |
$expected === 'json', |
| 239 |
$title->isSiteJsonConfigPage() |
| 240 |
); |
| 241 |
$this->assertSame( |
| 242 |
$expected === 'css', |
| 243 |
$title->isSiteCssConfigPage() |
| 244 |
); |
| 245 |
} |
| 246 |
|
| 247 |
public static function provideIsUserConfigPage() { |
| 248 |
return [ |
| 249 |
[ 'Help:Foo', false ], |
| 250 |
[ 'Help:Foo.js', false ], |
| 251 |
[ 'Help:Foo/bar.js', false ], |
| 252 |
[ 'User:Foo', false ], |
| 253 |
[ 'User:Foo.js', false ], |
| 254 |
[ 'User:Foo/bar.js', 'javascript' ], |
| 255 |
[ 'User:Foo/bar.JS', false ], |
| 256 |
[ 'User:Foo/bar.json', 'json' ], |
| 257 |
[ 'User:Foo/bar.JSON', false ], |
| 258 |
[ 'User:Foo/bar.css', 'css' ], |
| 259 |
[ 'User:Foo/bar.CSS', false ], |
| 260 |
[ 'User talk:Foo/bar.css', false ], |
| 261 |
[ 'User:Foo/bar.js.xxx', false ], |
| 262 |
[ 'User:Foo/bar.xxx', false ], |
| 263 |
[ 'MediaWiki:Foo.js', false ], |
| 264 |
[ 'MediaWiki:Foo.json', false ], |
| 265 |
[ 'MediaWiki:Foo.css', false ], |
| 266 |
[ 'MediaWiki:Foo.JS', false ], |
| 267 |
[ 'MediaWiki:Foo.JSON', false ], |
| 268 |
[ 'MediaWiki:Foo.CSS', false ], |
| 269 |
[ 'MediaWiki:Foo.css.xxx', false ], |
| 270 |
[ 'TEST-JS:Foo', false ], |
| 271 |
[ 'TEST-JS:Foo.js', false ], |
| 272 |
]; |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
public function testIsUserConfigPage( $title, $expected ) { |
| 283 |
$title = Title::newFromText( $title ); |
| 284 |
|
| 285 |
|
| 286 |
$this->assertSame( |
| 287 |
$expected !== false, |
| 288 |
$title->isUserConfigPage() |
| 289 |
); |
| 290 |
$this->assertSame( |
| 291 |
$expected === 'javascript', |
| 292 |
$title->isUserJsConfigPage() |
| 293 |
); |
| 294 |
$this->assertSame( |
| 295 |
$expected === 'json', |
| 296 |
$title->isUserJsonConfigPage() |
| 297 |
); |
| 298 |
$this->assertSame( |
| 299 |
$expected === 'css', |
| 300 |
$title->isUserCssConfigPage() |
| 301 |
); |
| 302 |
} |
| 303 |
|
| 304 |
public static function provideIsWikitextPage() { |
| 305 |
return [ |
| 306 |
[ 'Help:Foo', true ], |
| 307 |
[ 'Help:Foo.js', true ], |
| 308 |
[ 'Help:Foo/bar.js', true ], |
| 309 |
[ 'User:Foo', true ], |
| 310 |
[ 'User:Foo.js', true ], |
| 311 |
[ 'User:Foo/bar.js', false ], |
| 312 |
[ 'User:Foo/bar.json', false ], |
| 313 |
[ 'User:Foo/bar.css', false ], |
| 314 |
[ 'User talk:Foo/bar.css', true ], |
| 315 |
[ 'User:Foo/bar.js.xxx', true ], |
| 316 |
[ 'User:Foo/bar.xxx', true ], |
| 317 |
[ 'MediaWiki:Foo.js', false ], |
| 318 |
[ 'User:Foo/bar.JS', true ], |
| 319 |
[ 'User:Foo/bar.JSON', true ], |
| 320 |
[ 'User:Foo/bar.CSS', true ], |
| 321 |
[ 'MediaWiki:Foo.json', false ], |
| 322 |
[ 'MediaWiki:Foo.css', false ], |
| 323 |
[ 'MediaWiki:Foo.JS', true ], |
| 324 |
[ 'MediaWiki:Foo.JSON', true ], |
| 325 |
[ 'MediaWiki:Foo.CSS', true ], |
| 326 |
[ 'MediaWiki:Foo.css.xxx', true ], |
| 327 |
[ 'TEST-JS:Foo', false ], |
| 328 |
[ 'TEST-JS:Foo.js', false ], |
| 329 |
]; |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
public function testIsWikitextPage( $title, $expectedBool ) { |
| 337 |
$title = Title::newFromText( $title ); |
| 338 |
$this->assertEquals( $expectedBool, $title->isWikitextPage() ); |
| 339 |
} |
| 340 |
|
| 341 |
public static function provideGetOtherPage() { |
| 342 |
return [ |
| 343 |
[ 'Main Page', 'Talk:Main Page' ], |
| 344 |
[ 'Talk:Main Page', 'Main Page' ], |
| 345 |
[ 'Help:Main Page', 'Help talk:Main Page' ], |
| 346 |
[ 'Help talk:Main Page', 'Help:Main Page' ], |
| 347 |
[ 'Special:FooBar', null ], |
| 348 |
[ 'Media:File.jpg', null ], |
| 349 |
]; |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
public function testGetOtherPage( $text, $expected ) { |
| 360 |
if ( $expected === null ) { |
| 361 |
$this->expectException( MWException::class ); |
| 362 |
} |
| 363 |
|
| 364 |
$title = Title::newFromText( $text ); |
| 365 |
$this->assertEquals( $expected, $title->getOtherPage()->getPrefixedText() ); |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
public function testClearCaches() { |
| 372 |
$linkCache = $this->getServiceContainer()->getLinkCache(); |
| 373 |
|
| 374 |
$title1 = Title::newFromText( 'Foo' ); |
| 375 |
$this->addGoodLinkObject( 23, $title1 ); |
| 376 |
|
| 377 |
Title::clearCaches(); |
| 378 |
|
| 379 |
$title2 = Title::newFromText( 'Foo' ); |
| 380 |
$this->assertNotSame( $title1, $title2, 'title cache should be empty' ); |
| 381 |
$this->assertSame( 0, $linkCache->getGoodLinkID( 'Foo' ), 'link cache should be empty' ); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
public function testUseCaches() { |
| 388 |
$title1 = Title::makeTitle( NS_MAIN, __METHOD__ . '998724352' ); |
| 389 |
$this->addGoodLinkObject( 23, $title1, 7, 0, 42 ); |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
$this->assertSame( 23, $title1->getArticleID() ); |
| 394 |
$this->assertSame( 42, $title1->getLatestRevID() ); |
| 395 |
} |
| 396 |
|
| 397 |
public static function provideGetLinkURL() { |
| 398 |
yield 'Simple' => [ |
| 399 |
'/wiki/Goats', |
| 400 |
NS_MAIN, |
| 401 |
'Goats' |
| 402 |
]; |
| 403 |
|
| 404 |
yield 'Fragment' => [ |
| 405 |
'/wiki/Goats#Goatificatiön', |
| 406 |
NS_MAIN, |
| 407 |
'Goats', |
| 408 |
'Goatificatiön' |
| 409 |
]; |
| 410 |
|
| 411 |
yield 'Fragment only (query is ignored)' => [ |
| 412 |
'#Goatificatiön', |
| 413 |
NS_MAIN, |
| 414 |
'', |
| 415 |
'Goatificatiön', |
| 416 |
'', |
| 417 |
[ |
| 418 |
'a' => 1, |
| 419 |
] |
| 420 |
]; |
| 421 |
|
| 422 |
yield 'Unknown interwiki with fragment' => [ |
| 423 |
'https://xx.wiki.test/wiki/xyzzy:Goats#Goatificatiön', |
| 424 |
NS_MAIN, |
| 425 |
'Goats', |
| 426 |
'Goatificatiön', |
| 427 |
'xyzzy' |
| 428 |
]; |
| 429 |
|
| 430 |
yield 'Interwiki with fragment' => [ |
| 431 |
'https://acme.test/Goats#Goatificati.C3.B6n', |
| 432 |
NS_MAIN, |
| 433 |
'Goats', |
| 434 |
'Goatificatiön', |
| 435 |
'acme' |
| 436 |
]; |
| 437 |
|
| 438 |
yield 'Interwiki with query' => [ |
| 439 |
'https://acme.test/Goats?a=1&b=blank+blank#Goatificati.C3.B6n', |
| 440 |
NS_MAIN, |
| 441 |
'Goats', |
| 442 |
'Goatificatiön', |
| 443 |
'acme', |
| 444 |
[ |
| 445 |
'a' => 1, |
| 446 |
'b' => 'blank blank' |
| 447 |
] |
| 448 |
]; |
| 449 |
|
| 450 |
yield 'Local interwiki with fragment' => [ |
| 451 |
'https://yy.wiki.test/wiki/Goats#Goatificatiön', |
| 452 |
NS_MAIN, |
| 453 |
'Goats', |
| 454 |
'Goatificatiön', |
| 455 |
'yy' |
| 456 |
]; |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
public function testGetLinkURL( |
| 468 |
$expected, |
| 469 |
$ns, |
| 470 |
$title, |
| 471 |
$fragment = '', |
| 472 |
$interwiki = '', |
| 473 |
$query = '', |
| 474 |
$query2 = false, |
| 475 |
$proto = false |
| 476 |
) { |
| 477 |
$this->overrideConfigValues( [ |
| 478 |
MainConfigNames::Server => 'https://xx.wiki.test', |
| 479 |
MainConfigNames::ExternalInterwikiFragmentMode => 'legacy', |
| 480 |
MainConfigNames::FragmentMode => [ 'html5', 'legacy' ] |
| 481 |
] ); |
| 482 |
|
| 483 |
$title = Title::makeTitle( $ns, $title, $fragment, $interwiki ); |
| 484 |
$this->assertSame( $expected, $title->getLinkURL( $query, $query2, $proto ) ); |
| 485 |
} |
| 486 |
|
| 487 |
public static function provideProperPage() { |
| 488 |
return [ |
| 489 |
[ NS_MAIN, 'Test' ], |
| 490 |
[ NS_MAIN, 'User' ], |
| 491 |
]; |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
public function testToPageIdentity( $ns, $text ) { |
| 499 |
$title = Title::makeTitle( $ns, $text ); |
| 500 |
|
| 501 |
$page = $title->toPageIdentity(); |
| 502 |
|
| 503 |
$this->assertNotSame( $title, $page ); |
| 504 |
$this->assertSame( $title->getId(), $page->getId() ); |
| 505 |
$this->assertSame( $title->getNamespace(), $page->getNamespace() ); |
| 506 |
$this->assertSame( $title->getDBkey(), $page->getDBkey() ); |
| 507 |
$this->assertSame( $title->getWikiId(), $page->getWikiId() ); |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
public function testToPageRecord( $ns, $text ) { |
| 515 |
$title = Title::makeTitle( $ns, $text ); |
| 516 |
$wikiPage = $this->getExistingTestPage( $title ); |
| 517 |
|
| 518 |
$record = $title->toPageRecord(); |
| 519 |
|
| 520 |
$this->assertNotSame( $title, $record ); |
| 521 |
$this->assertNotSame( $title, $wikiPage ); |
| 522 |
|
| 523 |
$this->assertSame( $title->getId(), $record->getId() ); |
| 524 |
$this->assertSame( $title->getNamespace(), $record->getNamespace() ); |
| 525 |
$this->assertSame( $title->getDBkey(), $record->getDBkey() ); |
| 526 |
$this->assertSame( $title->getWikiId(), $record->getWikiId() ); |
| 527 |
|
| 528 |
$this->assertSame( $title->getLatestRevID(), $record->getLatest() ); |
| 529 |
$this->assertSame( MWTimestamp::convert( TS_MW, $title->getTouched() ), $record->getTouched() ); |
| 530 |
$this->assertSame( $title->isNewPage(), $record->isNew() ); |
| 531 |
$this->assertSame( $title->isRedirect(), $record->isRedirect() ); |
| 532 |
$this->assertSame( $title->getTouched(), $record->getTouched() ); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
public function testToPageRecord_fail( $ns, $text, $fragment = '', $interwiki = '' ) { |
| 540 |
$title = Title::makeTitle( $ns, $text, $fragment, $interwiki ); |
| 541 |
|
| 542 |
$this->expectException( PreconditionException::class ); |
| 543 |
$title->toPageRecord(); |
| 544 |
} |
| 545 |
|
| 546 |
public static function provideImproperPage() { |
| 547 |
return [ |
| 548 |
[ NS_MAIN, '' ], |
| 549 |
[ NS_MAIN, '<>' ], |
| 550 |
[ NS_MAIN, '|' ], |
| 551 |
[ NS_MAIN, '#' ], |
| 552 |
[ NS_PROJECT, '#test' ], |
| 553 |
[ NS_MAIN, '', 'test', 'acme' ], |
| 554 |
[ NS_MAIN, ' Test' ], |
| 555 |
[ NS_MAIN, '_Test' ], |
| 556 |
[ NS_MAIN, 'Test ' ], |
| 557 |
[ NS_MAIN, 'Test_' ], |
| 558 |
[ NS_MAIN, "Test\nthis" ], |
| 559 |
[ NS_MAIN, "Test\tthis" ], |
| 560 |
[ -33, 'Test' ], |
| 561 |
[ 77663399, 'Test' ], |
| 562 |
|
| 563 |
|
| 564 |
[ NS_MAIN, '', 'test' ], |
| 565 |
[ NS_SPECIAL, 'Test' ], |
| 566 |
[ NS_MAIN, 'Test', '', 'acme' ], |
| 567 |
]; |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
public function testGetId_fail( $ns, $text, $fragment = '', $interwiki = '' ) { |
| 575 |
$title = Title::makeTitle( $ns, $text, $fragment, $interwiki ); |
| 576 |
|
| 577 |
$this->expectException( PreconditionException::class ); |
| 578 |
$title->getId(); |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
public function testGetId_fragment() { |
| 586 |
$title = Title::makeTitle( NS_MAIN, 'Test', 'References' ); |
| 587 |
|
| 588 |
|
| 589 |
$this->assertIsInt( $title->getId() ); |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
public function testToPageIdentity_fail( $ns, $text, $fragment = '', $interwiki = '' ) { |
| 597 |
$title = Title::makeTitle( $ns, $text, $fragment, $interwiki ); |
| 598 |
|
| 599 |
$this->expectException( PreconditionException::class ); |
| 600 |
$title->toPageIdentity(); |
| 601 |
} |
| 602 |
|
| 603 |
public static function provideMakeTitle() { |
| 604 |
yield 'main namespace' => [ 'Foo', NS_MAIN, 'Foo' ]; |
| 605 |
yield 'user namespace' => [ 'User:Foo', NS_USER, 'Foo' ]; |
| 606 |
yield 'fragment' => [ 'Foo#Section', NS_MAIN, 'Foo', 'Section' ]; |
| 607 |
yield 'only fragment' => [ '#Section', NS_MAIN, '', 'Section' ]; |
| 608 |
yield 'interwiki' => [ 'acme:Foo', NS_MAIN, 'Foo', '', 'acme' ]; |
| 609 |
yield 'normalized underscores' => [ 'Foo Bar', NS_MAIN, 'Foo_Bar' ]; |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
public function testMakeTitle( $expected, $ns, $text, $fragment = '', $interwiki = '' ) { |
| 617 |
$title = Title::makeTitle( $ns, $text, $fragment, $interwiki ); |
| 618 |
|
| 619 |
$this->assertTrue( $title->isValid() ); |
| 620 |
$this->assertSame( $expected, $title->getFullText() ); |
| 621 |
} |
| 622 |
|
| 623 |
public static function provideMakeTitle_invalid() { |
| 624 |
yield 'bad namespace' => [ 'Special:Badtitle/NS-1234:Foo', -1234, 'Foo' ]; |
| 625 |
yield 'lower case' => [ 'User:foo', NS_USER, 'foo' ]; |
| 626 |
yield 'empty' => [ '', NS_MAIN, '' ]; |
| 627 |
yield 'bad character' => [ 'Foo|Bar', NS_MAIN, 'Foo|Bar' ]; |
| 628 |
yield 'bad interwiki' => [ 'qwerty:Foo', NS_MAIN, 'Foo', '', 'qwerty' ]; |
| 629 |
} |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
public function testMakeTitle_invalid( $expected, $ns, $text, $fragment = '', $interwiki = '' ) { |
| 636 |
$title = Title::makeTitle( $ns, $text, $fragment, $interwiki ); |
| 637 |
|
| 638 |
$this->assertFalse( $title->isValid() ); |
| 639 |
$this->assertSame( $expected, $title->getFullText() ); |
| 640 |
} |
| 641 |
|
| 642 |
public static function provideMakeName() { |
| 643 |
yield 'main namespace' => [ 'Foo', NS_MAIN, 'Foo' ]; |
| 644 |
yield 'user namespace' => [ 'User:Foo', NS_USER, 'Foo' ]; |
| 645 |
yield 'fragment' => [ 'Foo#Section', NS_MAIN, 'Foo', 'Section' ]; |
| 646 |
yield 'only fragment' => [ '#Section', NS_MAIN, '', 'Section' ]; |
| 647 |
yield 'interwiki' => [ 'acme:Foo', NS_MAIN, 'Foo', '', 'acme' ]; |
| 648 |
yield 'bad namespace' => [ 'Special:Badtitle/NS-1234:Foo', -1234, 'Foo' ]; |
| 649 |
yield 'lower case' => [ 'User:foo', NS_USER, 'foo' ]; |
| 650 |
yield 'empty' => [ '', NS_MAIN, '' ]; |
| 651 |
yield 'bad character' => [ 'Foo|Bar', NS_MAIN, 'Foo|Bar' ]; |
| 652 |
yield 'bad interwiki' => [ 'qwerty:Foo', NS_MAIN, 'Foo', '', 'qwerty' ]; |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
public function testMakeName( $expected, $ns, $text, $fragment = '', $interwiki = '' ) { |
| 660 |
$titleName = Title::makeName( $ns, $text, $fragment, $interwiki ); |
| 661 |
|
| 662 |
$this->assertSame( $expected, $titleName ); |
| 663 |
} |
| 664 |
|
| 665 |
public static function provideMakeTitleSafe() { |
| 666 |
yield 'main namespace' => [ 'Foo', NS_MAIN, 'Foo' ]; |
| 667 |
yield 'user namespace' => [ 'User:Foo', NS_USER, 'Foo' ]; |
| 668 |
yield 'fragment' => [ 'Foo#Section', NS_MAIN, 'Foo', 'Section' ]; |
| 669 |
yield 'only fragment' => [ '#Section', NS_MAIN, '', 'Section' ]; |
| 670 |
yield 'interwiki' => [ 'acme:Foo', NS_MAIN, 'Foo', '', 'acme' ]; |
| 671 |
|
| 672 |
|
| 673 |
yield 'normalized underscores' => [ 'Foo Bar', NS_MAIN, 'Foo_Bar' ]; |
| 674 |
yield 'lower case' => [ 'User:Foo', NS_USER, 'foo' ]; |
| 675 |
|
| 676 |
|
| 677 |
yield 'bad interwiki' => [ 'Qwerty:Foo', NS_MAIN, 'Foo', '', 'qwerty' ]; |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
public function testMakeTitleSafe( $expected, $ns, $text, $fragment = '', $interwiki = '' ) { |
| 685 |
$title = Title::makeTitleSafe( $ns, $text, $fragment, $interwiki ); |
| 686 |
|
| 687 |
$this->assertTrue( $title->isValid() ); |
| 688 |
$this->assertSame( $expected, $title->getFullText() ); |
| 689 |
} |
| 690 |
|
| 691 |
public static function provideMakeTitleSafe_invalid() { |
| 692 |
yield 'bad namespace' => [ -1234, 'Foo' ]; |
| 693 |
yield 'empty' => [ '', NS_MAIN, '' ]; |
| 694 |
yield 'bad character' => [ NS_MAIN, 'Foo|Bar' ]; |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
public function testMakeTitleSafe_invalid( $ns, $text, $fragment = '', $interwiki = '' ) { |
| 702 |
$title = Title::makeTitleSafe( $ns, $text, $fragment, $interwiki ); |
| 703 |
|
| 704 |
$this->assertNull( $title ); |
| 705 |
} |
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
public function testSetContentModel() { |
| 713 |
|
| 714 |
$title = Title::newFromText( 'Foo' ); |
| 715 |
|
| 716 |
$title->setContentModel( CONTENT_MODEL_UNKNOWN ); |
| 717 |
$this->assertSame( CONTENT_MODEL_UNKNOWN, $title->getContentModel() ); |
| 718 |
|
| 719 |
|
| 720 |
$title = Title::newFromText( 'Foo' ); |
| 721 |
$this->assertNotSame( CONTENT_MODEL_UNKNOWN, $title->getContentModel() ); |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
public function testNewFromId() { |
| 729 |
|
| 730 |
$existingPage1 = $this->getExistingTestPage( 'UTest1' ); |
| 731 |
$existingTitle1 = $existingPage1->getTitle(); |
| 732 |
$existingId1 = $existingTitle1->getId(); |
| 733 |
|
| 734 |
$this->assertGreaterThan( 0, $existingId1, 'Existing test page should have a positive id' ); |
| 735 |
|
| 736 |
$newFromId1 = Title::newFromID( $existingId1 ); |
| 737 |
$this->assertInstanceOf( Title::class, $newFromId1, 'newFromID returns a title for an existing id' ); |
| 738 |
$this->assertTrue( |
| 739 |
$newFromId1->equals( $existingTitle1 ), |
| 740 |
'newFromID returns the correct title' |
| 741 |
); |
| 742 |
|
| 743 |
|
| 744 |
$existingPage2 = $this->getExistingTestPage( 'UTest2' ); |
| 745 |
$existingTitle2 = $existingPage2->getTitle(); |
| 746 |
$existingId2 = $existingTitle2->getId(); |
| 747 |
|
| 748 |
$this->assertGreaterThan( 0, $existingId2, 'Existing test page should have a positive id' ); |
| 749 |
|
| 750 |
$newFromId2 = Title::newFromID( $existingId2 ); |
| 751 |
$this->assertInstanceOf( Title::class, $newFromId2, 'newFromID returns a title for an existing id' ); |
| 752 |
$this->assertTrue( |
| 753 |
$newFromId2->equals( $existingTitle2 ), |
| 754 |
'newFromID returns the correct title' |
| 755 |
); |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
public function testNewFromMissingId() { |
| 762 |
|
| 763 |
$maxPageId = (int)$this->getDb()->newSelectQueryBuilder() |
| 764 |
->select( 'max(page_id)' ) |
| 765 |
->from( 'page' ) |
| 766 |
->caller( __METHOD__ )->fetchField(); |
| 767 |
$res = Title::newFromID( $maxPageId + 1 ); |
| 768 |
$this->assertNull( $res, 'newFromID returns null for missing ids' ); |
| 769 |
} |
| 770 |
|
| 771 |
public static function provideValidSecureAndSplit() { |
| 772 |
return [ |
| 773 |
[ 'Sandbox' ], |
| 774 |
[ 'A "B"' ], |
| 775 |
[ 'A \'B\'' ], |
| 776 |
[ '.com' ], |
| 777 |
[ '~' ], |
| 778 |
[ '#' ], |
| 779 |
[ '"' ], |
| 780 |
[ '\'' ], |
| 781 |
[ 'Talk:Sandbox' ], |
| 782 |
[ 'Talk:Foo:Sandbox' ], |
| 783 |
[ 'File:Example.svg' ], |
| 784 |
[ 'File_talk:Example.svg' ], |
| 785 |
[ 'Foo/.../Sandbox' ], |
| 786 |
[ 'Sandbox/...' ], |
| 787 |
[ 'A~~' ], |
| 788 |
[ ':A' ], |
| 789 |
|
| 790 |
[ 'Category:' . str_repeat( 'x', 248 ) ], |
| 791 |
[ str_repeat( 'x', 252 ) ], |
| 792 |
|
| 793 |
[ 'localtestiw: #anchor' ], |
| 794 |
[ 'localtestiw:' ], |
| 795 |
[ 'localtestiw:foo' ], |
| 796 |
[ 'localtestiw: foo # anchor' ], |
| 797 |
[ 'localtestiw: Talk: Sandbox # anchor' ], |
| 798 |
[ 'remotetestiw:' ], |
| 799 |
[ 'remotetestiw: Talk: # anchor' ], |
| 800 |
[ 'remotetestiw: #bar' ], |
| 801 |
[ 'remotetestiw: Talk:' ], |
| 802 |
[ 'remotetestiw: Talk: Foo' ], |
| 803 |
[ 'localtestiw:remotetestiw:' ], |
| 804 |
[ 'localtestiw:remotetestiw:foo' ] |
| 805 |
]; |
| 806 |
} |
| 807 |
|
| 808 |
public static function provideInvalidSecureAndSplit() { |
| 809 |
return [ |
| 810 |
[ '', 'title-invalid-empty' ], |
| 811 |
[ ':', 'title-invalid-empty' ], |
| 812 |
[ '__ __', 'title-invalid-empty' ], |
| 813 |
[ ' __ ', 'title-invalid-empty' ], |
| 814 |
|
| 815 |
[ 'A [ B', 'title-invalid-characters' ], |
| 816 |
[ 'A ] B', 'title-invalid-characters' ], |
| 817 |
[ 'A { B', 'title-invalid-characters' ], |
| 818 |
[ 'A } B', 'title-invalid-characters' ], |
| 819 |
[ 'A < B', 'title-invalid-characters' ], |
| 820 |
[ 'A > B', 'title-invalid-characters' ], |
| 821 |
[ 'A | B', 'title-invalid-characters' ], |
| 822 |
[ "A \t B", 'title-invalid-characters' ], |
| 823 |
[ "A \n B", 'title-invalid-characters' ], |
| 824 |
|
| 825 |
[ 'A%20B', 'title-invalid-characters' ], |
| 826 |
[ 'A%23B', 'title-invalid-characters' ], |
| 827 |
[ 'A%2523B', 'title-invalid-characters' ], |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
[ 'Talk:File:Example.svg', 'title-invalid-talk-namespace' ], |
| 834 |
|
| 835 |
[ '.', 'title-invalid-relative' ], |
| 836 |
[ '..', 'title-invalid-relative' ], |
| 837 |
[ './Sandbox', 'title-invalid-relative' ], |
| 838 |
[ '../Sandbox', 'title-invalid-relative' ], |
| 839 |
[ 'Foo/./Sandbox', 'title-invalid-relative' ], |
| 840 |
[ 'Foo/../Sandbox', 'title-invalid-relative' ], |
| 841 |
[ 'Sandbox/.', 'title-invalid-relative' ], |
| 842 |
[ 'Sandbox/..', 'title-invalid-relative' ], |
| 843 |
|
| 844 |
[ 'A ~~~ Name', 'title-invalid-magic-tilde' ], |
| 845 |
[ 'A ~~~~ Signature', 'title-invalid-magic-tilde' ], |
| 846 |
[ 'A ~~~~~ Timestamp', 'title-invalid-magic-tilde' ], |
| 847 |
|
| 848 |
[ str_repeat( 'x', 256 ), 'title-invalid-too-long' ], |
| 849 |
|
| 850 |
[ 'Talk:', 'title-invalid-empty' ], |
| 851 |
[ 'Talk:#', 'title-invalid-empty' ], |
| 852 |
[ 'Category: ', 'title-invalid-empty' ], |
| 853 |
[ 'Category: #bar', 'title-invalid-empty' ], |
| 854 |
|
| 855 |
[ 'localtestiw: Talk: # anchor', 'title-invalid-empty' ], |
| 856 |
[ 'localtestiw: Talk:', 'title-invalid-empty' ] |
| 857 |
]; |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
public function testSecureAndSplitValid( $text ) { |
| 867 |
$this->assertInstanceOf( Title::class, Title::newFromText( $text ), "Valid: $text" ); |
| 868 |
} |
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
public function testSecureAndSplitInvalid( $text, $expectedErrorMessage ) { |
| 877 |
try { |
| 878 |
Title::newFromTextThrow( $text ); |
| 879 |
$this->fail( "Title::newFromTextThrow should have thrown with $text" ); |
| 880 |
} catch ( MalformedTitleException $ex ) { |
| 881 |
$this->assertEquals( $expectedErrorMessage, $ex->getErrorMessage(), "Invalid: $text" ); |
| 882 |
} |
| 883 |
} |
| 884 |
|
| 885 |
public static function provideSpecialNamesWithAndWithoutParameter() { |
| 886 |
return [ |
| 887 |
[ 'Special:Version', null ], |
| 888 |
[ 'Special:Version/', '' ], |
| 889 |
[ 'Special:Version/param', 'param' ], |
| 890 |
]; |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
public function testFixSpecialNameRetainsParameter( $text, $expectedParam ) { |
| 898 |
$title = Title::newFromText( $text ); |
| 899 |
$fixed = $title->fixSpecialName(); |
| 900 |
$stuff = explode( '/', $fixed->getDBkey(), 2 ); |
| 901 |
$par = $stuff[1] ?? null; |
| 902 |
$this->assertEquals( |
| 903 |
$expectedParam, |
| 904 |
$par, |
| 905 |
"T33100 regression check: Title->fixSpecialName() should preserve parameter" |
| 906 |
); |
| 907 |
} |
| 908 |
|
| 909 |
public function flattenErrorsArray( $errors ) { |
| 910 |
$result = []; |
| 911 |
foreach ( $errors as $error ) { |
| 912 |
$result[] = $error[0]; |
| 913 |
} |
| 914 |
|
| 915 |
return $result; |
| 916 |
} |
| 917 |
|
| 918 |
public static function provideGetPageViewLanguage() { |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
return [ |
| 926 |
[ 'fr', 'Help:I_need_somebody', 'fr', 'fr', false ], |
| 927 |
[ 'es', 'Help:I_need_somebody', 'es', 'zh-tw', false ], |
| 928 |
[ 'zh', 'Help:I_need_somebody', 'zh', 'zh-tw', false ], |
| 929 |
|
| 930 |
[ 'es', 'Help:I_need_somebody', 'es', 'zh-tw', 'zh-cn' ], |
| 931 |
[ 'es', 'MediaWiki:About', 'es', 'zh-tw', 'zh-cn' ], |
| 932 |
[ 'es', 'MediaWiki:About/', 'es', 'zh-tw', 'zh-cn' ], |
| 933 |
[ 'de', 'MediaWiki:About/de', 'es', 'zh-tw', 'zh-cn' ], |
| 934 |
[ 'en', 'MediaWiki:Common.js', 'es', 'zh-tw', 'zh-cn' ], |
| 935 |
[ 'en', 'MediaWiki:Common.css', 'es', 'zh-tw', 'zh-cn' ], |
| 936 |
[ 'en', 'User:JohnDoe/Common.js', 'es', 'zh-tw', 'zh-cn' ], |
| 937 |
[ 'en', 'User:JohnDoe/Monobook.css', 'es', 'zh-tw', 'zh-cn' ], |
| 938 |
|
| 939 |
[ 'zh-cn', 'Help:I_need_somebody', 'zh', 'zh-tw', 'zh-cn' ], |
| 940 |
[ 'zh', 'MediaWiki:About', 'zh', 'zh-tw', 'zh-cn' ], |
| 941 |
[ 'zh', 'MediaWiki:About/', 'zh', 'zh-tw', 'zh-cn' ], |
| 942 |
[ 'de', 'MediaWiki:About/de', 'zh', 'zh-tw', 'zh-cn' ], |
| 943 |
[ 'zh-cn', 'MediaWiki:About/zh-cn', 'zh', 'zh-tw', 'zh-cn' ], |
| 944 |
[ 'zh-tw', 'MediaWiki:About/zh-tw', 'zh', 'zh-tw', 'zh-cn' ], |
| 945 |
[ 'en', 'MediaWiki:Common.js', 'zh', 'zh-tw', 'zh-cn' ], |
| 946 |
[ 'en', 'MediaWiki:Common.css', 'zh', 'zh-tw', 'zh-cn' ], |
| 947 |
[ 'en', 'User:JohnDoe/Common.js', 'zh', 'zh-tw', 'zh-cn' ], |
| 948 |
[ 'en', 'User:JohnDoe/Monobook.css', 'zh', 'zh-tw', 'zh-cn' ], |
| 949 |
|
| 950 |
[ 'zh-tw', 'Special:NewPages', 'es', 'zh-tw', 'zh-cn' ], |
| 951 |
[ 'zh-tw', 'Special:NewPages', 'zh', 'zh-tw', 'zh-cn' ], |
| 952 |
|
| 953 |
]; |
| 954 |
} |
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
public function testGetPageViewLanguage( $expected, $titleText, $contLang, |
| 963 |
$lang, $variant, $msg = '' |
| 964 |
) { |
| 965 |
|
| 966 |
$this->overrideConfigValues( [ |
| 967 |
MainConfigNames::DefaultLanguageVariant => $variant, |
| 968 |
MainConfigNames::AllowUserJs => true, |
| 969 |
] ); |
| 970 |
$this->setUserLang( $lang ); |
| 971 |
$this->overrideConfigValue( MainConfigNames::LanguageCode, $contLang ); |
| 972 |
|
| 973 |
$title = Title::newFromText( $titleText ); |
| 974 |
$this->assertInstanceOf( Title::class, $title, |
| 975 |
"Test must be passed a valid title text, you gave '$titleText'" |
| 976 |
); |
| 977 |
$this->hideDeprecated( Title::class . '::getPageViewLanguage' ); |
| 978 |
$this->assertEquals( $expected, |
| 979 |
$title->getPageViewLanguage()->getCode(), |
| 980 |
$msg |
| 981 |
); |
| 982 |
} |
| 983 |
|
| 984 |
public static function provideSubpage() { |
| 985 |
|
| 986 |
return [ |
| 987 |
[ 'Foo', 'x', new TitleValue( NS_MAIN, 'Foo/x' ) ], |
| 988 |
[ 'Foo#bar', 'x', new TitleValue( NS_MAIN, 'Foo/x' ) ], |
| 989 |
[ 'User:Foo', 'x', new TitleValue( NS_USER, 'Foo/x' ) ], |
| 990 |
[ 'wiki:User:Foo', 'x', new TitleValue( NS_MAIN, 'User:Foo/x', '', 'wiki' ) ], |
| 991 |
]; |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
public function testSubpage( $title, $sub, LinkTarget $expected ) { |
| 999 |
$title = Title::newFromText( $title ); |
| 1000 |
$expected = Title::newFromLinkTarget( $expected ); |
| 1001 |
$actual = $title->getSubpage( $sub ); |
| 1002 |
|
| 1003 |
|
| 1004 |
$this->assertSame( $expected->getPrefixedText(), $actual->getPrefixedText(), 'text form' ); |
| 1005 |
$this->assertTrue( $expected->equals( $actual ), 'Title equality' ); |
| 1006 |
} |
| 1007 |
|
| 1008 |
public static function provideIsAlwaysKnown() { |
| 1009 |
return [ |
| 1010 |
[ 'Some nonexistent page' . wfRandomString(), false ], |
| 1011 |
[ 'Some existent page', false, true ], |
| 1012 |
[ '#test', true ], |
| 1013 |
[ 'Special:BlankPage', true ], |
| 1014 |
[ 'Special:SomeNonexistentSpecialPage', false ], |
| 1015 |
[ 'MediaWiki:Parentheses', true ], |
| 1016 |
[ 'MediaWiki:Some nonexistent message', false ], |
| 1017 |
]; |
| 1018 |
} |
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
public function testIsAlwaysKnown( $page, $isKnown, bool $createIfNotExists = false ) { |
| 1028 |
if ( $createIfNotExists ) { |
| 1029 |
$this->getExistingTestPage( $page ); |
| 1030 |
} |
| 1031 |
$title = Title::newFromText( $page ); |
| 1032 |
$this->assertEquals( $isKnown, $title->isAlwaysKnown() ); |
| 1033 |
} |
| 1034 |
|
| 1035 |
public static function provideIsValid() { |
| 1036 |
return [ |
| 1037 |
[ Title::makeTitle( NS_MAIN, '' ), false ], |
| 1038 |
[ Title::makeTitle( NS_MAIN, '<>' ), false ], |
| 1039 |
[ Title::makeTitle( NS_MAIN, '|' ), false ], |
| 1040 |
[ Title::makeTitle( NS_MAIN, '#' ), false ], |
| 1041 |
[ Title::makeTitle( NS_PROJECT, '#' ), false ], |
| 1042 |
[ Title::makeTitle( NS_MAIN, '', 'test' ), true ], |
| 1043 |
[ Title::makeTitle( NS_PROJECT, '#test' ), false ], |
| 1044 |
[ Title::makeTitle( NS_MAIN, '', 'test', 'wikipedia' ), true ], |
| 1045 |
[ Title::makeTitle( NS_MAIN, 'Test', '', 'wikipedia' ), true ], |
| 1046 |
[ Title::makeTitle( NS_MAIN, 'Test' ), true ], |
| 1047 |
[ Title::makeTitle( NS_SPECIAL, 'Test' ), true ], |
| 1048 |
[ Title::makeTitle( NS_MAIN, ' Test' ), false ], |
| 1049 |
[ Title::makeTitle( NS_MAIN, '_Test' ), false ], |
| 1050 |
[ Title::makeTitle( NS_MAIN, 'Test ' ), false ], |
| 1051 |
[ Title::makeTitle( NS_MAIN, 'Test_' ), false ], |
| 1052 |
[ Title::makeTitle( NS_MAIN, "Test\nthis" ), false ], |
| 1053 |
[ Title::makeTitle( NS_MAIN, "Test\tthis" ), false ], |
| 1054 |
[ Title::makeTitle( -33, 'Test' ), false ], |
| 1055 |
[ Title::makeTitle( 77663399, 'Test' ), false ], |
| 1056 |
]; |
| 1057 |
} |
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
public function testIsValid( Title $title, $isValid ) { |
| 1066 |
$this->assertEquals( $isValid, $title->isValid(), $title->getFullText() ); |
| 1067 |
} |
| 1068 |
|
| 1069 |
public static function provideIsValidRedirectTarget() { |
| 1070 |
return [ |
| 1071 |
[ Title::makeTitle( NS_MAIN, '' ), false ], |
| 1072 |
[ Title::makeTitle( NS_MAIN, '', 'test' ), false ], |
| 1073 |
[ Title::makeTitle( NS_MAIN, 'Foo', 'test' ), true ], |
| 1074 |
[ Title::makeTitle( NS_MAIN, '<>' ), false ], |
| 1075 |
[ Title::makeTitle( NS_MAIN, '_' ), false ], |
| 1076 |
[ Title::makeTitle( NS_MAIN, 'Test', '', 'acme' ), true ], |
| 1077 |
[ Title::makeTitle( NS_SPECIAL, 'UserLogout' ), false ], |
| 1078 |
[ Title::makeTitle( NS_SPECIAL, 'RecentChanges' ), true ], |
| 1079 |
]; |
| 1080 |
} |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
public function testIsValidRedirectTarget( Title $title, $isValid ) { |
| 1089 |
|
| 1090 |
$this->assertEquals( $isValid, $title->isValidRedirectTarget(), $title->getFullText() ); |
| 1091 |
} |
| 1092 |
|
| 1093 |
public static function provideCanExist() { |
| 1094 |
return [ |
| 1095 |
[ Title::makeTitle( NS_MAIN, '' ), false ], |
| 1096 |
[ Title::makeTitle( NS_MAIN, '<>' ), false ], |
| 1097 |
[ Title::makeTitle( NS_MAIN, '|' ), false ], |
| 1098 |
[ Title::makeTitle( NS_MAIN, '#' ), false ], |
| 1099 |
[ Title::makeTitle( NS_PROJECT, '#test' ), false ], |
| 1100 |
[ Title::makeTitle( NS_MAIN, '', 'test', 'acme' ), false ], |
| 1101 |
[ Title::makeTitle( NS_MAIN, 'Test' ), true ], |
| 1102 |
[ Title::makeTitle( NS_MAIN, ' Test' ), false ], |
| 1103 |
[ Title::makeTitle( NS_MAIN, '_Test' ), false ], |
| 1104 |
[ Title::makeTitle( NS_MAIN, 'Test ' ), false ], |
| 1105 |
[ Title::makeTitle( NS_MAIN, 'Test_' ), false ], |
| 1106 |
[ Title::makeTitle( NS_MAIN, "Test\nthis" ), false ], |
| 1107 |
[ Title::makeTitle( NS_MAIN, "Test\tthis" ), false ], |
| 1108 |
[ Title::makeTitle( -33, 'Test' ), false ], |
| 1109 |
[ Title::makeTitle( 77663399, 'Test' ), false ], |
| 1110 |
|
| 1111 |
|
| 1112 |
[ Title::makeTitle( NS_MAIN, '', 'test' ), false ], |
| 1113 |
[ Title::makeTitle( NS_SPECIAL, 'Test' ), false ], |
| 1114 |
[ Title::makeTitle( NS_MAIN, 'Test', '', 'acme' ), false ], |
| 1115 |
]; |
| 1116 |
} |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
public function testCanExist( Title $title, $canExist ) { |
| 1125 |
$this->assertEquals( $canExist, $title->canExist(), $title->getFullText() ); |
| 1126 |
} |
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
public function testIsAlwaysKnownOnInterwiki() { |
| 1132 |
$title = Title::makeTitle( NS_MAIN, 'Interwiki link', '', 'externalwiki' ); |
| 1133 |
$this->assertTrue( $title->isAlwaysKnown() ); |
| 1134 |
} |
| 1135 |
|
| 1136 |
public static function provideGetSkinFromConfigSubpage() { |
| 1137 |
return [ |
| 1138 |
[ 'User:Foo', '' ], |
| 1139 |
[ 'User:Foo.css', '' ], |
| 1140 |
[ 'User:Foo/', '' ], |
| 1141 |
[ 'User:Foo/bar', '' ], |
| 1142 |
[ 'User:Foo./bar', '' ], |
| 1143 |
[ 'User:Foo/bar.', 'bar' ], |
| 1144 |
[ 'User:Foo/bar.css', 'bar' ], |
| 1145 |
[ '/bar.css', '' ], |
| 1146 |
[ '//bar.css', 'bar' ], |
| 1147 |
[ '.css', '' ], |
| 1148 |
]; |
| 1149 |
} |
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
public function testGetSkinFromConfigSubpage( $title, $expected ) { |
| 1156 |
$title = Title::newFromText( $title ); |
| 1157 |
$this->assertSame( $expected, $title->getSkinFromConfigSubpage() ); |
| 1158 |
} |
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
public function testGetWikiId() { |
| 1164 |
$title = Title::newFromText( 'Foo' ); |
| 1165 |
$this->assertFalse( $title->getWikiId() ); |
| 1166 |
} |
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
public function testSetFragment() { |
| 1174 |
|
| 1175 |
$title = Title::newFromText( 'Foo' ); |
| 1176 |
|
| 1177 |
$title->setFragment( '#Xyzzy' ); |
| 1178 |
$this->assertSame( 'Xyzzy', $title->getFragment() ); |
| 1179 |
|
| 1180 |
|
| 1181 |
$title = Title::newFromText( 'Foo' ); |
| 1182 |
$this->assertNotSame( 'Xyzzy', $title->getFragment() ); |
| 1183 |
} |
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
public function testClone() { |
| 1189 |
|
| 1190 |
$title = Title::newFromText( 'Foo' ); |
| 1191 |
|
| 1192 |
$clone = clone $title; |
| 1193 |
$clone->setFragment( '#Xyzzy' ); |
| 1194 |
|
| 1195 |
|
| 1196 |
$title2 = Title::newFromText( 'Foo' ); |
| 1197 |
$this->assertSame( $title, $title2 ); |
| 1198 |
} |
| 1199 |
|
| 1200 |
public static function provideBaseTitleCases() { |
| 1201 |
return [ |
| 1202 |
|
| 1203 |
[ NS_USER, 'John_Doe', 'John Doe' ], |
| 1204 |
[ NS_USER, 'John_Doe/subOne/subTwo', 'John Doe/subOne' ], |
| 1205 |
[ NS_USER, 'Foo / Bar / Baz', 'Foo / Bar ' ], |
| 1206 |
[ NS_USER, 'Foo/', 'Foo' ], |
| 1207 |
[ NS_USER, 'Foo/Bar/', 'Foo/Bar' ], |
| 1208 |
[ NS_USER, '/', '/' ], |
| 1209 |
[ NS_USER, '//', '/' ], |
| 1210 |
[ NS_USER, '/oops/', '/oops' ], |
| 1211 |
[ NS_USER, '/indeed', '/indeed' ], |
| 1212 |
[ NS_USER, '//indeed', '/' ], |
| 1213 |
[ NS_USER, '/Ramba/Zamba/Mamba/', '/Ramba/Zamba/Mamba' ], |
| 1214 |
[ NS_USER, '//x//y//z//', '//x//y//z/' ], |
| 1215 |
]; |
| 1216 |
} |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
public function testGetBaseText( $namespace, $title, $expected ) { |
| 1223 |
$title = Title::makeTitle( $namespace, $title ); |
| 1224 |
$this->assertSame( $expected, $title->getBaseText() ); |
| 1225 |
} |
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
public function testGetBaseTitle( $namespace, $title, $expected ) { |
| 1232 |
$title = Title::makeTitle( $namespace, $title ); |
| 1233 |
$base = $title->getBaseTitle(); |
| 1234 |
$this->assertTrue( $base->isValid() ); |
| 1235 |
$this->assertTrue( |
| 1236 |
$base->equals( Title::makeTitleSafe( $title->getNamespace(), $expected ) ) |
| 1237 |
); |
| 1238 |
} |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
public function testGetBaseTitle_invalid() { |
| 1245 |
$title = Title::makeTitle( -23, 'Test' ); |
| 1246 |
$base = $title->getBaseTitle(); |
| 1247 |
$this->assertSame( $title, $base ); |
| 1248 |
} |
| 1249 |
|
| 1250 |
public static function provideRootTitleCases() { |
| 1251 |
return [ |
| 1252 |
|
| 1253 |
[ NS_USER, 'John_Doe', 'John Doe' ], |
| 1254 |
[ NS_USER, 'John_Doe/subOne/subTwo', 'John Doe' ], |
| 1255 |
[ NS_USER, 'Foo / Bar / Baz', 'Foo ' ], |
| 1256 |
[ NS_USER, 'Foo/', 'Foo' ], |
| 1257 |
[ NS_USER, 'Foo/Bar/', 'Foo' ], |
| 1258 |
[ NS_USER, '/', '/' ], |
| 1259 |
[ NS_USER, '//', '/' ], |
| 1260 |
[ NS_USER, '/oops/', '/oops' ], |
| 1261 |
[ NS_USER, '/Ramba/Zamba/Mamba/', '/Ramba' ], |
| 1262 |
[ NS_USER, '//x//y//z//', '//x' ], |
| 1263 |
[ NS_TALK, '////', '///' ], |
| 1264 |
[ NS_TEMPLATE, '////', '///' ], |
| 1265 |
[ NS_TEMPLATE, 'Foo////', 'Foo' ], |
| 1266 |
[ NS_TEMPLATE, 'Foo////Bar', 'Foo' ], |
| 1267 |
]; |
| 1268 |
} |
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
public function testGetRootText( $namespace, $title, $expected ) { |
| 1275 |
$title = Title::makeTitle( $namespace, $title ); |
| 1276 |
$this->assertEquals( $expected, $title->getRootText() ); |
| 1277 |
} |
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
public function testGetRootTitle( $namespace, $title, $expected ) { |
| 1284 |
$title = Title::makeTitle( $namespace, $title ); |
| 1285 |
$root = $title->getRootTitle(); |
| 1286 |
$this->assertTrue( $root->isValid() ); |
| 1287 |
$this->assertTrue( |
| 1288 |
$root->equals( Title::makeTitleSafe( $title->getNamespace(), $expected ) ) |
| 1289 |
); |
| 1290 |
} |
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
public function testGetRootTitle_invalid() { |
| 1297 |
$title = Title::makeTitle( -23, 'Test' ); |
| 1298 |
$base = $title->getRootTitle(); |
| 1299 |
$this->assertSame( $title, $base ); |
| 1300 |
} |
| 1301 |
|
| 1302 |
public static function provideSubpageTitleCases() { |
| 1303 |
return [ |
| 1304 |
|
| 1305 |
[ NS_USER, 'John_Doe', 'John Doe' ], |
| 1306 |
[ NS_USER, 'John_Doe/subOne/subTwo', 'subTwo' ], |
| 1307 |
[ NS_USER, 'John_Doe/subOne', 'subOne' ], |
| 1308 |
[ NS_USER, '/', '/' ], |
| 1309 |
[ NS_USER, '//', '' ], |
| 1310 |
[ NS_USER, '/oops/', '' ], |
| 1311 |
[ NS_USER, '/indeed', '/indeed' ], |
| 1312 |
[ NS_USER, '//indeed', 'indeed' ], |
| 1313 |
[ NS_USER, '/Ramba/Zamba/Mamba/', '' ], |
| 1314 |
[ NS_USER, '//x//y//z//', '' ], |
| 1315 |
[ NS_TEMPLATE, 'Foo', 'Foo' ], |
| 1316 |
[ NS_CATEGORY, 'Foo', 'Foo' ], |
| 1317 |
[ NS_MAIN, 'Bar', 'Bar' ], |
| 1318 |
]; |
| 1319 |
} |
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
public function testGetSubpageText( $namespace, $title, $expected ) { |
| 1326 |
$title = Title::makeTitle( $namespace, $title ); |
| 1327 |
$this->assertEquals( $expected, $title->getSubpageText() ); |
| 1328 |
} |
| 1329 |
|
| 1330 |
public static function provideGetTitleValue() { |
| 1331 |
return [ |
| 1332 |
[ 'Foo' ], |
| 1333 |
[ 'Foo#bar' ], |
| 1334 |
[ 'User:Hansi_Maier' ], |
| 1335 |
]; |
| 1336 |
} |
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
public function testGetTitleValue( $text ) { |
| 1343 |
$title = Title::newFromText( $text ); |
| 1344 |
$value = $title->getTitleValue(); |
| 1345 |
|
| 1346 |
$dbkey = str_replace( ' ', '_', $value->getText() ); |
| 1347 |
$this->assertEquals( $title->getDBkey(), $dbkey ); |
| 1348 |
$this->assertEquals( $title->getNamespace(), $value->getNamespace() ); |
| 1349 |
$this->assertEquals( $title->getFragment(), $value->getFragment() ); |
| 1350 |
} |
| 1351 |
|
| 1352 |
public static function provideGetFragment() { |
| 1353 |
return [ |
| 1354 |
[ 'Foo', '' ], |
| 1355 |
[ 'Foo#bar', 'bar' ], |
| 1356 |
[ 'Foo#bär', 'bär' ], |
| 1357 |
|
| 1358 |
|
| 1359 |
[ 'Foo#bar_bar', 'bar bar' ], |
| 1360 |
[ 'Foo#bar bar', 'bar bar' ], |
| 1361 |
[ 'Foo#bar bar', 'bar bar' ], |
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
[ 'Foo#_bar_bar_', ' bar bar' ], |
| 1366 |
[ 'Foo# bar bar ', ' bar bar' ], |
| 1367 |
]; |
| 1368 |
} |
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
public function testGetFragment( $full, $fragment ) { |
| 1378 |
$title = Title::newFromText( $full ); |
| 1379 |
$this->assertEquals( $fragment, $title->getFragment() ); |
| 1380 |
} |
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
public function testExists() { |
| 1386 |
$title = Title::makeTitle( NS_PROJECT, 'New page' ); |
| 1387 |
$linkCache = $this->getServiceContainer()->getLinkCache(); |
| 1388 |
|
| 1389 |
$article = new Article( $title ); |
| 1390 |
$page = $article->getPage(); |
| 1391 |
$page->doUserEditContent( |
| 1392 |
new WikitextContent( 'Some [[link]]' ), |
| 1393 |
$this->getTestSysop()->getUser(), |
| 1394 |
'summary' |
| 1395 |
); |
| 1396 |
|
| 1397 |
|
| 1398 |
$title->mArticleID = -1; |
| 1399 |
|
| 1400 |
|
| 1401 |
$linkCache->clearLink( $title ); |
| 1402 |
$linkCache->addBadLinkObj( $title ); |
| 1403 |
|
| 1404 |
$this->assertFalse( |
| 1405 |
$title->exists(), |
| 1406 |
'exists() should rely on link cache unless READ_LATEST is used' |
| 1407 |
); |
| 1408 |
$this->assertTrue( |
| 1409 |
$title->exists( IDBAccessObject::READ_LATEST ), |
| 1410 |
'exists() should re-query database when READ_LATEST is used' |
| 1411 |
); |
| 1412 |
} |
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
public function testGetArticleID() { |
| 1419 |
$title = Title::makeTitle( NS_PROJECT, __METHOD__ ); |
| 1420 |
$this->assertSame( 0, $title->getArticleID() ); |
| 1421 |
$this->assertSame( $title->getArticleID(), $title->getId() ); |
| 1422 |
|
| 1423 |
$article = new Article( $title ); |
| 1424 |
$page = $article->getPage(); |
| 1425 |
$page->doUserEditContent( |
| 1426 |
new WikitextContent( 'Some [[link]]' ), |
| 1427 |
$this->getTestSysop()->getUser(), |
| 1428 |
'summary' |
| 1429 |
); |
| 1430 |
|
| 1431 |
$this->assertGreaterThan( 0, $title->getArticleID() ); |
| 1432 |
$this->assertSame( $title->getArticleID(), $title->getId() ); |
| 1433 |
} |
| 1434 |
|
| 1435 |
public static function provideNonProperTitles() { |
| 1436 |
return [ |
| 1437 |
'section link' => [ Title::makeTitle( NS_MAIN, '', 'Section' ) ], |
| 1438 |
'empty' => [ Title::makeTitle( NS_MAIN, '' ) ], |
| 1439 |
'bad chars' => [ Title::makeTitle( NS_MAIN, '_|_' ) ], |
| 1440 |
'empty in namspace' => [ Title::makeTitle( NS_USER, '' ) ], |
| 1441 |
'special' => [ Title::makeTitle( NS_SPECIAL, 'RecentChanges' ) ], |
| 1442 |
'interwiki' => [ Title::makeTitle( NS_MAIN, 'Test', '', 'acme' ) ], |
| 1443 |
]; |
| 1444 |
} |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
public function testGetArticleIDFromNonProperTitle( $title ) { |
| 1451 |
|
| 1452 |
$this->assertSame( 0, $title->getArticleID() ); |
| 1453 |
} |
| 1454 |
|
| 1455 |
public static function provideCanHaveTalkPage() { |
| 1456 |
return [ |
| 1457 |
'User page has talk page' => [ |
| 1458 |
Title::makeTitle( NS_USER, 'Jane' ), true |
| 1459 |
], |
| 1460 |
'Talke page has talk page' => [ |
| 1461 |
Title::makeTitle( NS_TALK, 'Foo' ), true |
| 1462 |
], |
| 1463 |
'Special page cannot have talk page' => [ |
| 1464 |
Title::makeTitle( NS_SPECIAL, 'Thing' ), false |
| 1465 |
], |
| 1466 |
'Virtual namespace cannot have talk page' => [ |
| 1467 |
Title::makeTitle( NS_MEDIA, 'Kitten.jpg' ), false |
| 1468 |
], |
| 1469 |
'Relative link has no talk page' => [ |
| 1470 |
Title::makeTitle( NS_MAIN, '', 'Kittens' ), false |
| 1471 |
], |
| 1472 |
'Interwiki link has no talk page' => [ |
| 1473 |
Title::makeTitle( NS_MAIN, 'Kittens', '', 'acme' ), false |
| 1474 |
], |
| 1475 |
]; |
| 1476 |
} |
| 1477 |
|
| 1478 |
public static function provideGetTalkPage_good() { |
| 1479 |
return [ |
| 1480 |
[ Title::makeTitle( NS_MAIN, 'Test' ), Title::makeTitle( NS_TALK, 'Test' ) ], |
| 1481 |
[ Title::makeTitle( NS_TALK, 'Test' ), Title::makeTitle( NS_TALK, 'Test' ) ], |
| 1482 |
]; |
| 1483 |
} |
| 1484 |
|
| 1485 |
public static function provideGetTalkPage_bad() { |
| 1486 |
return [ |
| 1487 |
[ Title::makeTitle( NS_SPECIAL, 'Test' ) ], |
| 1488 |
[ Title::makeTitle( NS_MEDIA, 'Test' ) ], |
| 1489 |
]; |
| 1490 |
} |
| 1491 |
|
| 1492 |
public static function provideGetTalkPage_broken() { |
| 1493 |
|
| 1494 |
|
| 1495 |
return [ |
| 1496 |
[ |
| 1497 |
Title::makeTitle( NS_MAIN, '', 'Kittens' ), |
| 1498 |
Title::makeTitle( NS_TALK, '' ), |
| 1499 |
false, |
| 1500 |
], |
| 1501 |
[ |
| 1502 |
Title::makeTitle( NS_MAIN, 'Kittens', '', 'acme' ), |
| 1503 |
Title::makeTitle( NS_TALK, 'Kittens', '' ), |
| 1504 |
true, |
| 1505 |
], |
| 1506 |
]; |
| 1507 |
} |
| 1508 |
|
| 1509 |
public static function provideGetSubjectPage_good() { |
| 1510 |
return [ |
| 1511 |
[ Title::makeTitle( NS_TALK, 'Test' ), Title::makeTitle( NS_MAIN, 'Test' ) ], |
| 1512 |
[ Title::makeTitle( NS_MAIN, 'Test' ), Title::makeTitle( NS_MAIN, 'Test' ) ], |
| 1513 |
]; |
| 1514 |
} |
| 1515 |
|
| 1516 |
public static function provideGetOtherPage_good() { |
| 1517 |
return [ |
| 1518 |
[ Title::makeTitle( NS_MAIN, 'Test' ), Title::makeTitle( NS_TALK, 'Test' ) ], |
| 1519 |
[ Title::makeTitle( NS_TALK, 'Test' ), Title::makeTitle( NS_MAIN, 'Test' ) ], |
| 1520 |
]; |
| 1521 |
} |
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
public function testCanHaveTalkPage( Title $title, $expected ) { |
| 1531 |
$actual = $title->canHaveTalkPage(); |
| 1532 |
$this->assertSame( $expected, $actual, $title->getPrefixedDBkey() ); |
| 1533 |
} |
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
public function testGetTalkPage_good( Title $title, Title $expected ) { |
| 1540 |
$actual = $title->getTalkPage(); |
| 1541 |
$this->assertTrue( $expected->equals( $actual ), $title->getPrefixedDBkey() ); |
| 1542 |
} |
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
public function testGetTalkPage_bad( Title $title ) { |
| 1549 |
$this->expectException( MWException::class ); |
| 1550 |
$title->getTalkPage(); |
| 1551 |
} |
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
public function testGetTalkPage_broken( Title $title, Title $expected, $valid ) { |
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
$result = @$title->getTalkPage(); |
| 1562 |
$this->assertTrue( $expected->equals( $result ) ); |
| 1563 |
$this->assertSame( $valid, $result->isValid() ); |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
public function testGetTalkPageIfDefined_good( Title $title, Title $expected ) { |
| 1571 |
$actual = $title->getTalkPageIfDefined(); |
| 1572 |
$this->assertNotNull( $actual, $title->getPrefixedDBkey() ); |
| 1573 |
$this->assertTrue( $expected->equals( $actual ), $title->getPrefixedDBkey() ); |
| 1574 |
} |
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
public function testGetTalkPageIfDefined_bad( Title $title ) { |
| 1581 |
$talk = $title->getTalkPageIfDefined(); |
| 1582 |
$this->assertNull( |
| 1583 |
$talk, |
| 1584 |
$title->getPrefixedDBkey() |
| 1585 |
); |
| 1586 |
} |
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
public function testGetSubjectPage_good( Title $title, Title $expected ) { |
| 1593 |
$actual = $title->getSubjectPage(); |
| 1594 |
$this->assertTrue( $expected->equals( $actual ), $title->getPrefixedDBkey() ); |
| 1595 |
} |
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
public function testGetOtherPage_good( Title $title, Title $expected ) { |
| 1602 |
$actual = $title->getOtherPage(); |
| 1603 |
$this->assertTrue( $expected->equals( $actual ), $title->getPrefixedDBkey() ); |
| 1604 |
} |
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
public function testGetOtherPage_bad( Title $title ) { |
| 1611 |
$this->expectException( MWException::class ); |
| 1612 |
$title->getOtherPage(); |
| 1613 |
} |
| 1614 |
|
| 1615 |
public static function provideIsMovable() { |
| 1616 |
return [ |
| 1617 |
'Simple title' => [ 'Foo', true ], |
| 1618 |
|
| 1619 |
'Empty name' => [ Title::makeTitle( NS_MAIN, '' ), true ], |
| 1620 |
'Invalid name' => [ Title::makeTitle( NS_MAIN, '<' ), true ], |
| 1621 |
'Interwiki' => [ Title::makeTitle( NS_MAIN, 'Test', '', 'otherwiki' ), false ], |
| 1622 |
'Special page' => [ 'Special:FooBar', false ], |
| 1623 |
'Aborted by hook' => [ 'Hooked in place', false, |
| 1624 |
static function ( Title $title, &$result ) { |
| 1625 |
$result = false; |
| 1626 |
} |
| 1627 |
], |
| 1628 |
]; |
| 1629 |
} |
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
public function testIsMovable( $title, $expected, $hookCallback = null ) { |
| 1640 |
if ( $hookCallback ) { |
| 1641 |
$this->setTemporaryHook( 'TitleIsMovable', $hookCallback ); |
| 1642 |
} |
| 1643 |
if ( is_string( $title ) ) { |
| 1644 |
$title = Title::newFromText( $title ); |
| 1645 |
} |
| 1646 |
|
| 1647 |
$this->assertSame( $expected, $title->isMovable() ); |
| 1648 |
} |
| 1649 |
|
| 1650 |
public static function provideGetPrefixedText() { |
| 1651 |
return [ |
| 1652 |
|
| 1653 |
[ |
| 1654 |
Title::makeTitle( NS_MAIN, 'Foo bar' ), |
| 1655 |
'Foo bar' |
| 1656 |
], |
| 1657 |
|
| 1658 |
[ |
| 1659 |
Title::makeTitle( NS_USER, 'Foo bar' ), |
| 1660 |
'User:Foo bar' |
| 1661 |
], |
| 1662 |
|
| 1663 |
[ |
| 1664 |
Title::makeTitle( NS_USER_TALK, 'Foo bar' ), |
| 1665 |
'User talk:Foo bar' |
| 1666 |
], |
| 1667 |
|
| 1668 |
[ |
| 1669 |
Title::makeTitle( NS_MAIN, 'Foo bar', 'fragment' ), |
| 1670 |
'Foo bar' |
| 1671 |
], |
| 1672 |
|
| 1673 |
[ |
| 1674 |
Title::makeTitle( NS_MEDIA, 'Foo bar' ), |
| 1675 |
'Media:Foo bar' |
| 1676 |
], |
| 1677 |
|
| 1678 |
[ |
| 1679 |
Title::makeTitle( 100777, 'Foo bar' ), |
| 1680 |
'Special:Badtitle/NS100777:Foo bar' |
| 1681 |
], |
| 1682 |
]; |
| 1683 |
} |
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
public function testGetPrefixedText( Title $title, $expected ) { |
| 1690 |
$this->assertEquals( $expected, $title->getPrefixedText() ); |
| 1691 |
} |
| 1692 |
|
| 1693 |
public static function provideGetPrefixedDBKey() { |
| 1694 |
return [ |
| 1695 |
|
| 1696 |
[ |
| 1697 |
Title::makeTitle( NS_MAIN, 'Foo_bar' ), |
| 1698 |
'Foo_bar' |
| 1699 |
], |
| 1700 |
|
| 1701 |
[ |
| 1702 |
Title::makeTitle( NS_USER, 'Foo_bar' ), |
| 1703 |
'User:Foo_bar' |
| 1704 |
], |
| 1705 |
|
| 1706 |
[ |
| 1707 |
Title::makeTitle( NS_USER_TALK, 'Foo_bar' ), |
| 1708 |
'User_talk:Foo_bar' |
| 1709 |
], |
| 1710 |
|
| 1711 |
[ |
| 1712 |
Title::makeTitle( NS_MAIN, 'Foo_bar', 'fragment' ), |
| 1713 |
'Foo_bar' |
| 1714 |
], |
| 1715 |
|
| 1716 |
[ |
| 1717 |
Title::makeTitle( NS_MEDIA, 'Foo_bar' ), |
| 1718 |
'Media:Foo_bar' |
| 1719 |
], |
| 1720 |
|
| 1721 |
[ |
| 1722 |
Title::makeTitle( 100777, 'Foo_bar' ), |
| 1723 |
'Special:Badtitle/NS100777:Foo_bar' |
| 1724 |
], |
| 1725 |
]; |
| 1726 |
} |
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
public function testGetPrefixedDBKey( Title $title, $expected ) { |
| 1733 |
$this->assertEquals( $expected, $title->getPrefixedDBkey() ); |
| 1734 |
} |
| 1735 |
|
| 1736 |
public static function provideGetFragmentForURL() { |
| 1737 |
return [ |
| 1738 |
[ 'Foo', '' ], |
| 1739 |
[ 'Foo#ümlåût', '#ümlåût' ], |
| 1740 |
[ 'de:Foo#Bå®', '#Bå®' ], |
| 1741 |
[ 'zz:Foo#тест', '#.D1.82.D0.B5.D1.81.D1.82' ], |
| 1742 |
]; |
| 1743 |
} |
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
public function testGetFragmentForURL( $titleStr, $expected ) { |
| 1753 |
$this->overrideConfigValues( [ |
| 1754 |
MainConfigNames::FragmentMode => [ 'html5' ], |
| 1755 |
MainConfigNames::ExternalInterwikiFragmentMode => 'legacy', |
| 1756 |
] ); |
| 1757 |
|
| 1758 |
|
| 1759 |
$title = Title::newFromText( $titleStr ); |
| 1760 |
self::assertEquals( $expected, $title->getFragmentForURL() ); |
| 1761 |
} |
| 1762 |
|
| 1763 |
public static function provideIsRawHtmlMessage() { |
| 1764 |
return [ |
| 1765 |
[ 'MediaWiki:Foobar', true ], |
| 1766 |
[ 'MediaWiki:Foo bar', true ], |
| 1767 |
[ 'MediaWiki:Foo-bar', true ], |
| 1768 |
[ 'MediaWiki:foo bar', true ], |
| 1769 |
[ 'MediaWiki:foo-bar', true ], |
| 1770 |
[ 'MediaWiki:foobar', true ], |
| 1771 |
[ 'MediaWiki:some-other-message', false ], |
| 1772 |
[ 'Main Page', false ], |
| 1773 |
]; |
| 1774 |
} |
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
public function testIsRawHtmlMessage( $textForm, $expected ) { |
| 1781 |
$this->overrideConfigValue( |
| 1782 |
MainConfigNames::RawHtmlMessages, |
| 1783 |
[ |
| 1784 |
'foobar', |
| 1785 |
'foo_bar', |
| 1786 |
'foo-bar', |
| 1787 |
] |
| 1788 |
); |
| 1789 |
|
| 1790 |
$title = Title::newFromText( $textForm ); |
| 1791 |
$this->assertSame( $expected, $title->isRawHtmlMessage() ); |
| 1792 |
} |
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
public function testNewMainPage() { |
| 1798 |
$mock = $this->createMock( MessageCache::class ); |
| 1799 |
$mock->method( 'get' )->willReturn( 'Foresheet' ); |
| 1800 |
$mock->method( 'transform' )->willReturn( 'Foresheet' ); |
| 1801 |
|
| 1802 |
$this->setService( 'MessageCache', $mock ); |
| 1803 |
|
| 1804 |
$this->assertSame( |
| 1805 |
'Foresheet', |
| 1806 |
Title::newMainPage()->getText() |
| 1807 |
); |
| 1808 |
} |
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
public function testNewMainPageNoRecursion() { |
| 1816 |
$mock = $this->createMock( MessageCache::class ); |
| 1817 |
$mock->method( 'get' )->willReturn( 'localtestiw:' ); |
| 1818 |
$mock->method( 'transform' )->willReturn( 'localtestiw:' ); |
| 1819 |
$this->setService( 'MessageCache', $mock ); |
| 1820 |
|
| 1821 |
$this->assertSame( |
| 1822 |
'Main Page', |
| 1823 |
Title::newMainPage()->getPrefixedText() |
| 1824 |
); |
| 1825 |
} |
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
public function testNewMainPageWithLocal() { |
| 1831 |
$local = $this->createMock( MessageLocalizer::class ); |
| 1832 |
$local->method( 'msg' )->willReturn( new RawMessage( 'Prime Article' ) ); |
| 1833 |
|
| 1834 |
$this->assertSame( |
| 1835 |
'Prime Article', |
| 1836 |
Title::newMainPage( $local )->getText() |
| 1837 |
); |
| 1838 |
} |
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
public function testGetTitleProtection() { |
| 1844 |
$title = $this->getNonexistingTestPage( 'UTest1' )->getTitle(); |
| 1845 |
$this->hideDeprecated( Title::class . '::getTitleProtection' ); |
| 1846 |
$this->assertFalse( $title->getTitleProtection() ); |
| 1847 |
} |
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
public function testDeleteTitleProtection() { |
| 1853 |
$title = $this->getExistingTestPage( 'UTest1' )->getTitle(); |
| 1854 |
$this->hideDeprecated( Title::class . '::getTitleProtection' ); |
| 1855 |
$this->assertFalse( $title->getTitleProtection() ); |
| 1856 |
} |
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
public function testGetSubpages() { |
| 1862 |
$existingPage = $this->getExistingTestPage(); |
| 1863 |
$title = $existingPage->getTitle(); |
| 1864 |
|
| 1865 |
$this->overrideConfigValue( |
| 1866 |
MainConfigNames::NamespacesWithSubpages, |
| 1867 |
[ $title->getNamespace() => true ] |
| 1868 |
); |
| 1869 |
|
| 1870 |
$this->getExistingTestPage( $title->getSubpage( 'A' ) ); |
| 1871 |
$this->getExistingTestPage( $title->getSubpage( 'B' ) ); |
| 1872 |
|
| 1873 |
$notQuiteSubpageTitle = $title->getPrefixedDBkey() . 'X'; |
| 1874 |
$this->getExistingTestPage( $notQuiteSubpageTitle ); |
| 1875 |
|
| 1876 |
$subpages = iterator_to_array( $title->getSubpages() ); |
| 1877 |
|
| 1878 |
$this->assertCount( 2, $subpages ); |
| 1879 |
$this->assertCount( 1, $title->getSubpages( 1 ) ); |
| 1880 |
} |
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
public function testGetSubpages_disabled() { |
| 1886 |
$this->overrideConfigValue( MainConfigNames::NamespacesWithSubpages, [] ); |
| 1887 |
|
| 1888 |
$existingPage = $this->getExistingTestPage(); |
| 1889 |
$title = $existingPage->getTitle(); |
| 1890 |
|
| 1891 |
$this->getExistingTestPage( $title->getSubpage( 'A' ) ); |
| 1892 |
$this->getExistingTestPage( $title->getSubpage( 'B' ) ); |
| 1893 |
|
| 1894 |
$this->assertSame( [], $title->getSubpages() ); |
| 1895 |
} |
| 1896 |
|
| 1897 |
public static function provideNamespaces() { |
| 1898 |
|
| 1899 |
$title = Title::makeTitle( NS_FILE, 'test', 'frag', 'meta' ); |
| 1900 |
return [ |
| 1901 |
[ NS_MAIN, '' ], |
| 1902 |
[ NS_FILE, 'File' ], |
| 1903 |
[ NS_MEDIA, 'Media' ], |
| 1904 |
[ NS_TALK, 'Talk' ], |
| 1905 |
[ NS_CATEGORY, 'Category' ], |
| 1906 |
[ $title, 'File' ], |
| 1907 |
]; |
| 1908 |
} |
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
public function testGetNsText( $namespace, $expected ) { |
| 1915 |
if ( $namespace instanceof Title ) { |
| 1916 |
$this->assertSame( $expected, $namespace->getNsText() ); |
| 1917 |
} else { |
| 1918 |
$actual = Title::makeTitle( $namespace, 'Title_test' )->getNsText(); |
| 1919 |
$this->assertSame( $expected, $actual ); |
| 1920 |
} |
| 1921 |
} |
| 1922 |
|
| 1923 |
public static function providePagesWithSubjects() { |
| 1924 |
return [ |
| 1925 |
[ Title::makeTitle( NS_USER_TALK, 'User_test' ), 'User' ], |
| 1926 |
[ Title::makeTitle( NS_PROJECT, 'Test' ), 'Project' ], |
| 1927 |
[ Title::makeTitle( NS_MAIN, 'Test' ), '' ], |
| 1928 |
[ Title::makeTitle( NS_CATEGORY, 'Cat_test' ), 'Category' ], |
| 1929 |
]; |
| 1930 |
} |
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
public function testGetSubjectNsText( Title $title, $expected ) { |
| 1937 |
$actual = $title->getSubjectNsText(); |
| 1938 |
$this->assertSame( $expected, $actual ); |
| 1939 |
} |
| 1940 |
|
| 1941 |
public static function provideTitlesWithTalkPages() { |
| 1942 |
return [ |
| 1943 |
[ Title::makeTitle( NS_HELP, 'Help page' ), 'Help_talk' ], |
| 1944 |
[ Title::newMainPage(), 'Talk' ], |
| 1945 |
[ Title::makeTitle( NS_PROJECT, 'Test' ), 'Project_talk' ], |
| 1946 |
]; |
| 1947 |
} |
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
public function testGetTalkNsText( Title $title, $expected ) { |
| 1954 |
$actual = $title->getTalkNsText(); |
| 1955 |
$this->assertSame( $expected, $actual ); |
| 1956 |
} |
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
public function testIsSpecial() { |
| 1962 |
$title = Title::makeTitle( NS_SPECIAL, 'Recentchanges/Subpage' ); |
| 1963 |
$this->assertTrue( $title->isSpecial( 'Recentchanges' ) ); |
| 1964 |
} |
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
public function testIsNotSpecial() { |
| 1970 |
$title = Title::newFromText( 'NotSpecialPage/Subpage', NS_SPECIAL ); |
| 1971 |
$this->assertFalse( $title->isSpecial( 'NotSpecialPage' ) ); |
| 1972 |
} |
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
public function testIsTalkPage() { |
| 1978 |
$title = Title::newFromText( 'Talk page', NS_TALK ); |
| 1979 |
$this->assertTrue( $title->isTalkPage() ); |
| 1980 |
|
| 1981 |
$titleNotInTalkNs = Title::makeTitle( NS_HELP, 'Test' ); |
| 1982 |
$this->assertFalse( $titleNotInTalkNs->isTalkPage() ); |
| 1983 |
} |
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
public function testGetBacklinkCache() { |
| 1989 |
$blcFactory = $this->getServiceContainer()->getBacklinkCacheFactory(); |
| 1990 |
$backlinkCache = $blcFactory->getBacklinkCache( Title::makeTitle( NS_FILE, 'Test' ) ); |
| 1991 |
$this->assertInstanceOf( BacklinkCache::class, $backlinkCache ); |
| 1992 |
} |
| 1993 |
|
| 1994 |
public static function provideNsWithSubpagesSupport() { |
| 1995 |
return [ |
| 1996 |
[ NS_HELP, 'Mainhelp', 'Mainhelp/Subhelp' ], |
| 1997 |
[ NS_USER, 'Mainuser', 'Mainuser/Subuser' ], |
| 1998 |
[ NS_TALK, 'Maintalk', 'Maintalk/Subtalk' ], |
| 1999 |
[ NS_PROJECT, 'Mainproject', 'Mainproject/Subproject' ], |
| 2000 |
]; |
| 2001 |
} |
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
public function testIsSubpageOfWithNamespacesSubpages( $namespace, $pageName, $subpageName ) { |
| 2009 |
$page = Title::makeTitle( $namespace, $pageName, '', 'meta' ); |
| 2010 |
$subPage = Title::makeTitle( $namespace, $subpageName, '', 'meta' ); |
| 2011 |
|
| 2012 |
$this->assertTrue( $subPage->isSubpageOf( $page ) ); |
| 2013 |
$this->assertTrue( $subPage->isSubpage() ); |
| 2014 |
} |
| 2015 |
|
| 2016 |
public static function provideNsWithNoSubpages() { |
| 2017 |
return [ |
| 2018 |
[ NS_CATEGORY, 'Maincat', 'Maincat/Subcat' ], |
| 2019 |
[ NS_MAIN, 'Mainpage', 'Mainpage/Subpage' ] |
| 2020 |
]; |
| 2021 |
} |
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
public function testIsSubpageOfWithoutNamespacesSubpages( $namespace, $pageName, $subpageName ) { |
| 2029 |
$page = Title::makeTitle( $namespace, $pageName, '', 'meta' ); |
| 2030 |
$subPage = Title::makeTitle( $namespace, $subpageName, '', 'meta' ); |
| 2031 |
|
| 2032 |
$this->assertFalse( $page->isSubpageOf( $page ) ); |
| 2033 |
$this->assertFalse( $subPage->isSubpage() ); |
| 2034 |
} |
| 2035 |
|
| 2036 |
public static function provideTitleEditURLs() { |
| 2037 |
return [ |
| 2038 |
[ Title::makeTitle( NS_MAIN, 'Title' ), '/w/index.php?title=Title&action=edit' ], |
| 2039 |
[ Title::makeTitle( NS_HELP, 'Test', '', 'mw' ), '' ], |
| 2040 |
[ Title::makeTitle( NS_HELP, 'Test' ), '/w/index.php?title=Help:Test&action=edit' ], |
| 2041 |
]; |
| 2042 |
} |
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
public function testGetEditURL( Title $title, $expected ) { |
| 2049 |
$actual = $title->getEditURL(); |
| 2050 |
$this->assertSame( $expected, $actual ); |
| 2051 |
} |
| 2052 |
|
| 2053 |
public static function provideTitleEditURLsWithActionPaths() { |
| 2054 |
return [ |
| 2055 |
[ Title::newFromText( 'Title', NS_MAIN ), '/wiki/edit/Title' ], |
| 2056 |
[ Title::makeTitle( NS_HELP, 'Test', '', 'mw' ), '' ], |
| 2057 |
[ Title::newFromText( 'Test', NS_HELP ), '/wiki/edit/Help:Test' ], |
| 2058 |
]; |
| 2059 |
} |
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
public function testGetEditUrlWithActionPaths( Title $title, $expected ) { |
| 2066 |
$this->overrideConfigValue( MainConfigNames::ActionPaths, [ 'edit' => '/wiki/edit/$1' ] ); |
| 2067 |
$actual = $title->getEditURL(); |
| 2068 |
$this->assertSame( $expected, $actual ); |
| 2069 |
} |
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
public function testIsMainPage() { |
| 2076 |
$this->assertTrue( Title::newMainPage()->isMainPage() ); |
| 2077 |
} |
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
public function testIsNotMainPage( Title $title, $expected ) { |
| 2085 |
$this->assertSame( $expected, $title->isMainPage() ); |
| 2086 |
} |
| 2087 |
|
| 2088 |
public static function provideMainPageTitles() { |
| 2089 |
return [ |
| 2090 |
[ Title::makeTitle( NS_MAIN, 'Test' ), false ], |
| 2091 |
[ Title::makeTitle( NS_CATEGORY, 'mw:Category' ), false ], |
| 2092 |
]; |
| 2093 |
} |
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
public function testGetPrefixedURL( Title $title, $expected ) { |
| 2101 |
$actual = $title->getPrefixedURL(); |
| 2102 |
|
| 2103 |
$this->assertSame( $expected, $actual ); |
| 2104 |
} |
| 2105 |
|
| 2106 |
public static function provideDataForTestGetPrefixedURL() { |
| 2107 |
return [ |
| 2108 |
[ Title::makeTitle( NS_FILE, 'Title' ), 'File:Title' ], |
| 2109 |
[ Title::makeTitle( NS_MEDIA, 'Title' ), 'Media:Title' ], |
| 2110 |
[ Title::makeTitle( NS_CATEGORY, 'Title' ), 'Category:Title' ], |
| 2111 |
[ Title::makeTitle( NS_FILE, 'Title with spaces' ), 'File:Title_with_spaces' ], |
| 2112 |
[ |
| 2113 |
Title::makeTitle( NS_FILE, 'Title with spaces', '', 'mw' ), |
| 2114 |
'mw:File:Title_with_spaces' |
| 2115 |
], |
| 2116 |
]; |
| 2117 |
} |
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
public function testToString() { |
| 2123 |
$title = Title::makeTitle( NS_USER, 'User test' ); |
| 2124 |
|
| 2125 |
$this->assertSame( 'User:User test', (string)$title ); |
| 2126 |
} |
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
public function testGetFullText( Title $title, $expected ) { |
| 2133 |
$actual = $title->getFullText(); |
| 2134 |
|
| 2135 |
$this->assertSame( $expected, $actual ); |
| 2136 |
} |
| 2137 |
|
| 2138 |
public static function provideDataForTestGetFullText() { |
| 2139 |
return [ |
| 2140 |
[ Title::makeTitle( NS_TALK, 'Test' ), 'Talk:Test' ], |
| 2141 |
[ Title::makeTitle( NS_HELP, 'Test', 'frag' ), 'Help:Test#frag' ], |
| 2142 |
[ Title::makeTitle( NS_TALK, 'Test', 'frag', 'phab' ), 'phab:Talk:Test#frag' ], |
| 2143 |
]; |
| 2144 |
} |
| 2145 |
|
| 2146 |
public static function provideIsSamePageAs() { |
| 2147 |
$title = Title::makeTitle( 0, 'Foo' ); |
| 2148 |
$title->resetArticleID( 1 ); |
| 2149 |
yield '(PageIdentityValue) same text, title has ID 0' => [ |
| 2150 |
$title, |
| 2151 |
new PageIdentityValue( 1, 0, 'Foo', PageIdentity::LOCAL ), |
| 2152 |
true |
| 2153 |
]; |
| 2154 |
|
| 2155 |
$title = Title::makeTitle( 1, 'Bar_Baz' ); |
| 2156 |
$title->resetArticleID( 0 ); |
| 2157 |
yield '(PageIdentityValue) same text, PageIdentityValue has ID 0' => [ |
| 2158 |
$title, |
| 2159 |
new PageIdentityValue( 0, 1, 'Bar_Baz', PageIdentity::LOCAL ), |
| 2160 |
true |
| 2161 |
]; |
| 2162 |
|
| 2163 |
$title = Title::makeTitle( 0, 'Foo' ); |
| 2164 |
$title->resetArticleID( 0 ); |
| 2165 |
yield '(PageIdentityValue) different text, both IDs are 0' => [ |
| 2166 |
$title, |
| 2167 |
new PageIdentityValue( 0, 0, 'Foozz', PageIdentity::LOCAL ), |
| 2168 |
false |
| 2169 |
]; |
| 2170 |
|
| 2171 |
$title = Title::makeTitle( 0, 'Foo' ); |
| 2172 |
$title->resetArticleID( 0 ); |
| 2173 |
yield '(PageIdentityValue) different namespace' => [ |
| 2174 |
$title, |
| 2175 |
new PageIdentityValue( 0, 1, 'Foo', PageIdentity::LOCAL ), |
| 2176 |
false |
| 2177 |
]; |
| 2178 |
|
| 2179 |
$title = Title::makeTitle( 0, 'Foo', '' ); |
| 2180 |
$title->resetArticleID( 1 ); |
| 2181 |
yield '(PageIdentityValue) different wiki, different ID' => [ |
| 2182 |
$title, |
| 2183 |
new PageIdentityValue( 1, 0, 'Foo', 'bar' ), |
| 2184 |
false |
| 2185 |
]; |
| 2186 |
|
| 2187 |
$title = Title::makeTitle( 0, 'Foo', '' ); |
| 2188 |
$title->resetArticleID( 0 ); |
| 2189 |
yield '(PageIdentityValue) different wiki, both IDs are 0' => [ |
| 2190 |
$title, |
| 2191 |
new PageIdentityValue( 0, 0, 'Foo', 'bar' ), |
| 2192 |
false |
| 2193 |
]; |
| 2194 |
} |
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
public function testIsSamePageAs( Title $firstValue, $secondValue, $expectedSame ) { |
| 2201 |
$this->assertSame( |
| 2202 |
$expectedSame, |
| 2203 |
$firstValue->isSamePageAs( $secondValue ) |
| 2204 |
); |
| 2205 |
} |
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
public function testGetFieldsOfNonExistingPage() { |
| 2220 |
$title = Title::makeTitle( NS_MAIN, 'ThisDoesNotExist-92347852349' ); |
| 2221 |
|
| 2222 |
$this->assertSame( 0, $title->getArticleID() ); |
| 2223 |
$this->assertSame( 0, $title->getId() ); |
| 2224 |
$this->assertSame( 0, $title->getLength() ); |
| 2225 |
$this->assertSame( 0, $title->getLatestRevID() ); |
| 2226 |
$this->assertFalse( $title->exists() ); |
| 2227 |
$this->assertFalse( $title->isNewPage() ); |
| 2228 |
$this->assertFalse( $title->isRedirect() ); |
| 2229 |
$this->assertFalse( $title->getTouched() ); |
| 2230 |
$this->assertNotEmpty( $title->getContentModel() ); |
| 2231 |
} |
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
public function testGetDefaultSystemMessage() { |
| 2237 |
$title = Title::makeTitle( NS_MEDIAWIKI, 'Logouttext' ); |
| 2238 |
|
| 2239 |
$this->assertInstanceOf( Message::class, $title->getDefaultSystemMessage() ); |
| 2240 |
$this->assertStringContainsString( 'You are now logged out', $title->getDefaultMessageText() ); |
| 2241 |
} |
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
public function testGetDefaultSystemMessageReturnsNull() { |
| 2247 |
$title = Title::makeTitle( NS_MAIN, 'Some title' ); |
| 2248 |
|
| 2249 |
$this->assertNull( $title->getDefaultSystemMessage() ); |
| 2250 |
} |
| 2251 |
|
| 2252 |
} |