MediaWiki  1.23.0
TitleMethodsTest.php
Go to the documentation of this file.
1 <?php
2 
11 
12  protected function setUp() {
14 
15  parent::setUp();
16 
18  'wgExtraNamespaces',
19  array(
20  12302 => 'TEST-JS',
21  12303 => 'TEST-JS_TALK',
22  )
23  );
24 
26  'wgNamespaceContentModels',
27  array(
28  12302 => CONTENT_MODEL_JAVASCRIPT,
29  )
30  );
31 
32  MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
33  $wgContLang->resetNamespaces(); # reset namespace cache
34  }
35 
36  protected function tearDown() {
38 
39  parent::tearDown();
40 
41  MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
42  $wgContLang->resetNamespaces(); # reset namespace cache
43  }
44 
45  public static function provideEquals() {
46  return array(
47  array( 'Main Page', 'Main Page', true ),
48  array( 'Main Page', 'Not The Main Page', false ),
49  array( 'Main Page', 'Project:Main Page', false ),
50  array( 'File:Example.png', 'Image:Example.png', true ),
51  array( 'Special:Version', 'Special:Version', true ),
52  array( 'Special:Version', 'Special:Recentchanges', false ),
53  array( 'Special:Version', 'Main Page', false ),
54  );
55  }
56 
61  public function testEquals( $titleA, $titleB, $expectedBool ) {
62  $titleA = Title::newFromText( $titleA );
63  $titleB = Title::newFromText( $titleB );
64 
65  $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) );
66  $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
67  }
68 
69  public static function provideInNamespace() {
70  return array(
71  array( 'Main Page', NS_MAIN, true ),
72  array( 'Main Page', NS_TALK, false ),
73  array( 'Main Page', NS_USER, false ),
74  array( 'User:Foo', NS_USER, true ),
75  array( 'User:Foo', NS_USER_TALK, false ),
76  array( 'User:Foo', NS_TEMPLATE, false ),
77  array( 'User_talk:Foo', NS_USER_TALK, true ),
78  array( 'User_talk:Foo', NS_USER, false ),
79  );
80  }
81 
86  public function testInNamespace( $title, $ns, $expectedBool ) {
88  $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) );
89  }
90 
94  public function testInNamespaces() {
95  $mainpage = Title::newFromText( 'Main Page' );
96  $this->assertTrue( $mainpage->inNamespaces( NS_MAIN, NS_USER ) );
97  $this->assertTrue( $mainpage->inNamespaces( array( NS_MAIN, NS_USER ) ) );
98  $this->assertTrue( $mainpage->inNamespaces( array( NS_USER, NS_MAIN ) ) );
99  $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT, NS_TEMPLATE ) ) );
100  }
101 
102  public static function provideHasSubjectNamespace() {
103  return array(
104  array( 'Main Page', NS_MAIN, true ),
105  array( 'Main Page', NS_TALK, true ),
106  array( 'Main Page', NS_USER, false ),
107  array( 'User:Foo', NS_USER, true ),
108  array( 'User:Foo', NS_USER_TALK, true ),
109  array( 'User:Foo', NS_TEMPLATE, false ),
110  array( 'User_talk:Foo', NS_USER_TALK, true ),
111  array( 'User_talk:Foo', NS_USER, true ),
112  );
113  }
114 
119  public function testHasSubjectNamespace( $title, $ns, $expectedBool ) {
121  $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) );
122  }
123 
124  public function dataGetContentModel() {
125  return array(
126  array( 'Help:Foo', CONTENT_MODEL_WIKITEXT ),
127  array( 'Help:Foo.js', CONTENT_MODEL_WIKITEXT ),
128  array( 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT ),
129  array( 'User:Foo', CONTENT_MODEL_WIKITEXT ),
130  array( 'User:Foo.js', CONTENT_MODEL_WIKITEXT ),
131  array( 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ),
132  array( 'User:Foo/bar.css', CONTENT_MODEL_CSS ),
133  array( 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT ),
134  array( 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT ),
135  array( 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT ),
136  array( 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT ),
137  array( 'MediaWiki:Foo.css', CONTENT_MODEL_CSS ),
138  array( 'MediaWiki:Foo/bar.css', CONTENT_MODEL_CSS ),
139  array( 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT ),
140  array( 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT ),
141  array( 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT ),
142  array( 'TEST-JS:Foo', CONTENT_MODEL_JAVASCRIPT ),
143  array( 'TEST-JS:Foo.js', CONTENT_MODEL_JAVASCRIPT ),
144  array( 'TEST-JS:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ),
145  array( 'TEST-JS_TALK:Foo.js', CONTENT_MODEL_WIKITEXT ),
146  );
147  }
148 
153  public function testGetContentModel( $title, $expectedModelId ) {
155  $this->assertEquals( $expectedModelId, $title->getContentModel() );
156  }
157 
162  public function testHasContentModel( $title, $expectedModelId ) {
164  $this->assertTrue( $title->hasContentModel( $expectedModelId ) );
165  }
166 
167  public static function provideIsCssOrJsPage() {
168  return array(
169  array( 'Help:Foo', false ),
170  array( 'Help:Foo.js', false ),
171  array( 'Help:Foo/bar.js', false ),
172  array( 'User:Foo', false ),
173  array( 'User:Foo.js', false ),
174  array( 'User:Foo/bar.js', false ),
175  array( 'User:Foo/bar.css', false ),
176  array( 'User talk:Foo/bar.css', false ),
177  array( 'User:Foo/bar.js.xxx', false ),
178  array( 'User:Foo/bar.xxx', false ),
179  array( 'MediaWiki:Foo.js', true ),
180  array( 'MediaWiki:Foo.css', true ),
181  array( 'MediaWiki:Foo.JS', false ),
182  array( 'MediaWiki:Foo.CSS', false ),
183  array( 'MediaWiki:Foo.css.xxx', false ),
184  array( 'TEST-JS:Foo', false ),
185  array( 'TEST-JS:Foo.js', false ),
186  );
187  }
188 
193  public function testIsCssOrJsPage( $title, $expectedBool ) {
195  $this->assertEquals( $expectedBool, $title->isCssOrJsPage() );
196  }
197 
198  public static function provideIsCssJsSubpage() {
199  return array(
200  array( 'Help:Foo', false ),
201  array( 'Help:Foo.js', false ),
202  array( 'Help:Foo/bar.js', false ),
203  array( 'User:Foo', false ),
204  array( 'User:Foo.js', false ),
205  array( 'User:Foo/bar.js', true ),
206  array( 'User:Foo/bar.css', true ),
207  array( 'User talk:Foo/bar.css', false ),
208  array( 'User:Foo/bar.js.xxx', false ),
209  array( 'User:Foo/bar.xxx', false ),
210  array( 'MediaWiki:Foo.js', false ),
211  array( 'User:Foo/bar.JS', false ),
212  array( 'User:Foo/bar.CSS', false ),
213  array( 'TEST-JS:Foo', false ),
214  array( 'TEST-JS:Foo.js', false ),
215  );
216  }
217 
222  public function testIsCssJsSubpage( $title, $expectedBool ) {
224  $this->assertEquals( $expectedBool, $title->isCssJsSubpage() );
225  }
226 
227  public static function provideIsCssSubpage() {
228  return array(
229  array( 'Help:Foo', false ),
230  array( 'Help:Foo.css', false ),
231  array( 'User:Foo', false ),
232  array( 'User:Foo.js', false ),
233  array( 'User:Foo.css', false ),
234  array( 'User:Foo/bar.js', false ),
235  array( 'User:Foo/bar.css', true ),
236  );
237  }
238 
243  public function testIsCssSubpage( $title, $expectedBool ) {
245  $this->assertEquals( $expectedBool, $title->isCssSubpage() );
246  }
247 
248  public static function provideIsJsSubpage() {
249  return array(
250  array( 'Help:Foo', false ),
251  array( 'Help:Foo.css', false ),
252  array( 'User:Foo', false ),
253  array( 'User:Foo.js', false ),
254  array( 'User:Foo.css', false ),
255  array( 'User:Foo/bar.js', true ),
256  array( 'User:Foo/bar.css', false ),
257  );
258  }
259 
264  public function testIsJsSubpage( $title, $expectedBool ) {
266  $this->assertEquals( $expectedBool, $title->isJsSubpage() );
267  }
268 
269  public static function provideIsWikitextPage() {
270  return array(
271  array( 'Help:Foo', true ),
272  array( 'Help:Foo.js', true ),
273  array( 'Help:Foo/bar.js', true ),
274  array( 'User:Foo', true ),
275  array( 'User:Foo.js', true ),
276  array( 'User:Foo/bar.js', false ),
277  array( 'User:Foo/bar.css', false ),
278  array( 'User talk:Foo/bar.css', true ),
279  array( 'User:Foo/bar.js.xxx', true ),
280  array( 'User:Foo/bar.xxx', true ),
281  array( 'MediaWiki:Foo.js', false ),
282  array( 'MediaWiki:Foo.css', false ),
283  array( 'MediaWiki:Foo/bar.css', false ),
284  array( 'User:Foo/bar.JS', true ),
285  array( 'User:Foo/bar.CSS', true ),
286  array( 'TEST-JS:Foo', false ),
287  array( 'TEST-JS:Foo.js', false ),
288  array( 'TEST-JS_TALK:Foo.js', true ),
289  );
290  }
291 
296  public function testIsWikitextPage( $title, $expectedBool ) {
298  $this->assertEquals( $expectedBool, $title->isWikitextPage() );
299  }
300 }
TitleMethodsTest\testHasSubjectNamespace
testHasSubjectNamespace( $title, $ns, $expectedBool)
@dataProvider provideHasSubjectNamespace @covers Title::hasSubjectNamespace
Definition: TitleMethodsTest.php:119
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
TitleMethodsTest\testEquals
testEquals( $titleA, $titleB, $expectedBool)
@dataProvider provideEquals @covers Title::equals
Definition: TitleMethodsTest.php:61
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:369
TitleMethodsTest\provideIsCssSubpage
static provideIsCssSubpage()
Definition: TitleMethodsTest.php:227
TitleMethodsTest\provideIsCssJsSubpage
static provideIsCssJsSubpage()
Definition: TitleMethodsTest.php:198
TitleMethodsTest\testHasContentModel
testHasContentModel( $title, $expectedModelId)
@dataProvider dataGetContentModel @covers Title::hasContentModel
Definition: TitleMethodsTest.php:162
TitleMethodsTest\provideIsWikitextPage
static provideIsWikitextPage()
Definition: TitleMethodsTest.php:269
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:285
NS_TEMPLATE
const NS_TEMPLATE
Definition: Defines.php:89
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
TitleMethodsTest\testInNamespaces
testInNamespaces()
@covers Title::inNamespaces
Definition: TitleMethodsTest.php:94
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:283
TitleMethodsTest
@group ContentHandler @group Database
Definition: TitleMethodsTest.php:10
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
TitleMethodsTest\testIsWikitextPage
testIsWikitextPage( $title, $expectedBool)
@dataProvider provideIsWikitextPage @covers Title::isWikitextPage
Definition: TitleMethodsTest.php:296
NS_MAIN
const NS_MAIN
Definition: Defines.php:79
NS_PROJECT
const NS_PROJECT
Definition: Defines.php:83
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
TitleMethodsTest\testIsJsSubpage
testIsJsSubpage( $title, $expectedBool)
@dataProvider provideIsJsSubpage @covers Title::isJsSubpage
Definition: TitleMethodsTest.php:264
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
TitleMethodsTest\testGetContentModel
testGetContentModel( $title, $expectedModelId)
@dataProvider dataGetContentModel @covers Title::getContentModel
Definition: TitleMethodsTest.php:153
TitleMethodsTest\provideIsCssOrJsPage
static provideIsCssOrJsPage()
Definition: TitleMethodsTest.php:167
TitleMethodsTest\testIsCssSubpage
testIsCssSubpage( $title, $expectedBool)
@dataProvider provideIsCssSubpage @covers Title::isCssSubpage
Definition: TitleMethodsTest.php:243
TitleMethodsTest\provideEquals
static provideEquals()
Definition: TitleMethodsTest.php:45
TitleMethodsTest\tearDown
tearDown()
Definition: TitleMethodsTest.php:36
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
function
when a variable name is used in a function
Definition: design.txt:93
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:82
TitleMethodsTest\provideHasSubjectNamespace
static provideHasSubjectNamespace()
Definition: TitleMethodsTest.php:102
TitleMethodsTest\provideInNamespace
static provideInNamespace()
Definition: TitleMethodsTest.php:69
TitleMethodsTest\dataGetContentModel
dataGetContentModel()
Definition: TitleMethodsTest.php:124
TitleMethodsTest\testIsCssOrJsPage
testIsCssOrJsPage( $title, $expectedBool)
@dataProvider provideIsCssOrJsPage @covers Title::isCssOrJsPage
Definition: TitleMethodsTest.php:193
TitleMethodsTest\setUp
setUp()
Definition: TitleMethodsTest.php:12
MWNamespace\getCanonicalNamespaces
static getCanonicalNamespaces( $rebuild=false)
Returns array of all defined namespaces with their canonical (English) names.
Definition: Namespace.php:218
NS_USER
const NS_USER
Definition: Defines.php:81
NS_TALK
const NS_TALK
Definition: Defines.php:80
TitleMethodsTest\provideIsJsSubpage
static provideIsJsSubpage()
Definition: TitleMethodsTest.php:248
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:284
TitleMethodsTest\testInNamespace
testInNamespace( $title, $ns, $expectedBool)
@dataProvider provideInNamespace @covers Title::inNamespace
Definition: TitleMethodsTest.php:86
TitleMethodsTest\testIsCssJsSubpage
testIsCssJsSubpage( $title, $expectedBool)
@dataProvider provideIsCssJsSubpage @covers Title::isCssJsSubpage
Definition: TitleMethodsTest.php:222