Merge "Allow partially blocked users to tag unrelated revisions"
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleTest.php
1 <?php
2
3 use MediaWiki\Interwiki\InterwikiLookup;
4 use MediaWiki\Linker\LinkTarget;
5 use MediaWiki\MediaWikiServices;
6
7 /**
8 * @group Database
9 * @group Title
10 */
11 class TitleTest extends MediaWikiTestCase {
12 protected function setUp() {
13 parent::setUp();
14
15 $this->setMwGlobals( [
16 'wgAllowUserJs' => false,
17 'wgDefaultLanguageVariant' => false,
18 'wgMetaNamespace' => 'Project',
19 ] );
20 $this->setUserLang( 'en' );
21 $this->setContentLang( 'en' );
22 }
23
24 /**
25 * @covers Title::legalChars
26 */
27 public function testLegalChars() {
28 $titlechars = Title::legalChars();
29
30 foreach ( range( 1, 255 ) as $num ) {
31 $chr = chr( $num );
32 if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
33 $this->assertFalse(
34 (bool)preg_match( "/[$titlechars]/", $chr ),
35 "chr($num) = $chr is not a valid titlechar"
36 );
37 } else {
38 $this->assertTrue(
39 (bool)preg_match( "/[$titlechars]/", $chr ),
40 "chr($num) = $chr is a valid titlechar"
41 );
42 }
43 }
44 }
45
46 public static function provideValidSecureAndSplit() {
47 return [
48 [ 'Sandbox' ],
49 [ 'A "B"' ],
50 [ 'A \'B\'' ],
51 [ '.com' ],
52 [ '~' ],
53 [ '#' ],
54 [ '"' ],
55 [ '\'' ],
56 [ 'Talk:Sandbox' ],
57 [ 'Talk:Foo:Sandbox' ],
58 [ 'File:Example.svg' ],
59 [ 'File_talk:Example.svg' ],
60 [ 'Foo/.../Sandbox' ],
61 [ 'Sandbox/...' ],
62 [ 'A~~' ],
63 [ ':A' ],
64 // Length is 256 total, but only title part matters
65 [ 'Category:' . str_repeat( 'x', 248 ) ],
66 [ str_repeat( 'x', 252 ) ],
67 // interwiki prefix
68 [ 'localtestiw: #anchor' ],
69 [ 'localtestiw:' ],
70 [ 'localtestiw:foo' ],
71 [ 'localtestiw: foo # anchor' ],
72 [ 'localtestiw: Talk: Sandbox # anchor' ],
73 [ 'remotetestiw:' ],
74 [ 'remotetestiw: Talk: # anchor' ],
75 [ 'remotetestiw: #bar' ],
76 [ 'remotetestiw: Talk:' ],
77 [ 'remotetestiw: Talk: Foo' ],
78 [ 'localtestiw:remotetestiw:' ],
79 [ 'localtestiw:remotetestiw:foo' ]
80 ];
81 }
82
83 public static function provideInvalidSecureAndSplit() {
84 return [
85 [ '', 'title-invalid-empty' ],
86 [ ':', 'title-invalid-empty' ],
87 [ '__ __', 'title-invalid-empty' ],
88 [ ' __ ', 'title-invalid-empty' ],
89 // Bad characters forbidden regardless of wgLegalTitleChars
90 [ 'A [ B', 'title-invalid-characters' ],
91 [ 'A ] B', 'title-invalid-characters' ],
92 [ 'A { B', 'title-invalid-characters' ],
93 [ 'A } B', 'title-invalid-characters' ],
94 [ 'A < B', 'title-invalid-characters' ],
95 [ 'A > B', 'title-invalid-characters' ],
96 [ 'A | B', 'title-invalid-characters' ],
97 [ "A \t B", 'title-invalid-characters' ],
98 [ "A \n B", 'title-invalid-characters' ],
99 // URL encoding
100 [ 'A%20B', 'title-invalid-characters' ],
101 [ 'A%23B', 'title-invalid-characters' ],
102 [ 'A%2523B', 'title-invalid-characters' ],
103 // XML/HTML character entity references
104 // Note: Commented out because they are not marked invalid by the PHP test as
105 // Title::newFromText runs Sanitizer::decodeCharReferencesAndNormalize first.
106 // 'A &eacute; B',
107 // 'A &#233; B',
108 // 'A &#x00E9; B',
109 // Subject of NS_TALK does not roundtrip to NS_MAIN
110 [ 'Talk:File:Example.svg', 'title-invalid-talk-namespace' ],
111 // Directory navigation
112 [ '.', 'title-invalid-relative' ],
113 [ '..', 'title-invalid-relative' ],
114 [ './Sandbox', 'title-invalid-relative' ],
115 [ '../Sandbox', 'title-invalid-relative' ],
116 [ 'Foo/./Sandbox', 'title-invalid-relative' ],
117 [ 'Foo/../Sandbox', 'title-invalid-relative' ],
118 [ 'Sandbox/.', 'title-invalid-relative' ],
119 [ 'Sandbox/..', 'title-invalid-relative' ],
120 // Tilde
121 [ 'A ~~~ Name', 'title-invalid-magic-tilde' ],
122 [ 'A ~~~~ Signature', 'title-invalid-magic-tilde' ],
123 [ 'A ~~~~~ Timestamp', 'title-invalid-magic-tilde' ],
124 // Length
125 [ str_repeat( 'x', 256 ), 'title-invalid-too-long' ],
126 // Namespace prefix without actual title
127 [ 'Talk:', 'title-invalid-empty' ],
128 [ 'Talk:#', 'title-invalid-empty' ],
129 [ 'Category: ', 'title-invalid-empty' ],
130 [ 'Category: #bar', 'title-invalid-empty' ],
131 // interwiki prefix
132 [ 'localtestiw: Talk: # anchor', 'title-invalid-empty' ],
133 [ 'localtestiw: Talk:', 'title-invalid-empty' ]
134 ];
135 }
136
137 private function secureAndSplitGlobals() {
138 $this->setMwGlobals( [
139 'wgLocalInterwikis' => [ 'localtestiw' ],
140 'wgHooks' => [
141 'InterwikiLoadPrefix' => [
142 function ( $prefix, &$data ) {
143 if ( $prefix === 'localtestiw' ) {
144 $data = [ 'iw_url' => 'localtestiw' ];
145 } elseif ( $prefix === 'remotetestiw' ) {
146 $data = [ 'iw_url' => 'remotetestiw' ];
147 }
148 return false;
149 }
150 ]
151 ]
152 ] );
153 }
154
155 /**
156 * See also mediawiki.Title.test.js
157 * @covers Title::secureAndSplit
158 * @dataProvider provideValidSecureAndSplit
159 * @note This mainly tests MediaWikiTitleCodec::parseTitle().
160 */
161 public function testSecureAndSplitValid( $text ) {
162 $this->secureAndSplitGlobals();
163 $this->assertInstanceOf( Title::class, Title::newFromText( $text ), "Valid: $text" );
164 }
165
166 /**
167 * See also mediawiki.Title.test.js
168 * @covers Title::secureAndSplit
169 * @dataProvider provideInvalidSecureAndSplit
170 * @note This mainly tests MediaWikiTitleCodec::parseTitle().
171 */
172 public function testSecureAndSplitInvalid( $text, $expectedErrorMessage ) {
173 $this->secureAndSplitGlobals();
174 try {
175 Title::newFromTextThrow( $text ); // should throw
176 $this->assertTrue( false, "Invalid: $text" );
177 } catch ( MalformedTitleException $ex ) {
178 $this->assertEquals( $expectedErrorMessage, $ex->getErrorMessage(), "Invalid: $text" );
179 }
180 }
181
182 public static function provideConvertByteClassToUnicodeClass() {
183 return [
184 [
185 ' %!"$&\'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+',
186 ' %!"$&\'()*,\\-./0-9:;=?@A-Z\\\\\\^_`a-z~+\\u0080-\\uFFFF',
187 ],
188 [
189 'QWERTYf-\\xFF+',
190 'QWERTYf-\\x7F+\\u0080-\\uFFFF',
191 ],
192 [
193 'QWERTY\\x66-\\xFD+',
194 'QWERTYf-\\x7F+\\u0080-\\uFFFF',
195 ],
196 [
197 'QWERTYf-y+',
198 'QWERTYf-y+',
199 ],
200 [
201 'QWERTYf-\\x80+',
202 'QWERTYf-\\x7F+\\u0080-\\uFFFF',
203 ],
204 [
205 'QWERTY\\x66-\\x80+\\x23',
206 'QWERTYf-\\x7F+#\\u0080-\\uFFFF',
207 ],
208 [
209 'QWERTY\\x66-\\x80+\\xD3',
210 'QWERTYf-\\x7F+\\u0080-\\uFFFF',
211 ],
212 [
213 '\\\\\\x99',
214 '\\\\\\u0080-\\uFFFF',
215 ],
216 [
217 '-\\x99',
218 '\\-\\u0080-\\uFFFF',
219 ],
220 [
221 'QWERTY\\-\\x99',
222 'QWERTY\\-\\u0080-\\uFFFF',
223 ],
224 [
225 '\\\\x99',
226 '\\\\x99',
227 ],
228 [
229 'A-\\x9F',
230 'A-\\x7F\\u0080-\\uFFFF',
231 ],
232 [
233 '\\x66-\\x77QWERTY\\x88-\\x91FXZ',
234 'f-wQWERTYFXZ\\u0080-\\uFFFF',
235 ],
236 [
237 '\\x66-\\x99QWERTY\\xAA-\\xEEFXZ',
238 'f-\\x7FQWERTYFXZ\\u0080-\\uFFFF',
239 ],
240 ];
241 }
242
243 /**
244 * @dataProvider provideConvertByteClassToUnicodeClass
245 * @covers Title::convertByteClassToUnicodeClass
246 */
247 public function testConvertByteClassToUnicodeClass( $byteClass, $unicodeClass ) {
248 $this->assertEquals( $unicodeClass, Title::convertByteClassToUnicodeClass( $byteClass ) );
249 }
250
251 /**
252 * @dataProvider provideSpecialNamesWithAndWithoutParameter
253 * @covers Title::fixSpecialName
254 */
255 public function testFixSpecialNameRetainsParameter( $text, $expectedParam ) {
256 $title = Title::newFromText( $text );
257 $fixed = $title->fixSpecialName();
258 $stuff = explode( '/', $fixed->getDBkey(), 2 );
259 if ( count( $stuff ) == 2 ) {
260 $par = $stuff[1];
261 } else {
262 $par = null;
263 }
264 $this->assertEquals(
265 $expectedParam,
266 $par,
267 "T33100 regression check: Title->fixSpecialName() should preserve parameter"
268 );
269 }
270
271 public static function provideSpecialNamesWithAndWithoutParameter() {
272 return [
273 [ 'Special:Version', null ],
274 [ 'Special:Version/', '' ],
275 [ 'Special:Version/param', 'param' ],
276 ];
277 }
278
279 /**
280 * Auth-less test of Title::userCan
281 *
282 * @param array $whitelistRegexp
283 * @param string $source
284 * @param string $action
285 * @param array|string|bool $expected Required error
286 *
287 * @covers \Mediawiki\Permissions\PermissionManager::checkReadPermissions
288 * @dataProvider dataWgWhitelistReadRegexp
289 */
290 public function testWgWhitelistReadRegexp( $whitelistRegexp, $source, $action, $expected ) {
291 // $wgWhitelistReadRegexp must be an array. Since the provided test cases
292 // usually have only one regex, it is more concise to write the lonely regex
293 // as a string. Thus we cast to a [] to honor $wgWhitelistReadRegexp
294 // type requisite.
295 if ( is_string( $whitelistRegexp ) ) {
296 $whitelistRegexp = [ $whitelistRegexp ];
297 }
298
299 $this->setMwGlobals( [
300 // So User::isEveryoneAllowed( 'read' ) === false
301 'wgGroupPermissions' => [ '*' => [ 'read' => false ] ],
302 'wgWhitelistRead' => [ 'some random non sense title' ],
303 'wgWhitelistReadRegexp' => $whitelistRegexp,
304 ] );
305
306 $title = Title::newFromDBkey( $source );
307
308 // New anonymous user with no rights
309 $user = new User;
310 $this->overrideUserPermissions( $user, [] );
311 $errors = $title->userCan( $action, $user );
312
313 if ( is_bool( $expected ) ) {
314 # Forge the assertion message depending on the assertion expectation
315 $allowableness = $expected
316 ? " should be allowed"
317 : " should NOT be allowed";
318 $this->assertEquals(
319 $expected,
320 $errors,
321 "User action '$action' on [[$source]] $allowableness."
322 );
323 } else {
324 $errors = $this->flattenErrorsArray( $errors );
325 foreach ( (array)$expected as $error ) {
326 $this->assertContains( $error, $errors );
327 }
328 }
329 }
330
331 /**
332 * Provides test parameter values for testWgWhitelistReadRegexp()
333 */
334 public function dataWgWhitelistReadRegexp() {
335 $ALLOWED = true;
336 $DISALLOWED = false;
337
338 return [
339 // Everything, if this doesn't work, we're really in trouble
340 [ '/.*/', 'Main_Page', 'read', $ALLOWED ],
341 [ '/.*/', 'Main_Page', 'edit', $DISALLOWED ],
342
343 // We validate against the title name, not the db key
344 [ '/^Main_Page$/', 'Main_Page', 'read', $DISALLOWED ],
345 // Main page
346 [ '/^Main/', 'Main_Page', 'read', $ALLOWED ],
347 [ '/^Main.*/', 'Main_Page', 'read', $ALLOWED ],
348 // With spaces
349 [ '/Mic\sCheck/', 'Mic Check', 'read', $ALLOWED ],
350 // Unicode multibyte
351 // ...without unicode modifier
352 [ '/Unicode Test . Yes/', 'Unicode Test Ñ Yes', 'read', $DISALLOWED ],
353 // ...with unicode modifier
354 [ '/Unicode Test . Yes/u', 'Unicode Test Ñ Yes', 'read', $ALLOWED ],
355 // Case insensitive
356 [ '/MiC ChEcK/', 'mic check', 'read', $DISALLOWED ],
357 [ '/MiC ChEcK/i', 'mic check', 'read', $ALLOWED ],
358
359 // From DefaultSettings.php:
360 [ "@^UsEr.*@i", 'User is banned', 'read', $ALLOWED ],
361 [ "@^UsEr.*@i", 'User:John Doe', 'read', $ALLOWED ],
362
363 // With namespaces:
364 [ '/^Special:NewPages$/', 'Special:NewPages', 'read', $ALLOWED ],
365 [ null, 'Special:Newpages', 'read', $DISALLOWED ],
366
367 ];
368 }
369
370 public function flattenErrorsArray( $errors ) {
371 $result = [];
372 foreach ( $errors as $error ) {
373 $result[] = $error[0];
374 }
375
376 return $result;
377 }
378
379 /**
380 * @dataProvider provideGetPageViewLanguage
381 * @covers Title::getPageViewLanguage
382 */
383 public function testGetPageViewLanguage( $expected, $titleText, $contLang,
384 $lang, $variant, $msg = ''
385 ) {
386 // Setup environnement for this test
387 $this->setMwGlobals( [
388 'wgDefaultLanguageVariant' => $variant,
389 'wgAllowUserJs' => true,
390 ] );
391 $this->setUserLang( $lang );
392 $this->setContentLang( $contLang );
393
394 $title = Title::newFromText( $titleText );
395 $this->assertInstanceOf( Title::class, $title,
396 "Test must be passed a valid title text, you gave '$titleText'"
397 );
398 $this->assertEquals( $expected,
399 $title->getPageViewLanguage()->getCode(),
400 $msg
401 );
402 }
403
404 public static function provideGetPageViewLanguage() {
405 # Format:
406 # - expected
407 # - Title name
408 # - content language (expected in most cases)
409 # - wgLang (on some specific pages)
410 # - wgDefaultLanguageVariant
411 # - Optional message
412 return [
413 [ 'fr', 'Help:I_need_somebody', 'fr', 'fr', false ],
414 [ 'es', 'Help:I_need_somebody', 'es', 'zh-tw', false ],
415 [ 'zh', 'Help:I_need_somebody', 'zh', 'zh-tw', false ],
416
417 [ 'es', 'Help:I_need_somebody', 'es', 'zh-tw', 'zh-cn' ],
418 [ 'es', 'MediaWiki:About', 'es', 'zh-tw', 'zh-cn' ],
419 [ 'es', 'MediaWiki:About/', 'es', 'zh-tw', 'zh-cn' ],
420 [ 'de', 'MediaWiki:About/de', 'es', 'zh-tw', 'zh-cn' ],
421 [ 'en', 'MediaWiki:Common.js', 'es', 'zh-tw', 'zh-cn' ],
422 [ 'en', 'MediaWiki:Common.css', 'es', 'zh-tw', 'zh-cn' ],
423 [ 'en', 'User:JohnDoe/Common.js', 'es', 'zh-tw', 'zh-cn' ],
424 [ 'en', 'User:JohnDoe/Monobook.css', 'es', 'zh-tw', 'zh-cn' ],
425
426 [ 'zh-cn', 'Help:I_need_somebody', 'zh', 'zh-tw', 'zh-cn' ],
427 [ 'zh', 'MediaWiki:About', 'zh', 'zh-tw', 'zh-cn' ],
428 [ 'zh', 'MediaWiki:About/', 'zh', 'zh-tw', 'zh-cn' ],
429 [ 'de', 'MediaWiki:About/de', 'zh', 'zh-tw', 'zh-cn' ],
430 [ 'zh-cn', 'MediaWiki:About/zh-cn', 'zh', 'zh-tw', 'zh-cn' ],
431 [ 'zh-tw', 'MediaWiki:About/zh-tw', 'zh', 'zh-tw', 'zh-cn' ],
432 [ 'en', 'MediaWiki:Common.js', 'zh', 'zh-tw', 'zh-cn' ],
433 [ 'en', 'MediaWiki:Common.css', 'zh', 'zh-tw', 'zh-cn' ],
434 [ 'en', 'User:JohnDoe/Common.js', 'zh', 'zh-tw', 'zh-cn' ],
435 [ 'en', 'User:JohnDoe/Monobook.css', 'zh', 'zh-tw', 'zh-cn' ],
436
437 [ 'zh-tw', 'Special:NewPages', 'es', 'zh-tw', 'zh-cn' ],
438 [ 'zh-tw', 'Special:NewPages', 'zh', 'zh-tw', 'zh-cn' ],
439
440 ];
441 }
442
443 /**
444 * @dataProvider provideBaseTitleCases
445 * @covers Title::getBaseText
446 */
447 public function testGetBaseText( $title, $expected, $msg = '' ) {
448 $title = Title::newFromText( $title );
449 $this->assertSame( $expected,
450 $title->getBaseText(),
451 $msg
452 );
453 }
454
455 /**
456 * @dataProvider provideBaseTitleCases
457 * @covers Title::getBaseTitle
458 */
459 public function testGetBaseTitle( $title, $expected, $msg = '' ) {
460 $title = Title::newFromText( $title );
461 $base = $title->getBaseTitle();
462 $this->assertTrue( $base->isValid(), $msg );
463 $this->assertTrue(
464 $base->equals( Title::makeTitleSafe( $title->getNamespace(), $expected ) ),
465 $msg
466 );
467 }
468
469 public static function provideBaseTitleCases() {
470 return [
471 # Title, expected base, optional message
472 [ 'User:John_Doe/subOne/subTwo', 'John Doe/subOne' ],
473 [ 'User:Foo / Bar / Baz', 'Foo / Bar ' ],
474 ];
475 }
476
477 /**
478 * @dataProvider provideRootTitleCases
479 * @covers Title::getRootText
480 */
481 public function testGetRootText( $title, $expected, $msg = '' ) {
482 $title = Title::newFromText( $title );
483 $this->assertEquals( $expected,
484 $title->getRootText(),
485 $msg
486 );
487 }
488
489 /**
490 * @dataProvider provideRootTitleCases
491 * @covers Title::getRootTitle
492 */
493 public function testGetRootTitle( $title, $expected, $msg = '' ) {
494 $title = Title::newFromText( $title );
495 $root = $title->getRootTitle();
496 $this->assertTrue( $root->isValid(), $msg );
497 $this->assertTrue(
498 $root->equals( Title::makeTitleSafe( $title->getNamespace(), $expected ) ),
499 $msg
500 );
501 }
502
503 public static function provideRootTitleCases() {
504 return [
505 # Title, expected base, optional message
506 [ 'User:John_Doe/subOne/subTwo', 'John Doe' ],
507 [ 'User:Foo / Bar / Baz', 'Foo ' ],
508 [ 'Talk:////', '////' ],
509 [ 'Template:////', '////' ],
510 [ 'Template:Foo////', 'Foo' ],
511 [ 'Template:Foo////Bar', 'Foo' ],
512 ];
513 }
514
515 /**
516 * @todo Handle $wgNamespacesWithSubpages cases
517 * @dataProvider provideSubpageTitleCases
518 * @covers Title::getSubpageText
519 */
520 public function testGetSubpageText( $title, $expected, $msg = '' ) {
521 $title = Title::newFromText( $title );
522 $this->assertEquals( $expected,
523 $title->getSubpageText(),
524 $msg
525 );
526 }
527
528 public static function provideSubpageTitleCases() {
529 return [
530 # Title, expected base, optional message
531 [ 'User:John_Doe/subOne/subTwo', 'subTwo' ],
532 [ 'User:John_Doe/subOne', 'subOne' ],
533 ];
534 }
535
536 public function provideSubpage() {
537 // NOTE: avoid constructing Title objects in the provider, since it may access the database.
538 return [
539 [ 'Foo', 'x', new TitleValue( NS_MAIN, 'Foo/x' ) ],
540 [ 'Foo#bar', 'x', new TitleValue( NS_MAIN, 'Foo/x' ) ],
541 [ 'User:Foo', 'x', new TitleValue( NS_USER, 'Foo/x' ) ],
542 [ 'wiki:User:Foo', 'x', new TitleValue( NS_MAIN, 'User:Foo/x', '', 'wiki' ) ],
543 ];
544 }
545
546 /**
547 * @dataProvider provideSubpage
548 * @covers Title::getSubpage
549 */
550 public function testSubpage( $title, $sub, LinkTarget $expected ) {
551 $interwikiLookup = $this->getMock( InterwikiLookup::class );
552 $interwikiLookup->expects( $this->any() )
553 ->method( 'isValidInterwiki' )
554 ->willReturnCallback(
555 function ( $prefix ) {
556 return $prefix == 'wiki';
557 }
558 );
559
560 $this->setService( 'InterwikiLookup', $interwikiLookup );
561
562 $title = Title::newFromText( $title );
563 $expected = Title::newFromLinkTarget( $expected );
564 $actual = $title->getSubpage( $sub );
565
566 // NOTE: convert to string for comparison
567 $this->assertSame( $expected->getPrefixedText(), $actual->getPrefixedText(), 'text form' );
568 $this->assertTrue( $expected->equals( $actual ), 'Title equality' );
569 }
570
571 public static function provideNewFromTitleValue() {
572 return [
573 [ new TitleValue( NS_MAIN, 'Foo' ) ],
574 [ new TitleValue( NS_MAIN, 'Foo', 'bar' ) ],
575 [ new TitleValue( NS_USER, 'Hansi_Maier' ) ],
576 ];
577 }
578
579 /**
580 * @covers Title::newFromTitleValue
581 * @dataProvider provideNewFromTitleValue
582 */
583 public function testNewFromTitleValue( TitleValue $value ) {
584 $title = Title::newFromTitleValue( $value );
585
586 $dbkey = str_replace( ' ', '_', $value->getText() );
587 $this->assertEquals( $dbkey, $title->getDBkey() );
588 $this->assertEquals( $value->getNamespace(), $title->getNamespace() );
589 $this->assertEquals( $value->getFragment(), $title->getFragment() );
590 }
591
592 /**
593 * @covers Title::newFromLinkTarget
594 * @dataProvider provideNewFromTitleValue
595 */
596 public function testNewFromLinkTarget( LinkTarget $value ) {
597 $title = Title::newFromLinkTarget( $value );
598
599 $dbkey = str_replace( ' ', '_', $value->getText() );
600 $this->assertEquals( $dbkey, $title->getDBkey() );
601 $this->assertEquals( $value->getNamespace(), $title->getNamespace() );
602 $this->assertEquals( $value->getFragment(), $title->getFragment() );
603 }
604
605 /**
606 * @covers Title::newFromLinkTarget
607 */
608 public function testNewFromLinkTarget_clone() {
609 $title = Title::newFromText( __METHOD__ );
610 $this->assertSame( $title, Title::newFromLinkTarget( $title ) );
611
612 // The Title::NEW_CLONE flag should ensure that a fresh instance is returned.
613 $clone = Title::newFromLinkTarget( $title, Title::NEW_CLONE );
614 $this->assertNotSame( $title, $clone );
615 $this->assertTrue( $clone->equals( $title ) );
616 }
617
618 public function provideCastFromLinkTarget() {
619 return array_merge( [ [ null ] ], self::provideNewFromTitleValue() );
620 }
621
622 /**
623 * @covers Title::castFromLinkTarget
624 * @dataProvider provideCastFromLinkTarget
625 */
626 public function testCastFromLinkTarget( $value ) {
627 $title = Title::castFromLinkTarget( $value );
628
629 if ( $value === null ) {
630 $this->assertNull( $title );
631 } else {
632 $dbkey = str_replace( ' ', '_', $value->getText() );
633 $this->assertSame( $dbkey, $title->getDBkey() );
634 $this->assertSame( $value->getNamespace(), $title->getNamespace() );
635 $this->assertSame( $value->getFragment(), $title->getFragment() );
636 }
637 }
638
639 public static function provideGetTitleValue() {
640 return [
641 [ 'Foo' ],
642 [ 'Foo#bar' ],
643 [ 'User:Hansi_Maier' ],
644 ];
645 }
646
647 /**
648 * @covers Title::getTitleValue
649 * @dataProvider provideGetTitleValue
650 */
651 public function testGetTitleValue( $text ) {
652 $title = Title::newFromText( $text );
653 $value = $title->getTitleValue();
654
655 $dbkey = str_replace( ' ', '_', $value->getText() );
656 $this->assertEquals( $title->getDBkey(), $dbkey );
657 $this->assertEquals( $title->getNamespace(), $value->getNamespace() );
658 $this->assertEquals( $title->getFragment(), $value->getFragment() );
659 }
660
661 public static function provideGetFragment() {
662 return [
663 [ 'Foo', '' ],
664 [ 'Foo#bar', 'bar' ],
665 [ 'Foo#bär', 'bär' ],
666
667 // Inner whitespace is normalized
668 [ 'Foo#bar_bar', 'bar bar' ],
669 [ 'Foo#bar bar', 'bar bar' ],
670 [ 'Foo#bar bar', 'bar bar' ],
671
672 // Leading whitespace is kept, trailing whitespace is trimmed.
673 // XXX: Is this really want we want?
674 [ 'Foo#_bar_bar_', ' bar bar' ],
675 [ 'Foo# bar bar ', ' bar bar' ],
676 ];
677 }
678
679 /**
680 * @covers Title::getFragment
681 * @dataProvider provideGetFragment
682 *
683 * @param string $full
684 * @param string $fragment
685 */
686 public function testGetFragment( $full, $fragment ) {
687 $title = Title::newFromText( $full );
688 $this->assertEquals( $fragment, $title->getFragment() );
689 }
690
691 /**
692 * @covers Title::isAlwaysKnown
693 * @dataProvider provideIsAlwaysKnown
694 * @param string $page
695 * @param bool $isKnown
696 */
697 public function testIsAlwaysKnown( $page, $isKnown ) {
698 $title = Title::newFromText( $page );
699 $this->assertEquals( $isKnown, $title->isAlwaysKnown() );
700 }
701
702 public static function provideIsAlwaysKnown() {
703 return [
704 [ 'Some nonexistent page', false ],
705 [ 'UTPage', false ],
706 [ '#test', true ],
707 [ 'Special:BlankPage', true ],
708 [ 'Special:SomeNonexistentSpecialPage', false ],
709 [ 'MediaWiki:Parentheses', true ],
710 [ 'MediaWiki:Some nonexistent message', false ],
711 ];
712 }
713
714 /**
715 * @covers Title::isValid
716 * @dataProvider provideIsValid
717 * @param Title $title
718 * @param bool $isValid
719 */
720 public function testIsValid( Title $title, $isValid ) {
721 $this->assertEquals( $isValid, $title->isValid(), $title->getPrefixedText() );
722 }
723
724 public static function provideIsValid() {
725 return [
726 [ Title::makeTitle( NS_MAIN, '' ), false ],
727 [ Title::makeTitle( NS_MAIN, '<>' ), false ],
728 [ Title::makeTitle( NS_MAIN, '|' ), false ],
729 [ Title::makeTitle( NS_MAIN, '#' ), false ],
730 [ Title::makeTitle( NS_MAIN, 'Test' ), true ],
731 [ Title::makeTitle( NS_MAIN, ' Test' ), false ],
732 [ Title::makeTitle( NS_MAIN, '_Test' ), false ],
733 [ Title::makeTitle( NS_MAIN, 'Test ' ), false ],
734 [ Title::makeTitle( NS_MAIN, 'Test_' ), false ],
735 [ Title::makeTitle( NS_MAIN, "Test\nthis" ), false ],
736 [ Title::makeTitle( NS_MAIN, "Test\tthis" ), false ],
737 [ Title::makeTitle( -33, 'Test' ), false ],
738 [ Title::makeTitle( 77663399, 'Test' ), false ],
739 ];
740 }
741
742 /**
743 * @covers Title::isAlwaysKnown
744 */
745 public function testIsAlwaysKnownOnInterwiki() {
746 $title = Title::makeTitle( NS_MAIN, 'Interwiki link', '', 'externalwiki' );
747 $this->assertTrue( $title->isAlwaysKnown() );
748 }
749
750 /**
751 * @covers Title::exists
752 */
753 public function testExists() {
754 $title = Title::makeTitle( NS_PROJECT, 'New page' );
755 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
756
757 $article = new Article( $title );
758 $page = $article->getPage();
759 $page->doEditContent( new WikitextContent( 'Some [[link]]' ), 'summary' );
760
761 // Tell Title it doesn't know whether it exists
762 $title->mArticleID = -1;
763
764 // Tell the link cache it doesn't exist when it really does
765 $linkCache->clearLink( $title );
766 $linkCache->addBadLinkObj( $title );
767
768 $this->assertEquals(
769 false,
770 $title->exists(),
771 'exists() should rely on link cache unless READ_LATEST is used'
772 );
773 $this->assertEquals(
774 true,
775 $title->exists( Title::READ_LATEST ),
776 'exists() should re-query database when READ_LATEST is used'
777 );
778 }
779
780 public function provideCanHaveTalkPage() {
781 return [
782 'User page has talk page' => [
783 Title::makeTitle( NS_USER, 'Jane' ), true
784 ],
785 'Talke page has talk page' => [
786 Title::makeTitle( NS_TALK, 'Foo' ), true
787 ],
788 'Special page cannot have talk page' => [
789 Title::makeTitle( NS_SPECIAL, 'Thing' ), false
790 ],
791 'Virtual namespace cannot have talk page' => [
792 Title::makeTitle( NS_MEDIA, 'Kitten.jpg' ), false
793 ],
794 'Relative link has no talk page' => [
795 Title::makeTitle( NS_MAIN, '', 'Kittens' ), false
796 ],
797 'Interwiki link has no talk page' => [
798 Title::makeTitle( NS_MAIN, 'Kittens', '', 'acme' ), false
799 ],
800 ];
801 }
802
803 public function provideIsWatchable() {
804 return [
805 'User page is watchable' => [
806 Title::makeTitle( NS_USER, 'Jane' ), true
807 ],
808 'Talke page is watchable' => [
809 Title::makeTitle( NS_TALK, 'Foo' ), true
810 ],
811 'Special page is not watchable' => [
812 Title::makeTitle( NS_SPECIAL, 'Thing' ), false
813 ],
814 'Virtual namespace is not watchable' => [
815 Title::makeTitle( NS_MEDIA, 'Kitten.jpg' ), false
816 ],
817 'Relative link is not watchable' => [
818 Title::makeTitle( NS_MAIN, '', 'Kittens' ), false
819 ],
820 'Interwiki link is not watchable' => [
821 Title::makeTitle( NS_MAIN, 'Kittens', '', 'acme' ), false
822 ],
823 ];
824 }
825
826 public static function provideGetTalkPage_good() {
827 return [
828 [ Title::makeTitle( NS_MAIN, 'Test' ), Title::makeTitle( NS_TALK, 'Test' ) ],
829 [ Title::makeTitle( NS_TALK, 'Test' ), Title::makeTitle( NS_TALK, 'Test' ) ],
830 ];
831 }
832
833 public static function provideGetTalkPage_bad() {
834 return [
835 [ Title::makeTitle( NS_SPECIAL, 'Test' ) ],
836 [ Title::makeTitle( NS_MEDIA, 'Test' ) ],
837 [ Title::makeTitle( NS_MAIN, '', 'Kittens' ) ],
838 [ Title::makeTitle( NS_MAIN, 'Kittens', '', 'acme' ) ],
839 ];
840 }
841
842 public static function provideGetSubjectPage_good() {
843 return [
844 [ Title::makeTitle( NS_TALK, 'Test' ), Title::makeTitle( NS_MAIN, 'Test' ) ],
845 [ Title::makeTitle( NS_MAIN, 'Test' ), Title::makeTitle( NS_MAIN, 'Test' ) ],
846 ];
847 }
848
849 public static function provideGetOtherPage_good() {
850 return [
851 [ Title::makeTitle( NS_MAIN, 'Test' ), Title::makeTitle( NS_TALK, 'Test' ) ],
852 [ Title::makeTitle( NS_TALK, 'Test' ), Title::makeTitle( NS_MAIN, 'Test' ) ],
853 ];
854 }
855
856 /**
857 * @dataProvider provideCanHaveTalkPage
858 * @covers Title::canHaveTalkPage
859 *
860 * @param Title $title
861 * @param bool $expected
862 */
863 public function testCanHaveTalkPage( Title $title, $expected ) {
864 $actual = $title->canHaveTalkPage();
865 $this->assertSame( $expected, $actual, $title->getPrefixedDBkey() );
866 }
867
868 /**
869 * @dataProvider provideIsWatchable
870 * @covers Title::isWatchable
871 *
872 * @param Title $title
873 * @param bool $expected
874 */
875 public function testIsWatchable( Title $title, $expected ) {
876 $actual = $title->canHaveTalkPage();
877 $this->assertSame( $expected, $actual, $title->getPrefixedDBkey() );
878 }
879
880 /**
881 * @dataProvider provideGetTalkPage_good
882 * @covers Title::getTalkPageIfDefined
883 */
884 public function testGetTalkPage_good( Title $title, Title $expected ) {
885 $actual = $title->getTalkPage();
886 $this->assertTrue( $expected->equals( $actual ), $title->getPrefixedDBkey() );
887 }
888
889 /**
890 * @dataProvider provideGetTalkPage_bad
891 * @covers Title::getTalkPageIfDefined
892 */
893 public function testGetTalkPage_bad( Title $title ) {
894 $this->setExpectedException( MWException::class );
895 $title->getTalkPage();
896 }
897
898 /**
899 * @dataProvider provideGetTalkPage_good
900 * @covers Title::getTalkPageIfDefined
901 */
902 public function testGetTalkPageIfDefined_good( Title $title, Title $expected ) {
903 $actual = $title->getTalkPageIfDefined();
904 $this->assertNotNull( $actual, $title->getPrefixedDBkey() );
905 $this->assertTrue( $expected->equals( $actual ), $title->getPrefixedDBkey() );
906 }
907
908 /**
909 * @dataProvider provideGetTalkPage_bad
910 * @covers Title::getTalkPageIfDefined
911 */
912 public function testGetTalkPageIfDefined_bad( Title $title ) {
913 $talk = $title->getTalkPageIfDefined();
914 $this->assertNull(
915 $talk,
916 $title->getPrefixedDBkey()
917 );
918 }
919
920 /**
921 * @dataProvider provideGetSubjectPage_good
922 * @covers Title::getSubjectPage
923 */
924 public function testGetSubjectPage_good( Title $title, Title $expected ) {
925 $actual = $title->getSubjectPage();
926 $this->assertTrue( $expected->equals( $actual ), $title->getPrefixedDBkey() );
927 }
928
929 /**
930 * @dataProvider provideGetOtherPage_good
931 * @covers Title::getOtherPage
932 */
933 public function testGetOtherPage_good( Title $title, Title $expected ) {
934 $actual = $title->getOtherPage();
935 $this->assertTrue( $expected->equals( $actual ), $title->getPrefixedDBkey() );
936 }
937
938 /**
939 * @dataProvider provideGetTalkPage_bad
940 * @covers Title::getOtherPage
941 */
942 public function testGetOtherPage_bad( Title $title ) {
943 $this->setExpectedException( MWException::class );
944 $title->getOtherPage();
945 }
946
947 /**
948 * @dataProvider provideIsMovable
949 * @covers Title::isMovable
950 *
951 * @param string|Title $title
952 * @param bool $expected
953 * @param callable|null $hookCallback For TitleIsMovable
954 */
955 public function testIsMovable( $title, $expected, $hookCallback = null ) {
956 if ( $hookCallback ) {
957 $this->setTemporaryHook( 'TitleIsMovable', $hookCallback );
958 }
959 if ( is_string( $title ) ) {
960 $title = Title::newFromText( $title );
961 }
962
963 $this->assertSame( $expected, $title->isMovable() );
964 }
965
966 public static function provideIsMovable() {
967 return [
968 'Simple title' => [ 'Foo', true ],
969 // @todo Should these next two really be true?
970 'Empty name' => [ Title::makeTitle( NS_MAIN, '' ), true ],
971 'Invalid name' => [ Title::makeTitle( NS_MAIN, '<' ), true ],
972 'Interwiki' => [ Title::makeTitle( NS_MAIN, 'Test', '', 'otherwiki' ), false ],
973 'Special page' => [ 'Special:FooBar', false ],
974 'Aborted by hook' => [ 'Hooked in place', false,
975 function ( Title $title, &$result ) {
976 $result = false;
977 }
978 ],
979 ];
980 }
981
982 public function provideCreateFragmentTitle() {
983 return [
984 [ Title::makeTitle( NS_MAIN, 'Test' ), 'foo' ],
985 [ Title::makeTitle( NS_TALK, 'Test', 'foo' ), '' ],
986 [ Title::makeTitle( NS_CATEGORY, 'Test', 'foo' ), 'bar' ],
987 [ Title::makeTitle( NS_MAIN, 'Test1', '', 'interwiki' ), 'baz' ]
988 ];
989 }
990
991 /**
992 * @covers Title::createFragmentTarget
993 * @dataProvider provideCreateFragmentTitle
994 */
995 public function testCreateFragmentTitle( Title $title, $fragment ) {
996 $this->mergeMwGlobalArrayValue( 'wgHooks', [
997 'InterwikiLoadPrefix' => [
998 function ( $prefix, &$iwdata ) {
999 if ( $prefix === 'interwiki' ) {
1000 $iwdata = [
1001 'iw_url' => 'http://example.com/',
1002 'iw_local' => 0,
1003 'iw_trans' => 0,
1004 ];
1005 return false;
1006 }
1007 },
1008 ],
1009 ] );
1010
1011 $fragmentTitle = $title->createFragmentTarget( $fragment );
1012
1013 $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
1014 $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
1015 $this->assertEquals( $title->getInterwiki(), $fragmentTitle->getInterwiki() );
1016 $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
1017 }
1018
1019 public function provideGetPrefixedText() {
1020 return [
1021 // ns = 0
1022 [
1023 Title::makeTitle( NS_MAIN, 'Foo bar' ),
1024 'Foo bar'
1025 ],
1026 // ns = 2
1027 [
1028 Title::makeTitle( NS_USER, 'Foo bar' ),
1029 'User:Foo bar'
1030 ],
1031 // ns = 3
1032 [
1033 Title::makeTitle( NS_USER_TALK, 'Foo bar' ),
1034 'User talk:Foo bar'
1035 ],
1036 // fragment not included
1037 [
1038 Title::makeTitle( NS_MAIN, 'Foo bar', 'fragment' ),
1039 'Foo bar'
1040 ],
1041 // ns = -2
1042 [
1043 Title::makeTitle( NS_MEDIA, 'Foo bar' ),
1044 'Media:Foo bar'
1045 ],
1046 // non-existent namespace
1047 [
1048 Title::makeTitle( 100777, 'Foo bar' ),
1049 'Special:Badtitle/NS100777:Foo bar'
1050 ],
1051 ];
1052 }
1053
1054 /**
1055 * @covers Title::getPrefixedText
1056 * @dataProvider provideGetPrefixedText
1057 */
1058 public function testGetPrefixedText( Title $title, $expected ) {
1059 $this->assertEquals( $expected, $title->getPrefixedText() );
1060 }
1061
1062 public function provideGetPrefixedDBKey() {
1063 return [
1064 // ns = 0
1065 [
1066 Title::makeTitle( NS_MAIN, 'Foo_bar' ),
1067 'Foo_bar'
1068 ],
1069 // ns = 2
1070 [
1071 Title::makeTitle( NS_USER, 'Foo_bar' ),
1072 'User:Foo_bar'
1073 ],
1074 // ns = 3
1075 [
1076 Title::makeTitle( NS_USER_TALK, 'Foo_bar' ),
1077 'User_talk:Foo_bar'
1078 ],
1079 // fragment not included
1080 [
1081 Title::makeTitle( NS_MAIN, 'Foo_bar', 'fragment' ),
1082 'Foo_bar'
1083 ],
1084 // ns = -2
1085 [
1086 Title::makeTitle( NS_MEDIA, 'Foo_bar' ),
1087 'Media:Foo_bar'
1088 ],
1089 // non-existent namespace
1090 [
1091 Title::makeTitle( 100777, 'Foo_bar' ),
1092 'Special:Badtitle/NS100777:Foo_bar'
1093 ],
1094 ];
1095 }
1096
1097 /**
1098 * @covers Title::getPrefixedDBKey
1099 * @dataProvider provideGetPrefixedDBKey
1100 */
1101 public function testGetPrefixedDBKey( Title $title, $expected ) {
1102 $this->assertEquals( $expected, $title->getPrefixedDBkey() );
1103 }
1104
1105 /**
1106 * @covers Title::getFragmentForURL
1107 * @dataProvider provideGetFragmentForURL
1108 *
1109 * @param string $titleStr
1110 * @param string $expected
1111 */
1112 public function testGetFragmentForURL( $titleStr, $expected ) {
1113 $this->setMwGlobals( [
1114 'wgFragmentMode' => [ 'html5' ],
1115 'wgExternalInterwikiFragmentMode' => 'legacy',
1116 ] );
1117 $dbw = wfGetDB( DB_MASTER );
1118 $dbw->insert( 'interwiki',
1119 [
1120 [
1121 'iw_prefix' => 'de',
1122 'iw_url' => 'http://de.wikipedia.org/wiki/',
1123 'iw_api' => 'http://de.wikipedia.org/w/api.php',
1124 'iw_wikiid' => 'dewiki',
1125 'iw_local' => 1,
1126 'iw_trans' => 0,
1127 ],
1128 [
1129 'iw_prefix' => 'zz',
1130 'iw_url' => 'http://zzwiki.org/wiki/',
1131 'iw_api' => 'http://zzwiki.org/w/api.php',
1132 'iw_wikiid' => 'zzwiki',
1133 'iw_local' => 0,
1134 'iw_trans' => 0,
1135 ],
1136 ],
1137 __METHOD__,
1138 [ 'IGNORE' ]
1139 );
1140
1141 $title = Title::newFromText( $titleStr );
1142 self::assertEquals( $expected, $title->getFragmentForURL() );
1143
1144 $dbw->delete( 'interwiki', '*', __METHOD__ );
1145 }
1146
1147 public function provideGetFragmentForURL() {
1148 return [
1149 [ 'Foo', '' ],
1150 [ 'Foo#ümlåût', '#ümlåût' ],
1151 [ 'de:Foo#Bå®', '#Bå®' ],
1152 [ 'zz:Foo#тест', '#.D1.82.D0.B5.D1.81.D1.82' ],
1153 ];
1154 }
1155
1156 /**
1157 * @covers Title::isRawHtmlMessage
1158 * @dataProvider provideIsRawHtmlMessage
1159 */
1160 public function testIsRawHtmlMessage( $textForm, $expected ) {
1161 $this->setMwGlobals( 'wgRawHtmlMessages', [
1162 'foobar',
1163 'foo_bar',
1164 'foo-bar',
1165 ] );
1166
1167 $title = Title::newFromText( $textForm );
1168 $this->assertSame( $expected, $title->isRawHtmlMessage() );
1169 }
1170
1171 public function provideIsRawHtmlMessage() {
1172 return [
1173 [ 'MediaWiki:Foobar', true ],
1174 [ 'MediaWiki:Foo bar', true ],
1175 [ 'MediaWiki:Foo-bar', true ],
1176 [ 'MediaWiki:foo bar', true ],
1177 [ 'MediaWiki:foo-bar', true ],
1178 [ 'MediaWiki:foobar', true ],
1179 [ 'MediaWiki:some-other-message', false ],
1180 [ 'Main Page', false ],
1181 ];
1182 }
1183
1184 public function provideEquals() {
1185 yield [
1186 Title::newFromText( 'Main Page' ),
1187 Title::newFromText( 'Main Page' ),
1188 true
1189 ];
1190 yield [
1191 Title::newFromText( 'Main Page' ),
1192 Title::newFromText( 'Not The Main Page' ),
1193 false
1194 ];
1195 yield [
1196 Title::newFromText( 'Main Page' ),
1197 Title::newFromText( 'Project:Main Page' ),
1198 false
1199 ];
1200 yield [
1201 Title::newFromText( 'File:Example.png' ),
1202 Title::newFromText( 'Image:Example.png' ),
1203 true
1204 ];
1205 yield [
1206 Title::newFromText( 'Special:Version' ),
1207 Title::newFromText( 'Special:Version' ),
1208 true
1209 ];
1210 yield [
1211 Title::newFromText( 'Special:Version' ),
1212 Title::newFromText( 'Special:Recentchanges' ),
1213 false
1214 ];
1215 yield [
1216 Title::newFromText( 'Special:Version' ),
1217 Title::newFromText( 'Main Page' ),
1218 false
1219 ];
1220 yield [
1221 Title::makeTitle( NS_MAIN, 'Foo', '', '' ),
1222 Title::makeTitle( NS_MAIN, 'Foo', '', '' ),
1223 true
1224 ];
1225 yield [
1226 Title::makeTitle( NS_MAIN, 'Foo', '', '' ),
1227 Title::makeTitle( NS_MAIN, 'Bar', '', '' ),
1228 false
1229 ];
1230 yield [
1231 Title::makeTitle( NS_MAIN, 'Foo', '', '' ),
1232 Title::makeTitle( NS_TALK, 'Foo', '', '' ),
1233 false
1234 ];
1235 yield [
1236 Title::makeTitle( NS_MAIN, 'Foo', 'Bar', '' ),
1237 Title::makeTitle( NS_MAIN, 'Foo', 'Bar', '' ),
1238 true
1239 ];
1240 yield [
1241 Title::makeTitle( NS_MAIN, 'Foo', 'Bar', '' ),
1242 Title::makeTitle( NS_MAIN, 'Foo', 'Baz', '' ),
1243 true
1244 ];
1245 yield [
1246 Title::makeTitle( NS_MAIN, 'Foo', 'Bar', '' ),
1247 Title::makeTitle( NS_MAIN, 'Foo', '', '' ),
1248 true
1249 ];
1250 yield [
1251 Title::makeTitle( NS_MAIN, 'Foo', '', 'baz' ),
1252 Title::makeTitle( NS_MAIN, 'Foo', '', 'baz' ),
1253 true
1254 ];
1255 yield [
1256 Title::makeTitle( NS_MAIN, 'Foo', '', '' ),
1257 Title::makeTitle( NS_MAIN, 'Foo', '', 'baz' ),
1258 false
1259 ];
1260 }
1261
1262 /**
1263 * @covers Title::equals
1264 * @dataProvider provideEquals
1265 */
1266 public function testEquals( Title $firstValue, /* LinkTarget */ $secondValue, $expectedSame ) {
1267 $this->assertSame(
1268 $expectedSame,
1269 $firstValue->equals( $secondValue )
1270 );
1271 }
1272
1273 /**
1274 * @covers Title::newMainPage
1275 */
1276 public function testNewMainPage() {
1277 $mock = $this->createMock( MessageCache::class );
1278 $mock->method( 'get' )->willReturn( 'Foresheet' );
1279 $mock->method( 'transform' )->willReturn( 'Foresheet' );
1280
1281 $this->setService( 'MessageCache', $mock );
1282
1283 $this->assertSame(
1284 'Foresheet',
1285 Title::newMainPage()->getText()
1286 );
1287 }
1288
1289 /**
1290 * @covers Title::newMainPage
1291 */
1292 public function testNewMainPageWithLocal() {
1293 $local = $this->createMock( MessageLocalizer::class );
1294 $local->method( 'msg' )->willReturn( new RawMessage( 'Prime Article' ) );
1295
1296 $this->assertSame(
1297 'Prime Article',
1298 Title::newMainPage( $local )->getText()
1299 );
1300 }
1301 }