File: NamespaceInfoTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (1226 lines) | stat: -rw-r--r-- 36,564 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
<?php
/**
 * @author Antoine Musso
 * @copyright Copyright © 2011, Antoine Musso
 * @file
 */

use MediaWiki\Config\ServiceOptions;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MainConfigNames;
use MediaWiki\Title\NamespaceInfo;
use MediaWiki\Title\Title;
use MediaWiki\Title\TitleValue;

class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
	use TestAllServiceOptionsUsed;

	private const TEST_EXT_NAMESPACES = [ NS_MAIN => 'No effect', NS_TALK => 'No effect', 12345 => 'Extended' ];

	/**********************************************************************************************
	 * Shared code
	 * %{
	 */

	private const DEFAULT_OPTIONS = [
		MainConfigNames::CanonicalNamespaceNames => [
			NS_TALK => 'Talk',
			NS_USER => 'User',
			NS_USER_TALK => 'User_talk',
			NS_SPECIAL => 'Special',
			NS_MEDIA => 'Media',
		],
		MainConfigNames::CapitalLinkOverrides => [],
		MainConfigNames::CapitalLinks => true,
		MainConfigNames::ContentNamespaces => [ NS_MAIN ],
		MainConfigNames::ExtraNamespaces => [],
		MainConfigNames::ExtraSignatureNamespaces => [],
		MainConfigNames::NamespaceContentModels => [],
		MainConfigNames::NamespacesWithSubpages => [
			NS_TALK => true,
			NS_USER => true,
			NS_USER_TALK => true,
		],
		MainConfigNames::NonincludableNamespaces => [],
	];

	/**
	 * @return HookContainer
	 */
	private function getHookContainer() {
		return $this->getServiceContainer()->getHookContainer();
	}

	private function newObj( array $options = [], array $extensionNamespaces = [] ): NamespaceInfo {
		return new NamespaceInfo(
			new LoggedServiceOptions(
				self::$serviceOptionsAccessLog,
				NamespaceInfo::CONSTRUCTOR_OPTIONS,
				$options, self::DEFAULT_OPTIONS
			),
			$this->getHookContainer(),
			$extensionNamespaces,
			[]
		);
	}

	// %} End shared code

	/**********************************************************************************************
	 * Basic methods
	 * %{
	 */

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::__construct
	 * @dataProvider provideConstructor
	 * @param ServiceOptions $options
	 * @param string|null $expectedExceptionText
	 */
	public function testConstructor( ServiceOptions $options, $expectedExceptionText = null ) {
		if ( $expectedExceptionText !== null ) {
			$this->expectException( \Wikimedia\Assert\PreconditionException::class );
			$this->expectExceptionMessage( $expectedExceptionText );
		}
		new NamespaceInfo( $options, $this->getHookContainer(), [], [] );
		$this->assertTrue( true );
	}

	public static function provideConstructor() {
		return [
			[ new ServiceOptions( NamespaceInfo::CONSTRUCTOR_OPTIONS, self::DEFAULT_OPTIONS ) ],
			[ new ServiceOptions( [], [] ), 'Required options missing: ' ],
			[ new ServiceOptions(
				array_merge( NamespaceInfo::CONSTRUCTOR_OPTIONS, [ 'invalid' ] ),
				self::DEFAULT_OPTIONS,
				[ 'invalid' => '' ]
			), 'Unsupported options passed: invalid' ],
		];
	}

	/**
	 * @dataProvider provideIsMovable
	 * @covers \MediaWiki\Title\NamespaceInfo::isMovable
	 *
	 * @param bool $expected
	 * @param int $ns
	 */
	public function testIsMovable( $expected, $ns ) {
		$obj = $this->newObj();
		$this->assertSame( $expected, $obj->isMovable( $ns ) );
	}

	public static function provideIsMovable() {
		return [
			'Main' => [ true, NS_MAIN ],
			'Talk' => [ true, NS_TALK ],
			'Special' => [ false, NS_SPECIAL ],
			'Nonexistent even namespace' => [ true, 1234 ],
			'Nonexistent odd namespace' => [ true, 12345 ],

			'Media' => [ false, NS_MEDIA ],
			'File' => [ true, NS_FILE ],
		];
	}

	/**
	 * @param int $ns
	 * @param bool $expected
	 * @dataProvider provideIsSubject
	 * @covers \MediaWiki\Title\NamespaceInfo::isSubject
	 */
	public function testIsSubject( $ns, $expected ) {
		$this->assertSame( $expected, $this->newObj()->isSubject( $ns ) );
	}

	/**
	 * @param int $ns
	 * @param bool $expected
	 * @dataProvider provideIsSubject
	 * @covers \MediaWiki\Title\NamespaceInfo::isTalk
	 */
	public function testIsTalk( $ns, $expected ) {
		$this->assertSame( !$expected, $this->newObj()->isTalk( $ns ) );
	}

	public static function provideIsSubject() {
		return [
			// Special namespaces
			[ NS_MEDIA, true ],
			[ NS_SPECIAL, true ],

			// Subject pages
			[ NS_MAIN, true ],
			[ NS_USER, true ],
			[ 100, true ],

			// Talk pages
			[ NS_TALK, false ],
			[ NS_USER_TALK, false ],
			[ 101, false ],
		];
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::exists
	 * @dataProvider provideExists
	 * @param int $ns
	 * @param bool $expected
	 */
	public function testExists( $ns, $expected ) {
		$this->assertSame( $expected, $this->newObj()->exists( $ns ) );
	}

	public static function provideExists() {
		return [
			'Main' => [ NS_MAIN, true ],
			'Talk' => [ NS_TALK, true ],
			'Media' => [ NS_MEDIA, true ],
			'Special' => [ NS_SPECIAL, true ],
			'Nonexistent' => [ 12345, false ],
			'Negative nonexistent' => [ -12345, false ],
		];
	}

	/**
	 * Note if we add a namespace registration system with keys like 'MAIN'
	 * we should add tests here for equivalence on things like 'MAIN' == 0
	 * and 'MAIN' == NS_MAIN.
	 * @covers \MediaWiki\Title\NamespaceInfo::equals
	 */
	public function testEquals() {
		$obj = $this->newObj();
		$this->assertTrue( $obj->equals( NS_MAIN, NS_MAIN ) );
		$this->assertTrue( $obj->equals( NS_MAIN, 0 ) ); // In case we make NS_MAIN 'MAIN'
		$this->assertTrue( $obj->equals( NS_USER, NS_USER ) );
		$this->assertTrue( $obj->equals( NS_USER, 2 ) );
		$this->assertTrue( $obj->equals( NS_USER_TALK, NS_USER_TALK ) );
		$this->assertTrue( $obj->equals( NS_SPECIAL, NS_SPECIAL ) );
		$this->assertFalse( $obj->equals( NS_MAIN, NS_TALK ) );
		$this->assertFalse( $obj->equals( NS_USER, NS_USER_TALK ) );
		$this->assertFalse( $obj->equals( NS_PROJECT, NS_TEMPLATE ) );
	}

	/**
	 * @param int $ns1
	 * @param int $ns2
	 * @param bool $expected
	 * @dataProvider provideSubjectEquals
	 * @covers \MediaWiki\Title\NamespaceInfo::subjectEquals
	 */
	public function testSubjectEquals( $ns1, $ns2, $expected ) {
		$this->assertSame( $expected, $this->newObj()->subjectEquals( $ns1, $ns2 ) );
	}

	public static function provideSubjectEquals() {
		return [
			[ NS_MAIN, NS_MAIN, true ],
			// In case we make NS_MAIN 'MAIN'
			[ NS_MAIN, 0, true ],
			[ NS_USER, NS_USER, true ],
			[ NS_USER, 2, true ],
			[ NS_USER_TALK, NS_USER_TALK, true ],
			[ NS_SPECIAL, NS_SPECIAL, true ],
			[ NS_MAIN, NS_TALK, true ],
			[ NS_USER, NS_USER_TALK, true ],

			[ NS_PROJECT, NS_TEMPLATE, false ],
			[ NS_SPECIAL, NS_MAIN, false ],
			[ NS_MEDIA, NS_SPECIAL, false ],
			[ NS_SPECIAL, NS_MEDIA, false ],
		];
	}

	/**
	 * @dataProvider provideHasTalkNamespace
	 * @covers \MediaWiki\Title\NamespaceInfo::hasTalkNamespace
	 *
	 * @param int $ns
	 * @param bool $expected
	 */
	public function testHasTalkNamespace( $ns, $expected ) {
		$this->assertSame( $expected, $this->newObj()->hasTalkNamespace( $ns ) );
	}

	public static function provideHasTalkNamespace() {
		return [
			[ NS_MEDIA, false ],
			[ NS_SPECIAL, false ],

			[ NS_MAIN, true ],
			[ NS_TALK, true ],
			[ NS_USER, true ],
			[ NS_USER_TALK, true ],

			[ 100, true ],
			[ 101, true ],
		];
	}

	/**
	 * @param int $ns
	 * @param bool $expected
	 * @param array $contentNamespaces
	 * @covers \MediaWiki\Title\NamespaceInfo::isContent
	 * @dataProvider provideIsContent
	 */
	public function testIsContent( $ns, $expected, $contentNamespaces = [ NS_MAIN ] ) {
		$obj = $this->newObj( [ MainConfigNames::ContentNamespaces => $contentNamespaces ] );
		$this->assertSame( $expected, $obj->isContent( $ns ) );
	}

	public static function provideIsContent() {
		return [
			[ NS_MAIN, true ],
			[ NS_MEDIA, false ],
			[ NS_SPECIAL, false ],
			[ NS_TALK, false ],
			[ NS_USER, false ],
			[ NS_CATEGORY, false ],
			[ 100, false ],
			[ 100, true, [ NS_MAIN, 100, 252 ] ],
			[ 252, true, [ NS_MAIN, 100, 252 ] ],
			[ NS_MAIN, true, [ NS_MAIN, 100, 252 ] ],
			// NS_MAIN is always content
			[ NS_MAIN, true, [] ],
		];
	}

	/**
	 * @dataProvider provideWantSignatures
	 * @covers \MediaWiki\Title\NamespaceInfo::wantSignatures
	 *
	 * @param int $index
	 * @param bool $expected
	 */
	public function testWantSignatures( $index, $expected ) {
		$this->assertSame( $expected, $this->newObj()->wantSignatures( $index ) );
	}

	public static function provideWantSignatures() {
		return [
			'Main' => [ NS_MAIN, false ],
			'Talk' => [ NS_TALK, true ],
			'User' => [ NS_USER, false ],
			'User talk' => [ NS_USER_TALK, true ],
			'Special' => [ NS_SPECIAL, false ],
			'Media' => [ NS_MEDIA, false ],
			'Nonexistent talk' => [ 12345, true ],
			'Nonexistent subject' => [ 123456, false ],
			'Nonexistent negative odd' => [ -12345, false ],
		];
	}

	/**
	 * @dataProvider provideWantSignatures_ExtraSignatureNamespaces
	 * @covers \MediaWiki\Title\NamespaceInfo::wantSignatures
	 *
	 * @param int $index
	 * @param int $expected
	 */
	public function testWantSignatures_ExtraSignatureNamespaces( $index, $expected ) {
		$obj = $this->newObj( [ MainConfigNames::ExtraSignatureNamespaces =>
			[ NS_MAIN, NS_USER, NS_SPECIAL, NS_MEDIA, 123456, -12345 ] ] );
		$this->assertSame( $expected, $obj->wantSignatures( $index ) );
	}

	public function provideWantSignatures_ExtraSignatureNamespaces() {
		$ret = array_map(
			static function ( $arr ) {
				// We've added all these as extra signature namespaces, so expect true
				return [ $arr[0], true ];
			},
			$this->provideWantSignatures()
		);

		// Add one more that's false
		$ret['Another nonexistent subject'] = [ 12345678, false ];
		return $ret;
	}

	/**
	 * @param int $ns
	 * @param bool $expected
	 * @covers \MediaWiki\Title\NamespaceInfo::isWatchable
	 * @dataProvider provideIsWatchable
	 */
	public function testIsWatchable( $ns, $expected ) {
		$this->assertSame( $expected, $this->newObj()->isWatchable( $ns ) );
	}

	public static function provideIsWatchable() {
		return [
			// Specials namespaces are not watchable
			[ NS_MEDIA, false ],
			[ NS_SPECIAL, false ],

			// Core defined namespaces are watchables
			[ NS_MAIN, true ],
			[ NS_TALK, true ],

			// Additional, user defined namespaces are watchables
			[ 100, true ],
			[ 101, true ],
		];
	}

	/**
	 * @param int $ns
	 * @param int $expected
	 * @param array|null $namespacesWithSubpages To pass to constructor
	 * @covers \MediaWiki\Title\NamespaceInfo::hasSubpages
	 * @dataProvider provideHasSubpages
	 */
	public function testHasSubpages( $ns, $expected, ?array $namespacesWithSubpages = null ) {
		$obj = $this->newObj( $namespacesWithSubpages
			? [ MainConfigNames::NamespacesWithSubpages => $namespacesWithSubpages ]
			: [] );
		$this->assertSame( $expected, $obj->hasSubpages( $ns ) );
	}

	public static function provideHasSubpages() {
		return [
			// Special namespaces:
			[ NS_MEDIA, false ],
			[ NS_SPECIAL, false ],

			// Namespaces without subpages
			[ NS_MAIN, false ],
			[ NS_MAIN, true, [ NS_MAIN => true ] ],
			[ NS_MAIN, false, [ NS_MAIN => false ] ],

			// Some namespaces with subpages
			[ NS_TALK, true ],
			[ NS_USER, true ],
			[ NS_USER_TALK, true ],
		];
	}

	/**
	 * @dataProvider provideGetContentNamespaces
	 * @covers \MediaWiki\Title\NamespaceInfo::getContentNamespaces
	 */
	public function testGetContentNamespaces( $contentNamespaces, array $expected ) {
		$obj = $this->newObj( [ MainConfigNames::ContentNamespaces => $contentNamespaces ] );
		$this->assertSame( $expected, $obj->getContentNamespaces() );
	}

	public static function provideGetContentNamespaces() {
		return [
			// Non-array
			[ '', [ NS_MAIN ] ],
			[ false, [ NS_MAIN ] ],
			[ null, [ NS_MAIN ] ],
			[ 5, [ NS_MAIN ] ],

			// Empty array
			[ [], [ NS_MAIN ] ],

			// NS_MAIN is forced to be content even if unwanted
			[ [ NS_USER, NS_CATEGORY ], [ NS_MAIN, NS_USER, NS_CATEGORY ] ],

			// In other cases, return as-is
			[ [ NS_MAIN ], [ NS_MAIN ] ],
			[ [ NS_MAIN, NS_USER, NS_CATEGORY ], [ NS_MAIN, NS_USER, NS_CATEGORY ] ],
		];
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getSubjectNamespaces
	 */
	public function testGetSubjectNamespaces() {
		$subjectsNS = $this->newObj()->getSubjectNamespaces();
		$this->assertContains( NS_MAIN, $subjectsNS,
			"Talk namespaces should have NS_MAIN" );
		$this->assertNotContains( NS_TALK, $subjectsNS,
			"Talk namespaces should have NS_TALK" );

		$this->assertNotContains( NS_MEDIA, $subjectsNS,
			"Talk namespaces should not have NS_MEDIA" );
		$this->assertNotContains( NS_SPECIAL, $subjectsNS,
			"Talk namespaces should not have NS_SPECIAL" );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getTalkNamespaces
	 */
	public function testGetTalkNamespaces() {
		$talkNS = $this->newObj()->getTalkNamespaces();
		$this->assertContains( NS_TALK, $talkNS,
			"Subject namespaces should have NS_TALK" );
		$this->assertNotContains( NS_MAIN, $talkNS,
			"Subject namespaces should not have NS_MAIN" );

		$this->assertNotContains( NS_MEDIA, $talkNS,
			"Subject namespaces should not have NS_MEDIA" );
		$this->assertNotContains( NS_SPECIAL, $talkNS,
			"Subject namespaces should not have NS_SPECIAL" );
	}

	/**
	 * @param int $ns
	 * @param bool $expected
	 * @param bool $capitalLinks To pass to constructor
	 * @param array $capitalLinkOverrides To pass to constructor
	 * @dataProvider provideIsCapitalized
	 * @covers \MediaWiki\Title\NamespaceInfo::isCapitalized
	 */
	public function testIsCapitalized(
		$ns, $expected, $capitalLinks = true, array $capitalLinkOverrides = []
	) {
		$obj = $this->newObj( [
			MainConfigNames::CapitalLinks => $capitalLinks,
			MainConfigNames::CapitalLinkOverrides => $capitalLinkOverrides,
		] );
		$this->assertSame( $expected, $obj->isCapitalized( $ns ) );
	}

	public static function provideIsCapitalized() {
		return [
			// Test default settings
			[ NS_PROJECT, true ],
			[ NS_PROJECT_TALK, true ],
			[ NS_MEDIA, true ],
			[ NS_FILE, true ],

			// Always capitalized no matter what
			[ NS_SPECIAL, true, false ],
			[ NS_USER, true, false ],
			[ NS_MEDIAWIKI, true, false ],

			// Even with an override too
			[ NS_SPECIAL, true, false, [ NS_SPECIAL => false ] ],
			[ NS_USER, true, false, [ NS_USER => false ] ],
			[ NS_MEDIAWIKI, true, false, [ NS_MEDIAWIKI => false ] ],

			// Overrides work for other namespaces
			[ NS_PROJECT, false, true, [ NS_PROJECT => false ] ],
			[ NS_PROJECT, true, false, [ NS_PROJECT => true ] ],

			// NS_MEDIA is treated like NS_FILE, and ignores NS_MEDIA overrides
			[ NS_MEDIA, false, true, [ NS_FILE => false, NS_MEDIA => true ] ],
			[ NS_MEDIA, true, false, [ NS_FILE => true, NS_MEDIA => false ] ],
			[ NS_FILE, false, true, [ NS_FILE => false, NS_MEDIA => true ] ],
			[ NS_FILE, true, false, [ NS_FILE => true, NS_MEDIA => false ] ],
		];
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::hasGenderDistinction
	 */
	public function testHasGenderDistinction() {
		$obj = $this->newObj();

		// Namespaces with gender distinctions
		$this->assertTrue( $obj->hasGenderDistinction( NS_USER ) );
		$this->assertTrue( $obj->hasGenderDistinction( NS_USER_TALK ) );

		// Other ones, "genderless"
		$this->assertFalse( $obj->hasGenderDistinction( NS_MEDIA ) );
		$this->assertFalse( $obj->hasGenderDistinction( NS_SPECIAL ) );
		$this->assertFalse( $obj->hasGenderDistinction( NS_MAIN ) );
		$this->assertFalse( $obj->hasGenderDistinction( NS_TALK ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::isNonincludable
	 */
	public function testIsNonincludable() {
		$obj = $this->newObj( [ MainConfigNames::NonincludableNamespaces => [ NS_USER ] ] );
		$this->assertTrue( $obj->isNonincludable( NS_USER ) );
		$this->assertFalse( $obj->isNonincludable( NS_TEMPLATE ) );
	}

	/**
	 * @dataProvider provideGetNamespaceContentModel
	 * @covers \MediaWiki\Title\NamespaceInfo::getNamespaceContentModel
	 *
	 * @param int $ns
	 * @param string $expected
	 */
	public function testGetNamespaceContentModel( $ns, $expected ) {
		$obj = $this->newObj( [ MainConfigNames::NamespaceContentModels =>
			[ NS_USER => CONTENT_MODEL_WIKITEXT, 123 => CONTENT_MODEL_JSON, 1234 => 'abcdef' ],
		] );
		$this->assertSame( $expected, $obj->getNamespaceContentModel( $ns ) );
	}

	public static function provideGetNamespaceContentModel() {
		return [
			[ NS_MAIN, null ],
			[ NS_TALK, null ],
			[ NS_USER, CONTENT_MODEL_WIKITEXT ],
			[ NS_USER_TALK, null ],
			[ NS_SPECIAL, null ],
			[ 122, null ],
			[ 123, CONTENT_MODEL_JSON ],
			[ 1234, 'abcdef' ],
			[ 1235, null ],
		];
	}

	/**
	 * @dataProvider provideGetCategoryLinkType
	 * @covers \MediaWiki\Title\NamespaceInfo::getCategoryLinkType
	 *
	 * @param int $ns
	 * @param string $expected
	 */
	public function testGetCategoryLinkType( $ns, $expected ) {
		$this->assertSame( $expected, $this->newObj()->getCategoryLinkType( $ns ) );
	}

	public static function provideGetCategoryLinkType() {
		return [
			[ NS_MAIN, 'page' ],
			[ NS_TALK, 'page' ],
			[ NS_USER, 'page' ],
			[ NS_USER_TALK, 'page' ],

			[ NS_FILE, 'file' ],
			[ NS_FILE_TALK, 'page' ],

			[ NS_CATEGORY, 'subcat' ],
			[ NS_CATEGORY_TALK, 'page' ],

			[ 100, 'page' ],
			[ 101, 'page' ],
		];
	}

	// %} End basic methods

	/**********************************************************************************************
	 * getSubject/Talk/Associated
	 * %{
	 */

	/**
	 * @dataProvider provideSubjectTalk
	 * @covers \MediaWiki\Title\NamespaceInfo::getSubject
	 * @covers \MediaWiki\Title\NamespaceInfo::getSubjectPage
	 * @covers \MediaWiki\Title\NamespaceInfo::isMethodValidFor
	 * @covers \MediaWiki\Title\Title::getSubjectPage
	 *
	 * @param int $subject
	 * @param int $talk
	 */
	public function testGetSubject( $subject, $talk ) {
		$obj = $this->newObj();
		$this->assertSame( $subject, $obj->getSubject( $subject ) );
		$this->assertSame( $subject, $obj->getSubject( $talk ) );

		$subjectTitleVal = new TitleValue( $subject, 'A' );
		$talkTitleVal = new TitleValue( $talk, 'A' );
		// Object will be the same one passed in if it's a subject, different but equal object if
		// it's talk
		$this->assertSame( $subjectTitleVal, $obj->getSubjectPage( $subjectTitleVal ) );
		$this->assertEquals( $subjectTitleVal, $obj->getSubjectPage( $talkTitleVal ) );

		$subjectTitle = Title::makeTitle( $subject, 'A' );
		$talkTitle = Title::makeTitle( $talk, 'A' );
		$this->assertSame( $subjectTitle, $subjectTitle->getSubjectPage() );
		$this->assertEquals( $subjectTitle, $talkTitle->getSubjectPage() );
	}

	/**
	 * @dataProvider provideSpecialNamespaces
	 * @covers \MediaWiki\Title\NamespaceInfo::getSubject
	 * @covers \MediaWiki\Title\NamespaceInfo::getSubjectPage
	 *
	 * @param int $ns
	 */
	public function testGetSubject_special( $ns ) {
		$obj = $this->newObj();
		$this->assertSame( $ns, $obj->getSubject( $ns ) );

		$title = new TitleValue( $ns, 'A' );
		$this->assertSame( $title, $obj->getSubjectPage( $title ) );
	}

	/**
	 * @dataProvider provideSubjectTalk
	 * @covers \MediaWiki\Title\NamespaceInfo::getTalk
	 * @covers \MediaWiki\Title\NamespaceInfo::getTalkPage
	 * @covers \MediaWiki\Title\NamespaceInfo::isMethodValidFor
	 * @covers \MediaWiki\Title\Title::getTalkPage
	 *
	 * @param int $subject
	 * @param int $talk
	 */
	public function testGetTalk( $subject, $talk ) {
		$obj = $this->newObj();
		$this->assertSame( $talk, $obj->getTalk( $subject ) );
		$this->assertSame( $talk, $obj->getTalk( $talk ) );

		$subjectTitleVal = new TitleValue( $subject, 'A' );
		$talkTitleVal = new TitleValue( $talk, 'A' );
		// Object will be the same one passed in if it's a talk, different but equal object if it's
		// subject
		$this->assertEquals( $talkTitleVal, $obj->getTalkPage( $subjectTitleVal ) );
		$this->assertSame( $talkTitleVal, $obj->getTalkPage( $talkTitleVal ) );

		$subjectTitle = Title::makeTitle( $subject, 'A' );
		$talkTitle = Title::makeTitle( $talk, 'A' );
		$this->assertEquals( $talkTitle, $subjectTitle->getTalkPage() );
		$this->assertSame( $talkTitle, $talkTitle->getTalkPage() );
	}

	/**
	 * @dataProvider provideSpecialNamespaces
	 * @covers \MediaWiki\Title\NamespaceInfo::getTalk
	 * @covers \MediaWiki\Title\NamespaceInfo::isMethodValidFor
	 *
	 * @param int $ns
	 */
	public function testGetTalk_special( $ns ) {
		$this->expectException( MWException::class );
		$this->expectExceptionMessage(
			"NamespaceInfo::getTalk does not make any sense for given namespace $ns"
		);
		$this->newObj()->getTalk( $ns );
	}

	/**
	 * @dataProvider provideSpecialNamespaces
	 * @covers \MediaWiki\Title\NamespaceInfo::getAssociated
	 * @covers \MediaWiki\Title\NamespaceInfo::isMethodValidFor
	 *
	 * @param int $ns
	 */
	public function testGetAssociated_special( $ns ) {
		$this->expectException( MWException::class );
		$this->expectExceptionMessage(
			"NamespaceInfo::getAssociated does not make any sense for given namespace $ns"
		);
		$this->newObj()->getAssociated( $ns );
	}

	public static function provideCanHaveTalkPage() {
		return [
			[ new TitleValue( NS_MAIN, 'Test' ), true ],
			[ new TitleValue( NS_TALK, 'Test' ), true ],
			[ new TitleValue( NS_USER, 'Test' ), true ],
			[ new TitleValue( NS_SPECIAL, 'Test' ), false ],
			[ new TitleValue( NS_MEDIA, 'Test' ), false ],
			[ new TitleValue( NS_MAIN, '', 'Kittens' ), false ],
			[ new TitleValue( NS_MAIN, 'Kittens', '', 'acme' ), false ],
		];
	}

	/**
	 * @dataProvider provideCanHaveTalkPage
	 * @covers \MediaWiki\Title\NamespaceInfo::canHaveTalkPage
	 */
	public function testCanHaveTalkPage( LinkTarget $t, $expected ) {
		$actual = $this->newObj()->canHaveTalkPage( $t );
		$this->assertEquals( $expected, $actual, $t->getDBkey() );
	}

	public static function provideGetTalkPage_good() {
		return [
			[ new TitleValue( NS_MAIN, 'Test' ), new TitleValue( NS_TALK, 'Test' ) ],
			[ new TitleValue( NS_TALK, 'Test' ), new TitleValue( NS_TALK, 'Test' ) ],
			[ new TitleValue( NS_USER, 'Test' ), new TitleValue( NS_USER_TALK, 'Test' ) ],
		];
	}

	/**
	 * @dataProvider provideGetTalkPage_good
	 * @covers \MediaWiki\Title\NamespaceInfo::getTalk
	 * @covers \MediaWiki\Title\NamespaceInfo::getTalkPage
	 * @covers \MediaWiki\Title\NamespaceInfo::isMethodValidFor
	 */
	public function testGetTalkPage_good( LinkTarget $t, LinkTarget $expected ) {
		$actual = $this->newObj()->getTalkPage( $t );
		$this->assertEquals( $expected, $actual, $t->getDBkey() );
	}

	public static function provideGetTalkPage_bad() {
		return [
			[ new TitleValue( NS_SPECIAL, 'Test' ) ],
			[ new TitleValue( NS_MEDIA, 'Test' ) ],
			[ new TitleValue( NS_MAIN, '', 'Kittens' ) ],
			[ new TitleValue( NS_MAIN, 'Kittens', '', 'acme' ) ],
		];
	}

	/**
	 * @dataProvider provideGetTalkPage_bad
	 * @covers \MediaWiki\Title\NamespaceInfo::getTalk
	 * @covers \MediaWiki\Title\NamespaceInfo::getTalkPage
	 * @covers \MediaWiki\Title\NamespaceInfo::isMethodValidFor
	 */
	public function testGetTalkPage_bad( LinkTarget $t ) {
		$this->expectException( MWException::class );
		$this->newObj()->getTalkPage( $t );
	}

	/**
	 * @dataProvider provideGetTalkPage_bad
	 * @covers \MediaWiki\Title\NamespaceInfo::getAssociated
	 * @covers \MediaWiki\Title\NamespaceInfo::getAssociatedPage
	 * @covers \MediaWiki\Title\NamespaceInfo::isMethodValidFor
	 */
	public function testGetAssociatedPage_bad( LinkTarget $t ) {
		$this->expectException( MWException::class );
		$this->newObj()->getAssociatedPage( $t );
	}

	/**
	 * @dataProvider provideSubjectTalk
	 * @covers \MediaWiki\Title\NamespaceInfo::getAssociated
	 * @covers \MediaWiki\Title\NamespaceInfo::getAssociatedPage
	 * @covers \MediaWiki\Title\Title::getOtherPage
	 *
	 * @param int $subject
	 * @param int $talk
	 */
	public function testGetAssociated( $subject, $talk ) {
		$obj = $this->newObj();
		$this->assertSame( $talk, $obj->getAssociated( $subject ) );
		$this->assertSame( $subject, $obj->getAssociated( $talk ) );

		$subjectTitle = new TitleValue( $subject, 'A' );
		$talkTitle = new TitleValue( $talk, 'A' );
		// Object will not be the same
		$this->assertEquals( $talkTitle, $obj->getAssociatedPage( $subjectTitle ) );
		$this->assertEquals( $subjectTitle, $obj->getAssociatedPage( $talkTitle ) );

		$subjectTitle = Title::makeTitle( $subject, 'A' );
		$talkTitle = Title::makeTitle( $talk, 'A' );
		$this->assertEquals( $talkTitle, $subjectTitle->getOtherPage() );
		$this->assertEquals( $subjectTitle, $talkTitle->getOtherPage() );
	}

	public static function provideSubjectTalk() {
		return [
			// Format: [ subject, talk ]
			'Main/talk' => [ NS_MAIN, NS_TALK ],
			'User/user talk' => [ NS_USER, NS_USER_TALK ],
			'Unknown namespaces also supported' => [ 106, 107 ],
		];
	}

	public static function provideSpecialNamespaces() {
		return [
			'Special' => [ NS_SPECIAL ],
			'Media' => [ NS_MEDIA ],
			'Unknown negative index' => [ -613 ],
		];
	}

	// %} End getSubject/Talk/Associated

	/**********************************************************************************************
	 * Canonical namespaces
	 * %{
	 */

	// Default canonical namespaces
	// %{
	private function getDefaultNamespaces() {
		return [ NS_MAIN => '' ] + self::DEFAULT_OPTIONS['CanonicalNamespaceNames'];
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalNamespaces
	 */
	public function testGetCanonicalNamespaces() {
		$this->assertSame(
			$this->getDefaultNamespaces(),
			$this->newObj()->getCanonicalNamespaces()
		);
	}

	/**
	 * @dataProvider provideGetCanonicalName
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalName
	 *
	 * @param int $index
	 * @param string|bool $expected
	 */
	public function testGetCanonicalName( $index, $expected ) {
		$this->assertSame( $expected, $this->newObj()->getCanonicalName( $index ) );
	}

	public static function provideGetCanonicalName() {
		return [
			'Main' => [ NS_MAIN, '' ],
			'Talk' => [ NS_TALK, 'Talk' ],
			'With underscore not space' => [ NS_USER_TALK, 'User_talk' ],
			'Special' => [ NS_SPECIAL, 'Special' ],
			'Nonexistent' => [ 12345, false ],
			'Nonexistent negative' => [ -12345, false ],
		];
	}

	/**
	 * @dataProvider provideGetCanonicalIndex
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalIndex
	 *
	 * @param string $name
	 * @param int|null $expected
	 */
	public function testGetCanonicalIndex( $name, $expected ) {
		$this->assertSame( $expected, $this->newObj()->getCanonicalIndex( $name ) );
	}

	public static function provideGetCanonicalIndex() {
		return [
			'Main' => [ '', NS_MAIN ],
			'Talk' => [ 'talk', NS_TALK ],
			'Not lowercase' => [ 'Talk', null ],
			'With underscore' => [ 'user_talk', NS_USER_TALK ],
			'Space is not recognized for underscore' => [ 'user talk', null ],
			'0' => [ '0', null ],
		];
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getValidNamespaces
	 */
	public function testGetValidNamespaces() {
		$this->assertSame(
			[ NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK ],
			$this->newObj()->getValidNamespaces()
		);
	}

	// %} End default canonical namespaces

	// No canonical namespace names
	// %{

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalNamespaces
	 */
	public function testGetCanonicalNamespaces_NoCanonicalNamespaceNames() {
		$obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] );

		$this->assertSame( [ NS_MAIN => '' ], $obj->getCanonicalNamespaces() );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalName
	 */
	public function testGetCanonicalName_NoCanonicalNamespaceNames() {
		$obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] );

		$this->assertSame( '', $obj->getCanonicalName( NS_MAIN ) );
		$this->assertFalse( $obj->getCanonicalName( NS_TALK ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalIndex
	 */
	public function testGetCanonicalIndex_NoCanonicalNamespaceNames() {
		$obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] );

		$this->assertSame( NS_MAIN, $obj->getCanonicalIndex( '' ) );
		$this->assertNull( $obj->getCanonicalIndex( 'talk' ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getValidNamespaces
	 */
	public function testGetValidNamespaces_NoCanonicalNamespaceNames() {
		$obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] );

		$this->assertSame( [ NS_MAIN ], $obj->getValidNamespaces() );
	}

	// %} End no canonical namespace names

	// Test extension namespaces
	// %{

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalNamespaces
	 */
	public function testGetCanonicalNamespaces_ExtensionNamespaces() {
		$this->assertSame(
			$this->getDefaultNamespaces() + [ 12345 => 'Extended' ],
			$this->newObj( [], self::TEST_EXT_NAMESPACES )->getCanonicalNamespaces()
		);
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalName
	 */
	public function testGetCanonicalName_ExtensionNamespaces() {
		$obj = $this->newObj( [], self::TEST_EXT_NAMESPACES );

		$this->assertSame( '', $obj->getCanonicalName( NS_MAIN ) );
		$this->assertSame( 'Talk', $obj->getCanonicalName( NS_TALK ) );
		$this->assertSame( 'Extended', $obj->getCanonicalName( 12345 ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalIndex
	 */
	public function testGetCanonicalIndex_ExtensionNamespaces() {
		$obj = $this->newObj( [], self::TEST_EXT_NAMESPACES );

		$this->assertSame( NS_MAIN, $obj->getCanonicalIndex( '' ) );
		$this->assertSame( NS_TALK, $obj->getCanonicalIndex( 'talk' ) );
		$this->assertSame( 12345, $obj->getCanonicalIndex( 'extended' ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getValidNamespaces
	 */
	public function testGetValidNamespaces_ExtensionNamespaces() {
		$this->assertSame(
			[ NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK, 12345 ],
			$this->newObj( [], self::TEST_EXT_NAMESPACES )->getValidNamespaces()
		);
	}

	// %} End extension namespaces

	// Hook namespaces
	// %{

	/**
	 * @return array Expected canonical namespaces
	 */
	private function setupHookNamespaces() {
		$callback =
			static function ( &$canonicalNamespaces ) {
				$canonicalNamespaces[NS_MAIN] = 'Main';
				unset( $canonicalNamespaces[NS_MEDIA] );
				$canonicalNamespaces[123456] = 'Hooked';
			};
		$this->setTemporaryHook( 'CanonicalNamespaces', $callback );
		$expected = $this->getDefaultNamespaces();
		( $callback )( $expected );
		return $expected;
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalNamespaces
	 */
	public function testGetCanonicalNamespaces_HookNamespaces() {
		$expected = $this->setupHookNamespaces();

		$this->assertSame( $expected, $this->newObj()->getCanonicalNamespaces() );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalName
	 */
	public function testGetCanonicalName_HookNamespaces() {
		$this->setupHookNamespaces();
		$obj = $this->newObj();

		$this->assertSame( 'Main', $obj->getCanonicalName( NS_MAIN ) );
		$this->assertFalse( $obj->getCanonicalName( NS_MEDIA ) );
		$this->assertSame( 'Hooked', $obj->getCanonicalName( 123456 ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalIndex
	 */
	public function testGetCanonicalIndex_HookNamespaces() {
		$this->setupHookNamespaces();
		$obj = $this->newObj();

		$this->assertSame( NS_MAIN, $obj->getCanonicalIndex( 'main' ) );
		$this->assertNull( $obj->getCanonicalIndex( 'media' ) );
		$this->assertSame( 123456, $obj->getCanonicalIndex( 'hooked' ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getValidNamespaces
	 */
	public function testGetValidNamespaces_HookNamespaces() {
		$this->setupHookNamespaces();

		$this->assertSame(
			[ NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK, 123456 ],
			$this->newObj()->getValidNamespaces()
		);
	}

	// %} End hook namespaces

	// Extra namespaces
	// %{

	/**
	 * @return NamespaceInfo
	 */
	private function setupExtraNamespaces() {
		return $this->newObj( [ MainConfigNames::ExtraNamespaces =>
			[ NS_MAIN => 'No effect', NS_TALK => 'No effect', 1234567 => 'Extra' ]
		] );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalNamespaces
	 */
	public function testGetCanonicalNamespaces_ExtraNamespaces() {
		$this->assertSame(
			$this->getDefaultNamespaces() + [ 1234567 => 'Extra' ],
			$this->setupExtraNamespaces()->getCanonicalNamespaces()
		);
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalName
	 */
	public function testGetCanonicalName_ExtraNamespaces() {
		$obj = $this->setupExtraNamespaces();

		$this->assertSame( '', $obj->getCanonicalName( NS_MAIN ) );
		$this->assertSame( 'Talk', $obj->getCanonicalName( NS_TALK ) );
		$this->assertSame( 'Extra', $obj->getCanonicalName( 1234567 ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalIndex
	 */
	public function testGetCanonicalIndex_ExtraNamespaces() {
		$obj = $this->setupExtraNamespaces();

		$this->assertNull( $obj->getCanonicalIndex( 'no effect' ) );
		$this->assertNull( $obj->getCanonicalIndex( 'no_effect' ) );
		$this->assertSame( 1234567, $obj->getCanonicalIndex( 'extra' ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getValidNamespaces
	 */
	public function testGetValidNamespaces_ExtraNamespaces() {
		$this->assertSame(
			[ NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK, 1234567 ],
			$this->setupExtraNamespaces()->getValidNamespaces()
		);
	}

	// %} End extra namespaces

	// Canonical namespace caching
	// %{

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalNamespaces
	 */
	public function testGetCanonicalNamespaces_caching() {
		$obj = $this->newObj();

		// This should cache the values
		$obj->getCanonicalNamespaces();

		// Now try to alter them through nefarious means
		$this->setupHookNamespaces();

		// Should have no effect
		$this->assertSame( $this->getDefaultNamespaces(), $obj->getCanonicalNamespaces() );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalName
	 */
	public function testGetCanonicalName_caching() {
		$obj = $this->newObj();

		// This should cache the values
		$obj->getCanonicalName( NS_MAIN );

		// Now try to alter them through nefarious means
		$this->setupHookNamespaces();

		// Should have no effect
		$this->assertSame( '', $obj->getCanonicalName( NS_MAIN ) );
		$this->assertSame( 'Media', $obj->getCanonicalName( NS_MEDIA ) );
		$this->assertFalse( $obj->getCanonicalName( 12345 ) );
		$this->assertFalse( $obj->getCanonicalName( 123456 ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getCanonicalIndex
	 */
	public function testGetCanonicalIndex_caching() {
		$obj = $this->newObj();

		// This should cache the values
		$obj->getCanonicalIndex( '' );

		// Now try to alter them through nefarious means
		$this->setupHookNamespaces();

		// Should have no effect
		$this->assertSame( NS_MAIN, $obj->getCanonicalIndex( '' ) );
		$this->assertSame( NS_MEDIA, $obj->getCanonicalIndex( 'media' ) );
		$this->assertNull( $obj->getCanonicalIndex( 'extended' ) );
		$this->assertNull( $obj->getCanonicalIndex( 'hooked' ) );
	}

	/**
	 * @covers \MediaWiki\Title\NamespaceInfo::getValidNamespaces
	 */
	public function testGetValidNamespaces_caching() {
		$obj = $this->newObj();

		// This should cache the values
		$obj->getValidNamespaces();

		// Now try to alter through nefarious means
		$this->setupHookNamespaces();

		// Should have no effect
		$this->assertSame(
			[ NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK ],
			$obj->getValidNamespaces()
		);
	}

	// %} End canonical namespace caching

	// Miscellaneous
	// %{

	/**
	 * @dataProvider provideGetValidNamespaces_misc
	 * @covers \MediaWiki\Title\NamespaceInfo::getValidNamespaces
	 *
	 * @param array $namespaces List of namespace indices to return from getCanonicalNamespaces()
	 *   (list is overwritten by a hook, so NS_MAIN doesn't have to be present)
	 * @param array $expected
	 */
	public function testGetValidNamespaces_misc( array $namespaces, array $expected ) {
		// Each namespace's name is just its index
		$this->setTemporaryHook( 'CanonicalNamespaces',
			static function ( &$canonicalNamespaces ) use ( $namespaces ) {
				$canonicalNamespaces = array_combine( $namespaces, $namespaces );
			}
		);
		$this->assertSame( $expected, $this->newObj()->getValidNamespaces() );
	}

	public static function provideGetValidNamespaces_misc() {
		return [
			'Out of order (T109137)' => [ [ 1, 0 ], [ 0, 1 ] ],
			'Alphabetical order' => [ [ 10, 2 ], [ 2, 10 ] ],
			'Negative' => [ [ -1000, -500, -2, 0 ], [ 0 ] ],
		];
	}

	// %} End miscellaneous
	// %} End canonical namespaces

	/**
	 * @coversNothing
	 */
	public function testAllServiceOptionsUsed() {
		$this->assertAllServiceOptionsUsed();
	}
}

/**
 * For really cool vim folding this needs to be at the end:
 * vim: foldmarker=%{,%} foldmethod=marker
 */