Merge "(bug 35961) Hash comparison should always be strict."
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleMethodsTest.php
1 <?php
2
3 class TitleMethodsTest extends MediaWikiTestCase {
4
5 public function dataEquals() {
6 return array(
7 array( 'Main Page', 'Main Page', true ),
8 array( 'Main Page', 'Not The Main Page', false ),
9 array( 'Main Page', 'Project:Main Page', false ),
10 array( 'File:Example.png', 'Image:Example.png', true ),
11 array( 'Special:Version', 'Special:Version', true ),
12 array( 'Special:Version', 'Special:Recentchanges', false ),
13 array( 'Special:Version', 'Main Page', false ),
14 );
15 }
16
17 /**
18 * @dataProvider dataEquals
19 */
20 public function testEquals( $titleA, $titleB, $expectedBool ) {
21 $titleA = Title::newFromText( $titleA );
22 $titleB = Title::newFromText( $titleB );
23
24 $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) );
25 $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
26 }
27
28 public function dataInNamespace() {
29 return array(
30 array( 'Main Page', NS_MAIN, true ),
31 array( 'Main Page', NS_TALK, false ),
32 array( 'Main Page', NS_USER, false ),
33 array( 'User:Foo', NS_USER, true ),
34 array( 'User:Foo', NS_USER_TALK, false ),
35 array( 'User:Foo', NS_TEMPLATE, false ),
36 array( 'User_talk:Foo', NS_USER_TALK, true ),
37 array( 'User_talk:Foo', NS_USER, false ),
38 );
39 }
40
41 /**
42 * @dataProvider dataInNamespace
43 */
44 public function testInNamespace( $title, $ns, $expectedBool ) {
45 $title = Title::newFromText( $title );
46 $this->assertEquals( $title->inNamespace( $ns ), $expectedBool );
47 }
48
49 public function testInNamespaces() {
50 $mainpage = Title::newFromText( 'Main Page' );
51 $this->assertTrue( $mainpage->inNamespaces( NS_MAIN, NS_USER ) );
52 $this->assertTrue( $mainpage->inNamespaces( array( NS_MAIN, NS_USER ) ) );
53 $this->assertTrue( $mainpage->inNamespaces( array( NS_USER, NS_MAIN ) ) );
54 $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT, NS_TEMPLATE ) ) );
55 }
56
57 public function dataHasSubjectNamespace() {
58 return array(
59 array( 'Main Page', NS_MAIN, true ),
60 array( 'Main Page', NS_TALK, true ),
61 array( 'Main Page', NS_USER, false ),
62 array( 'User:Foo', NS_USER, true ),
63 array( 'User:Foo', NS_USER_TALK, true ),
64 array( 'User:Foo', NS_TEMPLATE, false ),
65 array( 'User_talk:Foo', NS_USER_TALK, true ),
66 array( 'User_talk:Foo', NS_USER, true ),
67 );
68 }
69
70 /**
71 * @dataProvider dataHasSubjectNamespace
72 */
73 public function testHasSubjectNamespace( $title, $ns, $expectedBool ) {
74 $title = Title::newFromText( $title );
75 $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) );
76 }
77
78 }