3 class TitleMethodsTest
extends MediaWikiTestCase
{
5 public function dataEquals() {
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 ),
18 * @dataProvider dataEquals
20 public function testEquals( $titleA, $titleB, $expectedBool ) {
21 $titleA = Title
::newFromText( $titleA );
22 $titleB = Title
::newFromText( $titleB );
24 $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) );
25 $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
28 public function dataInNamespace() {
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 ),
42 * @dataProvider dataInNamespace
44 public function testInNamespace( $title, $ns, $expectedBool ) {
45 $title = Title
::newFromText( $title );
46 $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) );
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
) ) );
57 public function dataHasSubjectNamespace() {
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 ),
71 * @dataProvider dataHasSubjectNamespace
73 public function testHasSubjectNamespace( $title, $ns, $expectedBool ) {
74 $title = Title
::newFromText( $title );
75 $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) );
78 public function dataIsCssOrJsPage() {
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 ),
99 * @dataProvider dataIsCssOrJsPage
101 public function testIsCssOrJsPage( $title, $expectedBool ) {
102 $title = Title
::newFromText( $title );
103 $this->assertEquals( $expectedBool, $title->isCssOrJsPage() );
107 public function dataIsCssJsSubpage() {
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 ),
126 * @dataProvider dataIsCssJsSubpage
128 public function testIsCssJsSubpage( $title, $expectedBool ) {
129 $title = Title
::newFromText( $title );
130 $this->assertEquals( $expectedBool, $title->isCssJsSubpage() );
133 public function dataIsCssSubpage() {
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 ),
146 * @dataProvider dataIsCssSubpage
148 public function testIsCssSubpage( $title, $expectedBool ) {
149 $title = Title
::newFromText( $title );
150 $this->assertEquals( $expectedBool, $title->isCssSubpage() );
153 public function dataIsJsSubpage() {
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 ),
166 * @dataProvider dataIsJsSubpage
168 public function testIsJsSubpage( $title, $expectedBool ) {
169 $title = Title
::newFromText( $title );
170 $this->assertEquals( $expectedBool, $title->isJsSubpage() );
173 public function dataIsWikitextPage() {
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 ),
194 * @dataProvider dataIsWikitextPage
196 public function testIsWikitextPage( $title, $expectedBool ) {
197 $title = Title
::newFromText( $title );
198 $this->assertEquals( $expectedBool, $title->isWikitextPage() );