MWNamespaceTest.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <?php
  2. /**
  3. * @author Antoine Musso
  4. * @copyright Copyright © 2011, Antoine Musso
  5. * @file
  6. */
  7. class MWNamespaceTest extends MediaWikiTestCase {
  8. protected function setUp() {
  9. parent::setUp();
  10. $this->setMwGlobals( [
  11. 'wgContentNamespaces' => [ NS_MAIN ],
  12. 'wgNamespacesWithSubpages' => [
  13. NS_TALK => true,
  14. NS_USER => true,
  15. NS_USER_TALK => true,
  16. ],
  17. 'wgCapitalLinks' => true,
  18. 'wgCapitalLinkOverrides' => [],
  19. 'wgNonincludableNamespaces' => [],
  20. ] );
  21. }
  22. /**
  23. * @todo Write more texts, handle $wgAllowImageMoving setting
  24. * @covers MWNamespace::isMovable
  25. */
  26. public function testIsMovable() {
  27. $this->assertFalse( MWNamespace::isMovable( NS_SPECIAL ) );
  28. }
  29. private function assertIsSubject( $ns ) {
  30. $this->assertTrue( MWNamespace::isSubject( $ns ) );
  31. }
  32. private function assertIsNotSubject( $ns ) {
  33. $this->assertFalse( MWNamespace::isSubject( $ns ) );
  34. }
  35. /**
  36. * Please make sure to change testIsTalk() if you change the assertions below
  37. * @covers MWNamespace::isSubject
  38. */
  39. public function testIsSubject() {
  40. // Special namespaces
  41. $this->assertIsSubject( NS_MEDIA );
  42. $this->assertIsSubject( NS_SPECIAL );
  43. // Subject pages
  44. $this->assertIsSubject( NS_MAIN );
  45. $this->assertIsSubject( NS_USER );
  46. $this->assertIsSubject( 100 ); # user defined
  47. // Talk pages
  48. $this->assertIsNotSubject( NS_TALK );
  49. $this->assertIsNotSubject( NS_USER_TALK );
  50. $this->assertIsNotSubject( 101 ); # user defined
  51. }
  52. private function assertIsTalk( $ns ) {
  53. $this->assertTrue( MWNamespace::isTalk( $ns ) );
  54. }
  55. private function assertIsNotTalk( $ns ) {
  56. $this->assertFalse( MWNamespace::isTalk( $ns ) );
  57. }
  58. /**
  59. * Reverse of testIsSubject().
  60. * Please update testIsSubject() if you change assertions below
  61. * @covers MWNamespace::isTalk
  62. */
  63. public function testIsTalk() {
  64. // Special namespaces
  65. $this->assertIsNotTalk( NS_MEDIA );
  66. $this->assertIsNotTalk( NS_SPECIAL );
  67. // Subject pages
  68. $this->assertIsNotTalk( NS_MAIN );
  69. $this->assertIsNotTalk( NS_USER );
  70. $this->assertIsNotTalk( 100 ); # user defined
  71. // Talk pages
  72. $this->assertIsTalk( NS_TALK );
  73. $this->assertIsTalk( NS_USER_TALK );
  74. $this->assertIsTalk( 101 ); # user defined
  75. }
  76. /**
  77. * @covers MWNamespace::getSubject
  78. */
  79. public function testGetSubject() {
  80. // Special namespaces are their own subjects
  81. $this->assertEquals( NS_MEDIA, MWNamespace::getSubject( NS_MEDIA ) );
  82. $this->assertEquals( NS_SPECIAL, MWNamespace::getSubject( NS_SPECIAL ) );
  83. $this->assertEquals( NS_MAIN, MWNamespace::getSubject( NS_TALK ) );
  84. $this->assertEquals( NS_USER, MWNamespace::getSubject( NS_USER_TALK ) );
  85. }
  86. /**
  87. * Regular getTalk() calls
  88. * Namespaces without a talk page (NS_MEDIA, NS_SPECIAL) are tested in
  89. * the function testGetTalkExceptions()
  90. * @covers MWNamespace::getTalk
  91. */
  92. public function testGetTalk() {
  93. $this->assertEquals( NS_TALK, MWNamespace::getTalk( NS_MAIN ) );
  94. $this->assertEquals( NS_TALK, MWNamespace::getTalk( NS_TALK ) );
  95. $this->assertEquals( NS_USER_TALK, MWNamespace::getTalk( NS_USER ) );
  96. $this->assertEquals( NS_USER_TALK, MWNamespace::getTalk( NS_USER_TALK ) );
  97. }
  98. /**
  99. * Exceptions with getTalk()
  100. * NS_MEDIA does not have talk pages. MediaWiki raise an exception for them.
  101. * @expectedException MWException
  102. * @covers MWNamespace::getTalk
  103. */
  104. public function testGetTalkExceptionsForNsMedia() {
  105. $this->assertNull( MWNamespace::getTalk( NS_MEDIA ) );
  106. }
  107. /**
  108. * Exceptions with getTalk()
  109. * NS_SPECIAL does not have talk pages. MediaWiki raise an exception for them.
  110. * @expectedException MWException
  111. * @covers MWNamespace::getTalk
  112. */
  113. public function testGetTalkExceptionsForNsSpecial() {
  114. $this->assertNull( MWNamespace::getTalk( NS_SPECIAL ) );
  115. }
  116. /**
  117. * Regular getAssociated() calls
  118. * Namespaces without an associated page (NS_MEDIA, NS_SPECIAL) are tested in
  119. * the function testGetAssociatedExceptions()
  120. * @covers MWNamespace::getAssociated
  121. */
  122. public function testGetAssociated() {
  123. $this->assertEquals( NS_TALK, MWNamespace::getAssociated( NS_MAIN ) );
  124. $this->assertEquals( NS_MAIN, MWNamespace::getAssociated( NS_TALK ) );
  125. }
  126. # ## Exceptions with getAssociated()
  127. # ## NS_MEDIA and NS_SPECIAL do not have talk pages. MediaWiki raises
  128. # ## an exception for them.
  129. /**
  130. * @expectedException MWException
  131. * @covers MWNamespace::getAssociated
  132. */
  133. public function testGetAssociatedExceptionsForNsMedia() {
  134. $this->assertNull( MWNamespace::getAssociated( NS_MEDIA ) );
  135. }
  136. /**
  137. * @expectedException MWException
  138. * @covers MWNamespace::getAssociated
  139. */
  140. public function testGetAssociatedExceptionsForNsSpecial() {
  141. $this->assertNull( MWNamespace::getAssociated( NS_SPECIAL ) );
  142. }
  143. /**
  144. * Test MWNamespace::equals
  145. * Note if we add a namespace registration system with keys like 'MAIN'
  146. * we should add tests here for equivilance on things like 'MAIN' == 0
  147. * and 'MAIN' == NS_MAIN.
  148. * @covers MWNamespace::equals
  149. */
  150. public function testEquals() {
  151. $this->assertTrue( MWNamespace::equals( NS_MAIN, NS_MAIN ) );
  152. $this->assertTrue( MWNamespace::equals( NS_MAIN, 0 ) ); // In case we make NS_MAIN 'MAIN'
  153. $this->assertTrue( MWNamespace::equals( NS_USER, NS_USER ) );
  154. $this->assertTrue( MWNamespace::equals( NS_USER, 2 ) );
  155. $this->assertTrue( MWNamespace::equals( NS_USER_TALK, NS_USER_TALK ) );
  156. $this->assertTrue( MWNamespace::equals( NS_SPECIAL, NS_SPECIAL ) );
  157. $this->assertFalse( MWNamespace::equals( NS_MAIN, NS_TALK ) );
  158. $this->assertFalse( MWNamespace::equals( NS_USER, NS_USER_TALK ) );
  159. $this->assertFalse( MWNamespace::equals( NS_PROJECT, NS_TEMPLATE ) );
  160. }
  161. /**
  162. * @covers MWNamespace::subjectEquals
  163. */
  164. public function testSubjectEquals() {
  165. $this->assertSameSubject( NS_MAIN, NS_MAIN );
  166. $this->assertSameSubject( NS_MAIN, 0 ); // In case we make NS_MAIN 'MAIN'
  167. $this->assertSameSubject( NS_USER, NS_USER );
  168. $this->assertSameSubject( NS_USER, 2 );
  169. $this->assertSameSubject( NS_USER_TALK, NS_USER_TALK );
  170. $this->assertSameSubject( NS_SPECIAL, NS_SPECIAL );
  171. $this->assertSameSubject( NS_MAIN, NS_TALK );
  172. $this->assertSameSubject( NS_USER, NS_USER_TALK );
  173. $this->assertDifferentSubject( NS_PROJECT, NS_TEMPLATE );
  174. $this->assertDifferentSubject( NS_SPECIAL, NS_MAIN );
  175. }
  176. /**
  177. * @covers MWNamespace::subjectEquals
  178. */
  179. public function testSpecialAndMediaAreDifferentSubjects() {
  180. $this->assertDifferentSubject(
  181. NS_MEDIA, NS_SPECIAL,
  182. "NS_MEDIA and NS_SPECIAL are different subject namespaces"
  183. );
  184. $this->assertDifferentSubject(
  185. NS_SPECIAL, NS_MEDIA,
  186. "NS_SPECIAL and NS_MEDIA are different subject namespaces"
  187. );
  188. }
  189. public function provideHasTalkNamespace() {
  190. return [
  191. [ NS_MEDIA, false ],
  192. [ NS_SPECIAL, false ],
  193. [ NS_MAIN, true ],
  194. [ NS_TALK, true ],
  195. [ NS_USER, true ],
  196. [ NS_USER_TALK, true ],
  197. [ 100, true ],
  198. [ 101, true ],
  199. ];
  200. }
  201. /**
  202. * @dataProvider provideHasTalkNamespace
  203. * @covers MWNamespace::hasTalkNamespace
  204. *
  205. * @param int $index
  206. * @param bool $expected
  207. */
  208. public function testHasTalkNamespace( $index, $expected ) {
  209. $actual = MWNamespace::hasTalkNamespace( $index );
  210. $this->assertSame( $actual, $expected, "NS $index" );
  211. }
  212. /**
  213. * @dataProvider provideHasTalkNamespace
  214. * @covers MWNamespace::canTalk
  215. *
  216. * @param int $index
  217. * @param bool $expected
  218. */
  219. public function testCanTalk( $index, $expected ) {
  220. $actual = MWNamespace::canTalk( $index );
  221. $this->assertSame( $actual, $expected, "NS $index" );
  222. }
  223. private function assertIsContent( $ns ) {
  224. $this->assertTrue( MWNamespace::isContent( $ns ) );
  225. }
  226. private function assertIsNotContent( $ns ) {
  227. $this->assertFalse( MWNamespace::isContent( $ns ) );
  228. }
  229. /**
  230. * @covers MWNamespace::isContent
  231. */
  232. public function testIsContent() {
  233. // NS_MAIN is a content namespace per DefaultSettings.php
  234. // and per function definition.
  235. $this->assertIsContent( NS_MAIN );
  236. // Other namespaces which are not expected to be content
  237. $this->assertIsNotContent( NS_MEDIA );
  238. $this->assertIsNotContent( NS_SPECIAL );
  239. $this->assertIsNotContent( NS_TALK );
  240. $this->assertIsNotContent( NS_USER );
  241. $this->assertIsNotContent( NS_CATEGORY );
  242. $this->assertIsNotContent( 100 );
  243. }
  244. /**
  245. * Similar to testIsContent() but alters the $wgContentNamespaces
  246. * global variable.
  247. * @covers MWNamespace::isContent
  248. */
  249. public function testIsContentAdvanced() {
  250. global $wgContentNamespaces;
  251. // Test that user defined namespace #252 is not content
  252. $this->assertIsNotContent( 252 );
  253. // Bless namespace # 252 as a content namespace
  254. $wgContentNamespaces[] = 252;
  255. $this->assertIsContent( 252 );
  256. // Makes sure NS_MAIN was not impacted
  257. $this->assertIsContent( NS_MAIN );
  258. }
  259. private function assertIsWatchable( $ns ) {
  260. $this->assertTrue( MWNamespace::isWatchable( $ns ) );
  261. }
  262. private function assertIsNotWatchable( $ns ) {
  263. $this->assertFalse( MWNamespace::isWatchable( $ns ) );
  264. }
  265. /**
  266. * @covers MWNamespace::isWatchable
  267. */
  268. public function testIsWatchable() {
  269. // Specials namespaces are not watchable
  270. $this->assertIsNotWatchable( NS_MEDIA );
  271. $this->assertIsNotWatchable( NS_SPECIAL );
  272. // Core defined namespaces are watchables
  273. $this->assertIsWatchable( NS_MAIN );
  274. $this->assertIsWatchable( NS_TALK );
  275. // Additional, user defined namespaces are watchables
  276. $this->assertIsWatchable( 100 );
  277. $this->assertIsWatchable( 101 );
  278. }
  279. private function assertHasSubpages( $ns ) {
  280. $this->assertTrue( MWNamespace::hasSubpages( $ns ) );
  281. }
  282. private function assertHasNotSubpages( $ns ) {
  283. $this->assertFalse( MWNamespace::hasSubpages( $ns ) );
  284. }
  285. /**
  286. * @covers MWNamespace::hasSubpages
  287. */
  288. public function testHasSubpages() {
  289. global $wgNamespacesWithSubpages;
  290. // Special namespaces:
  291. $this->assertHasNotSubpages( NS_MEDIA );
  292. $this->assertHasNotSubpages( NS_SPECIAL );
  293. // Namespaces without subpages
  294. $this->assertHasNotSubpages( NS_MAIN );
  295. $wgNamespacesWithSubpages[NS_MAIN] = true;
  296. $this->assertHasSubpages( NS_MAIN );
  297. $wgNamespacesWithSubpages[NS_MAIN] = false;
  298. $this->assertHasNotSubpages( NS_MAIN );
  299. // Some namespaces with subpages
  300. $this->assertHasSubpages( NS_TALK );
  301. $this->assertHasSubpages( NS_USER );
  302. $this->assertHasSubpages( NS_USER_TALK );
  303. }
  304. /**
  305. * @covers MWNamespace::getContentNamespaces
  306. */
  307. public function testGetContentNamespaces() {
  308. global $wgContentNamespaces;
  309. $this->assertEquals(
  310. [ NS_MAIN ],
  311. MWNamespace::getContentNamespaces(),
  312. '$wgContentNamespaces is an array with only NS_MAIN by default'
  313. );
  314. # test !is_array( $wgcontentNamespaces )
  315. $wgContentNamespaces = '';
  316. $this->assertEquals( [ NS_MAIN ], MWNamespace::getContentNamespaces() );
  317. $wgContentNamespaces = false;
  318. $this->assertEquals( [ NS_MAIN ], MWNamespace::getContentNamespaces() );
  319. $wgContentNamespaces = null;
  320. $this->assertEquals( [ NS_MAIN ], MWNamespace::getContentNamespaces() );
  321. $wgContentNamespaces = 5;
  322. $this->assertEquals( [ NS_MAIN ], MWNamespace::getContentNamespaces() );
  323. # test $wgContentNamespaces === []
  324. $wgContentNamespaces = [];
  325. $this->assertEquals( [ NS_MAIN ], MWNamespace::getContentNamespaces() );
  326. # test !in_array( NS_MAIN, $wgContentNamespaces )
  327. $wgContentNamespaces = [ NS_USER, NS_CATEGORY ];
  328. $this->assertEquals(
  329. [ NS_MAIN, NS_USER, NS_CATEGORY ],
  330. MWNamespace::getContentNamespaces(),
  331. 'NS_MAIN is forced in $wgContentNamespaces even if unwanted'
  332. );
  333. # test other cases, return $wgcontentNamespaces as is
  334. $wgContentNamespaces = [ NS_MAIN ];
  335. $this->assertEquals(
  336. [ NS_MAIN ],
  337. MWNamespace::getContentNamespaces()
  338. );
  339. $wgContentNamespaces = [ NS_MAIN, NS_USER, NS_CATEGORY ];
  340. $this->assertEquals(
  341. [ NS_MAIN, NS_USER, NS_CATEGORY ],
  342. MWNamespace::getContentNamespaces()
  343. );
  344. }
  345. /**
  346. * @covers MWNamespace::getSubjectNamespaces
  347. */
  348. public function testGetSubjectNamespaces() {
  349. $subjectsNS = MWNamespace::getSubjectNamespaces();
  350. $this->assertContains( NS_MAIN, $subjectsNS,
  351. "Talk namespaces should have NS_MAIN" );
  352. $this->assertNotContains( NS_TALK, $subjectsNS,
  353. "Talk namespaces should have NS_TALK" );
  354. $this->assertNotContains( NS_MEDIA, $subjectsNS,
  355. "Talk namespaces should not have NS_MEDIA" );
  356. $this->assertNotContains( NS_SPECIAL, $subjectsNS,
  357. "Talk namespaces should not have NS_SPECIAL" );
  358. }
  359. /**
  360. * @covers MWNamespace::getTalkNamespaces
  361. */
  362. public function testGetTalkNamespaces() {
  363. $talkNS = MWNamespace::getTalkNamespaces();
  364. $this->assertContains( NS_TALK, $talkNS,
  365. "Subject namespaces should have NS_TALK" );
  366. $this->assertNotContains( NS_MAIN, $talkNS,
  367. "Subject namespaces should not have NS_MAIN" );
  368. $this->assertNotContains( NS_MEDIA, $talkNS,
  369. "Subject namespaces should not have NS_MEDIA" );
  370. $this->assertNotContains( NS_SPECIAL, $talkNS,
  371. "Subject namespaces should not have NS_SPECIAL" );
  372. }
  373. private function assertIsCapitalized( $ns ) {
  374. $this->assertTrue( MWNamespace::isCapitalized( $ns ) );
  375. }
  376. private function assertIsNotCapitalized( $ns ) {
  377. $this->assertFalse( MWNamespace::isCapitalized( $ns ) );
  378. }
  379. /**
  380. * Some namespaces are always capitalized per code definition
  381. * in MWNamespace::$alwaysCapitalizedNamespaces
  382. * @covers MWNamespace::isCapitalized
  383. */
  384. public function testIsCapitalizedHardcodedAssertions() {
  385. // NS_MEDIA and NS_FILE are treated the same
  386. $this->assertEquals(
  387. MWNamespace::isCapitalized( NS_MEDIA ),
  388. MWNamespace::isCapitalized( NS_FILE ),
  389. 'NS_MEDIA and NS_FILE have same capitalization rendering'
  390. );
  391. // Boths are capitalized by default
  392. $this->assertIsCapitalized( NS_MEDIA );
  393. $this->assertIsCapitalized( NS_FILE );
  394. // Always capitalized namespaces
  395. // @see MWNamespace::$alwaysCapitalizedNamespaces
  396. $this->assertIsCapitalized( NS_SPECIAL );
  397. $this->assertIsCapitalized( NS_USER );
  398. $this->assertIsCapitalized( NS_MEDIAWIKI );
  399. }
  400. /**
  401. * Follows up for testIsCapitalizedHardcodedAssertions() but alter the
  402. * global $wgCapitalLink setting to have extended coverage.
  403. *
  404. * MWNamespace::isCapitalized() rely on two global settings:
  405. * $wgCapitalLinkOverrides = []; by default
  406. * $wgCapitalLinks = true; by default
  407. * This function test $wgCapitalLinks
  408. *
  409. * Global setting correctness is tested against the NS_PROJECT and
  410. * NS_PROJECT_TALK namespaces since they are not hardcoded nor specials
  411. * @covers MWNamespace::isCapitalized
  412. */
  413. public function testIsCapitalizedWithWgCapitalLinks() {
  414. global $wgCapitalLinks;
  415. $this->assertIsCapitalized( NS_PROJECT );
  416. $this->assertIsCapitalized( NS_PROJECT_TALK );
  417. $wgCapitalLinks = false;
  418. // hardcoded namespaces (see above function) are still capitalized:
  419. $this->assertIsCapitalized( NS_SPECIAL );
  420. $this->assertIsCapitalized( NS_USER );
  421. $this->assertIsCapitalized( NS_MEDIAWIKI );
  422. // setting is correctly applied
  423. $this->assertIsNotCapitalized( NS_PROJECT );
  424. $this->assertIsNotCapitalized( NS_PROJECT_TALK );
  425. }
  426. /**
  427. * Counter part for MWNamespace::testIsCapitalizedWithWgCapitalLinks() now
  428. * testing the $wgCapitalLinkOverrides global.
  429. *
  430. * @todo split groups of assertions in autonomous testing functions
  431. * @covers MWNamespace::isCapitalized
  432. */
  433. public function testIsCapitalizedWithWgCapitalLinkOverrides() {
  434. global $wgCapitalLinkOverrides;
  435. // Test default settings
  436. $this->assertIsCapitalized( NS_PROJECT );
  437. $this->assertIsCapitalized( NS_PROJECT_TALK );
  438. // hardcoded namespaces (see above function) are capitalized:
  439. $this->assertIsCapitalized( NS_SPECIAL );
  440. $this->assertIsCapitalized( NS_USER );
  441. $this->assertIsCapitalized( NS_MEDIAWIKI );
  442. // Hardcoded namespaces remains capitalized
  443. $wgCapitalLinkOverrides[NS_SPECIAL] = false;
  444. $wgCapitalLinkOverrides[NS_USER] = false;
  445. $wgCapitalLinkOverrides[NS_MEDIAWIKI] = false;
  446. $this->assertIsCapitalized( NS_SPECIAL );
  447. $this->assertIsCapitalized( NS_USER );
  448. $this->assertIsCapitalized( NS_MEDIAWIKI );
  449. $wgCapitalLinkOverrides[NS_PROJECT] = false;
  450. $this->assertIsNotCapitalized( NS_PROJECT );
  451. $wgCapitalLinkOverrides[NS_PROJECT] = true;
  452. $this->assertIsCapitalized( NS_PROJECT );
  453. unset( $wgCapitalLinkOverrides[NS_PROJECT] );
  454. $this->assertIsCapitalized( NS_PROJECT );
  455. }
  456. /**
  457. * @covers MWNamespace::hasGenderDistinction
  458. */
  459. public function testHasGenderDistinction() {
  460. // Namespaces with gender distinctions
  461. $this->assertTrue( MWNamespace::hasGenderDistinction( NS_USER ) );
  462. $this->assertTrue( MWNamespace::hasGenderDistinction( NS_USER_TALK ) );
  463. // Other ones, "genderless"
  464. $this->assertFalse( MWNamespace::hasGenderDistinction( NS_MEDIA ) );
  465. $this->assertFalse( MWNamespace::hasGenderDistinction( NS_SPECIAL ) );
  466. $this->assertFalse( MWNamespace::hasGenderDistinction( NS_MAIN ) );
  467. $this->assertFalse( MWNamespace::hasGenderDistinction( NS_TALK ) );
  468. }
  469. /**
  470. * @covers MWNamespace::isNonincludable
  471. */
  472. public function testIsNonincludable() {
  473. global $wgNonincludableNamespaces;
  474. $wgNonincludableNamespaces = [ NS_USER ];
  475. $this->assertTrue( MWNamespace::isNonincludable( NS_USER ) );
  476. $this->assertFalse( MWNamespace::isNonincludable( NS_TEMPLATE ) );
  477. }
  478. private function assertSameSubject( $ns1, $ns2, $msg = '' ) {
  479. $this->assertTrue( MWNamespace::subjectEquals( $ns1, $ns2 ), $msg );
  480. }
  481. private function assertDifferentSubject( $ns1, $ns2, $msg = '' ) {
  482. $this->assertFalse( MWNamespace::subjectEquals( $ns1, $ns2 ), $msg );
  483. }
  484. public function provideGetCategoryLinkType() {
  485. return [
  486. [ NS_MAIN, 'page' ],
  487. [ NS_TALK, 'page' ],
  488. [ NS_USER, 'page' ],
  489. [ NS_USER_TALK, 'page' ],
  490. [ NS_FILE, 'file' ],
  491. [ NS_FILE_TALK, 'page' ],
  492. [ NS_CATEGORY, 'subcat' ],
  493. [ NS_CATEGORY_TALK, 'page' ],
  494. [ 100, 'page' ],
  495. [ 101, 'page' ],
  496. ];
  497. }
  498. /**
  499. * @dataProvider provideGetCategoryLinkType
  500. * @covers MWNamespace::getCategoryLinkType
  501. *
  502. * @param int $index
  503. * @param string $expected
  504. */
  505. public function testGetCategoryLinkType( $index, $expected ) {
  506. $actual = MWNamespace::getCategoryLinkType( $index );
  507. $this->assertSame( $expected, $actual, "NS $index" );
  508. }
  509. }