Merge "fix bug 29002 - in RTL wikis resizable are flipped"
[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( $expectedBool, $title->inNamespace( $ns ) );
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 public function dataIsCssOrJsPage() {
79 return array(
80 array( 'Foo', false ),
81 array( 'Foo.js', false ),
82 array( 'Foo/bar.js', false ),
83 array( 'User:Foo', false ),
84 array( 'User:Foo.js', false ),
85 array( 'User:Foo/bar.js', false ),
86 array( 'User:Foo/bar.css', false ),
87 array( 'User talk:Foo/bar.css', false ),
88 array( 'User:Foo/bar.js.xxx', false ),
89 array( 'User:Foo/bar.xxx', false ),
90 array( 'MediaWiki:Foo.js', true ),
91 array( 'MediaWiki:Foo.css', true ),
92 array( 'MediaWiki:Foo.JS', false ),
93 array( 'MediaWiki:Foo.CSS', false ),
94 array( 'MediaWiki:Foo.css.xxx', false ),
95 );
96 }
97
98 /**
99 * @dataProvider dataIsCssOrJsPage
100 */
101 public function testIsCssOrJsPage( $title, $expectedBool ) {
102 $title = Title::newFromText( $title );
103 $this->assertEquals( $expectedBool, $title->isCssOrJsPage() );
104 }
105
106
107 public function dataIsCssJsSubpage() {
108 return array(
109 array( 'Foo', false ),
110 array( 'Foo.js', false ),
111 array( 'Foo/bar.js', false ),
112 array( 'User:Foo', false ),
113 array( 'User:Foo.js', false ),
114 array( 'User:Foo/bar.js', true ),
115 array( 'User:Foo/bar.css', true ),
116 array( 'User talk:Foo/bar.css', false ),
117 array( 'User:Foo/bar.js.xxx', false ),
118 array( 'User:Foo/bar.xxx', false ),
119 array( 'MediaWiki:Foo.js', false ),
120 array( 'User:Foo/bar.JS', false ),
121 array( 'User:Foo/bar.CSS', false ),
122 );
123 }
124
125 /**
126 * @dataProvider dataIsCssJsSubpage
127 */
128 public function testIsCssJsSubpage( $title, $expectedBool ) {
129 $title = Title::newFromText( $title );
130 $this->assertEquals( $expectedBool, $title->isCssJsSubpage() );
131 }
132
133 public function dataIsCssSubpage() {
134 return array(
135 array( 'Foo', false ),
136 array( 'Foo.css', false ),
137 array( 'User:Foo', false ),
138 array( 'User:Foo.js', false ),
139 array( 'User:Foo.css', false ),
140 array( 'User:Foo/bar.js', false ),
141 array( 'User:Foo/bar.css', true ),
142 );
143 }
144
145 /**
146 * @dataProvider dataIsCssSubpage
147 */
148 public function testIsCssSubpage( $title, $expectedBool ) {
149 $title = Title::newFromText( $title );
150 $this->assertEquals( $expectedBool, $title->isCssSubpage() );
151 }
152
153 public function dataIsJsSubpage() {
154 return array(
155 array( 'Foo', false ),
156 array( 'Foo.css', false ),
157 array( 'User:Foo', false ),
158 array( 'User:Foo.js', false ),
159 array( 'User:Foo.css', false ),
160 array( 'User:Foo/bar.js', true ),
161 array( 'User:Foo/bar.css', false ),
162 );
163 }
164
165 /**
166 * @dataProvider dataIsJsSubpage
167 */
168 public function testIsJsSubpage( $title, $expectedBool ) {
169 $title = Title::newFromText( $title );
170 $this->assertEquals( $expectedBool, $title->isJsSubpage() );
171 }
172
173 public function dataIsWikitextPage() {
174 return array(
175 array( 'Foo', true ),
176 array( 'Foo.js', true ),
177 array( 'Foo/bar.js', true ),
178 array( 'User:Foo', true ),
179 array( 'User:Foo.js', true ),
180 array( 'User:Foo/bar.js', false ),
181 array( 'User:Foo/bar.css', false ),
182 array( 'User talk:Foo/bar.css', true ),
183 array( 'User:Foo/bar.js.xxx', true ),
184 array( 'User:Foo/bar.xxx', true ),
185 array( 'MediaWiki:Foo.js', false ),
186 array( 'MediaWiki:Foo.css', false ),
187 array( 'MediaWiki:Foo/bar.css', false ),
188 array( 'User:Foo/bar.JS', true ),
189 array( 'User:Foo/bar.CSS', true ),
190 );
191 }
192
193 /**
194 * @dataProvider dataIsWikitextPage
195 */
196 public function testIsWikitextPage( $title, $expectedBool ) {
197 $title = Title::newFromText( $title );
198 $this->assertEquals( $expectedBool, $title->isWikitextPage() );
199 }
200
201 }