MediaWiki  1.31.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  [
20  12302 => 'TEST-JS',
21  12303 => 'TEST-JS_TALK',
22  ]
23  );
24 
26  'wgNamespaceContentModels',
27  [
28  12302 => CONTENT_MODEL_JAVASCRIPT,
29  ]
30  );
31 
33  $wgContLang->resetNamespaces(); # reset namespace cache
34  }
35 
36  protected function tearDown() {
38 
39  parent::tearDown();
40 
42  $wgContLang->resetNamespaces(); # reset namespace cache
43  }
44 
46  return [
47  [ 'Main Page', 'Main Page', true ],
48  [ 'Main Page', 'Not The Main Page', false ],
49  [ 'Main Page', 'Project:Main Page', false ],
50  [ 'File:Example.png', 'Image:Example.png', true ],
51  [ 'Special:Version', 'Special:Version', true ],
52  [ 'Special:Version', 'Special:Recentchanges', false ],
53  [ '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 [
71  [ 'Main Page', NS_MAIN, true ],
72  [ 'Main Page', NS_TALK, false ],
73  [ 'Main Page', NS_USER, false ],
74  [ 'User:Foo', NS_USER, true ],
75  [ 'User:Foo', NS_USER_TALK, false ],
76  [ 'User:Foo', NS_TEMPLATE, false ],
77  [ 'User_talk:Foo', NS_USER_TALK, true ],
78  [ '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( [ NS_MAIN, NS_USER ] ) );
98  $this->assertTrue( $mainpage->inNamespaces( [ NS_USER, NS_MAIN ] ) );
99  $this->assertFalse( $mainpage->inNamespaces( [ NS_PROJECT, NS_TEMPLATE ] ) );
100  }
101 
102  public static function provideHasSubjectNamespace() {
103  return [
104  [ 'Main Page', NS_MAIN, true ],
105  [ 'Main Page', NS_TALK, true ],
106  [ 'Main Page', NS_USER, false ],
107  [ 'User:Foo', NS_USER, true ],
108  [ 'User:Foo', NS_USER_TALK, true ],
109  [ 'User:Foo', NS_TEMPLATE, false ],
110  [ 'User_talk:Foo', NS_USER_TALK, true ],
111  [ '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 [
126  [ 'Help:Foo', CONTENT_MODEL_WIKITEXT ],
127  [ 'Help:Foo.js', CONTENT_MODEL_WIKITEXT ],
128  [ 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT ],
129  [ 'User:Foo', CONTENT_MODEL_WIKITEXT ],
130  [ 'User:Foo.js', CONTENT_MODEL_WIKITEXT ],
131  [ 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ],
132  [ 'User:Foo/bar.css', CONTENT_MODEL_CSS ],
133  [ 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT ],
134  [ 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT ],
135  [ 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT ],
136  [ 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT ],
137  [ 'MediaWiki:Foo.css', CONTENT_MODEL_CSS ],
138  [ 'MediaWiki:Foo/bar.css', CONTENT_MODEL_CSS ],
139  [ 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT ],
140  [ 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT ],
141  [ 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT ],
142  [ 'TEST-JS:Foo', CONTENT_MODEL_JAVASCRIPT ],
143  [ 'TEST-JS:Foo.js', CONTENT_MODEL_JAVASCRIPT ],
144  [ 'TEST-JS:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ],
145  [ '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 provideIsSiteConfigPage() {
168  return [
169  [ 'Help:Foo', false ],
170  [ 'Help:Foo.js', false ],
171  [ 'Help:Foo/bar.js', false ],
172  [ 'User:Foo', false ],
173  [ 'User:Foo.js', false ],
174  [ 'User:Foo/bar.js', false ],
175  [ 'User:Foo/bar.json', false ],
176  [ 'User:Foo/bar.css', false ],
177  [ 'User:Foo/bar.JS', false ],
178  [ 'User:Foo/bar.JSON', false ],
179  [ 'User:Foo/bar.CSS', false ],
180  [ 'User talk:Foo/bar.css', false ],
181  [ 'User:Foo/bar.js.xxx', false ],
182  [ 'User:Foo/bar.xxx', false ],
183  [ 'MediaWiki:Foo.js', true ],
184  [ 'MediaWiki:Foo.json', true ],
185  [ 'MediaWiki:Foo.css', true ],
186  [ 'MediaWiki:Foo.JS', false ],
187  [ 'MediaWiki:Foo.JSON', false ],
188  [ 'MediaWiki:Foo.CSS', false ],
189  [ 'MediaWiki:Foo/bar.css', true ],
190  [ 'MediaWiki:Foo.css.xxx', false ],
191  [ 'TEST-JS:Foo', false ],
192  [ 'TEST-JS:Foo.js', false ],
193  ];
194  }
195 
200  public function testSiteConfigPage( $title, $expectedBool ) {
202  $this->assertEquals( $expectedBool, $title->isSiteConfigPage() );
203  }
204 
205  public static function provideIsUserConfigPage() {
206  return [
207  [ 'Help:Foo', false ],
208  [ 'Help:Foo.js', false ],
209  [ 'Help:Foo/bar.js', false ],
210  [ 'User:Foo', false ],
211  [ 'User:Foo.js', false ],
212  [ 'User:Foo/bar.js', true ],
213  [ 'User:Foo/bar.JS', false ],
214  [ 'User:Foo/bar.json', true ],
215  [ 'User:Foo/bar.JSON', false ],
216  [ 'User:Foo/bar.css', true ],
217  [ 'User:Foo/bar.CSS', false ],
218  [ 'User talk:Foo/bar.css', false ],
219  [ 'User:Foo/bar.js.xxx', false ],
220  [ 'User:Foo/bar.xxx', false ],
221  [ 'MediaWiki:Foo.js', false ],
222  [ 'MediaWiki:Foo.json', false ],
223  [ 'MediaWiki:Foo.css', false ],
224  [ 'MediaWiki:Foo.JS', false ],
225  [ 'MediaWiki:Foo.JSON', false ],
226  [ 'MediaWiki:Foo.CSS', false ],
227  [ 'MediaWiki:Foo.css.xxx', false ],
228  [ 'TEST-JS:Foo', false ],
229  [ 'TEST-JS:Foo.js', false ],
230  ];
231  }
232 
237  public function testIsUserConfigPage( $title, $expectedBool ) {
239  $this->assertEquals( $expectedBool, $title->isUserConfigPage() );
240  }
241 
242  public static function provideIsUserCssConfigPage() {
243  return [
244  [ 'Help:Foo', false ],
245  [ 'Help:Foo.css', false ],
246  [ 'User:Foo', false ],
247  [ 'User:Foo.js', false ],
248  [ 'User:Foo.json', false ],
249  [ 'User:Foo.css', false ],
250  [ 'User:Foo/bar.js', false ],
251  [ 'User:Foo/bar.json', false ],
252  [ 'User:Foo/bar.css', true ],
253  ];
254  }
255 
260  public function testIsUserCssConfigPage( $title, $expectedBool ) {
262  $this->assertEquals( $expectedBool, $title->isUserCssConfigPage() );
263  }
264 
265  public static function provideIsUserJsConfigPage() {
266  return [
267  [ 'Help:Foo', false ],
268  [ 'Help:Foo.css', false ],
269  [ 'User:Foo', false ],
270  [ 'User:Foo.js', false ],
271  [ 'User:Foo.json', false ],
272  [ 'User:Foo.css', false ],
273  [ 'User:Foo/bar.js', true ],
274  [ 'User:Foo/bar.json', false ],
275  [ 'User:Foo/bar.css', false ],
276  ];
277  }
278 
283  public function testIsUserJsConfigPage( $title, $expectedBool ) {
285  $this->assertEquals( $expectedBool, $title->isUserJsConfigPage() );
286  }
287 
288  public static function provideIsWikitextPage() {
289  return [
290  [ 'Help:Foo', true ],
291  [ 'Help:Foo.js', true ],
292  [ 'Help:Foo/bar.js', true ],
293  [ 'User:Foo', true ],
294  [ 'User:Foo.js', true ],
295  [ 'User:Foo/bar.js', false ],
296  [ 'User:Foo/bar.json', false ],
297  [ 'User:Foo/bar.css', false ],
298  [ 'User talk:Foo/bar.css', true ],
299  [ 'User:Foo/bar.js.xxx', true ],
300  [ 'User:Foo/bar.xxx', true ],
301  [ 'MediaWiki:Foo.js', false ],
302  [ 'User:Foo/bar.JS', true ],
303  [ 'User:Foo/bar.JSON', true ],
304  [ 'User:Foo/bar.CSS', true ],
305  [ 'MediaWiki:Foo.json', false ],
306  [ 'MediaWiki:Foo.css', false ],
307  [ 'MediaWiki:Foo.JS', true ],
308  [ 'MediaWiki:Foo.JSON', true ],
309  [ 'MediaWiki:Foo.CSS', true ],
310  [ 'MediaWiki:Foo.css.xxx', true ],
311  [ 'TEST-JS:Foo', false ],
312  [ 'TEST-JS:Foo.js', false ],
313  ];
314  }
315 
320  public function testIsWikitextPage( $title, $expectedBool ) {
322  $this->assertEquals( $expectedBool, $title->isWikitextPage() );
323  }
324 
325  public static function provideGetOtherPage() {
326  return [
327  [ 'Main Page', 'Talk:Main Page' ],
328  [ 'Talk:Main Page', 'Main Page' ],
329  [ 'Help:Main Page', 'Help talk:Main Page' ],
330  [ 'Help talk:Main Page', 'Help:Main Page' ],
331  [ 'Special:FooBar', null ],
332  [ 'Media:File.jpg', null ],
333  ];
334  }
335 
343  public function testGetOtherPage( $text, $expected ) {
344  if ( $expected === null ) {
345  $this->setExpectedException( MWException::class );
346  }
347 
348  $title = Title::newFromText( $text );
349  $this->assertEquals( $expected, $title->getOtherPage()->getPrefixedText() );
350  }
351 
355  public function testClearCaches() {
356  $linkCache = LinkCache::singleton();
357 
358  $title1 = Title::newFromText( 'Foo' );
359  $linkCache->addGoodLinkObj( 23, $title1 );
360 
362 
363  $title2 = Title::newFromText( 'Foo' );
364  $this->assertNotSame( $title1, $title2, 'title cache should be empty' );
365  $this->assertEquals( 0, $linkCache->getGoodLinkID( 'Foo' ), 'link cache should be empty' );
366  }
367 }
function
when a variable name is used in a function
Definition: design.txt:93
TitleMethodsTest\testHasSubjectNamespace
testHasSubjectNamespace( $title, $ns, $expectedBool)
provideHasSubjectNamespace Title::hasSubjectNamespace
Definition: TitleMethodsTest.php:119
TitleMethodsTest\testClearCaches
testClearCaches()
Title::clearCaches.
Definition: TitleMethodsTest.php:355
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:273
TitleMethodsTest\testEquals
testEquals( $titleA, $titleB, $expectedBool)
provideEquals Title::equals
Definition: TitleMethodsTest.php:61
TitleMethodsTest\provideGetOtherPage
static provideGetOtherPage()
Definition: TitleMethodsTest.php:325
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:813
TitleMethodsTest\provideIsUserCssConfigPage
static provideIsUserCssConfigPage()
Definition: TitleMethodsTest.php:242
TitleMethodsTest\testHasContentModel
testHasContentModel( $title, $expectedModelId)
dataGetContentModel Title::hasContentModel
Definition: TitleMethodsTest.php:162
Title\clearCaches
static clearCaches()
Text form (spaces not underscores) of the main part.
Definition: Title.php:3579
TitleMethodsTest\provideIsWikitextPage
static provideIsWikitextPage()
Definition: TitleMethodsTest.php:288
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:238
NS_TEMPLATE
const NS_TEMPLATE
Definition: Defines.php:75
TitleMethodsTest\provideIsUserConfigPage
static provideIsUserConfigPage()
Definition: TitleMethodsTest.php:205
TitleMethodsTest\provideIsUserJsConfigPage
static provideIsUserJsConfigPage()
Definition: TitleMethodsTest.php:265
TitleMethodsTest\testInNamespaces
testInNamespaces()
Title::inNamespaces.
Definition: TitleMethodsTest.php:94
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:236
TitleMethodsTest
ContentHandler 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)
provideIsWikitextPage Title::isWikitextPage
Definition: TitleMethodsTest.php:320
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
TitleMethodsTest\provideIsSiteConfigPage
static provideIsSiteConfigPage()
Definition: TitleMethodsTest.php:167
NS_MAIN
const NS_MAIN
Definition: Defines.php:65
MWNamespace\clearCaches
static clearCaches()
Clear internal caches.
Definition: MWNamespace.php:76
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
NS_PROJECT
const NS_PROJECT
Definition: Defines.php:69
TitleMethodsTest\testGetOtherPage
testGetOtherPage( $text, $expected)
provideGetOtherpage Title::getOtherPage
Definition: TitleMethodsTest.php:343
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)
dataGetContentModel Title::getContentModel
Definition: TitleMethodsTest.php:153
TitleMethodsTest\testIsUserJsConfigPage
testIsUserJsConfigPage( $title, $expectedBool)
provideIsUserJsConfigPage Title::isUserJsConfigPage
Definition: TitleMethodsTest.php:283
TitleMethodsTest\provideEquals
static provideEquals()
Definition: TitleMethodsTest.php:45
TitleMethodsTest\tearDown
tearDown()
Definition: TitleMethodsTest.php:36
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:68
TitleMethodsTest\provideHasSubjectNamespace
static provideHasSubjectNamespace()
Definition: TitleMethodsTest.php:102
TitleMethodsTest\provideInNamespace
static provideInNamespace()
Definition: TitleMethodsTest.php:69
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
TitleMethodsTest\dataGetContentModel
dataGetContentModel()
Definition: TitleMethodsTest.php:124
TitleMethodsTest\setUp
setUp()
Definition: TitleMethodsTest.php:12
TitleMethodsTest\testIsUserCssConfigPage
testIsUserCssConfigPage( $title, $expectedBool)
provideIsUserCssConfigPage Title::isUserCssConfigPage
Definition: TitleMethodsTest.php:260
LinkCache\singleton
static singleton()
Get an instance of this class.
Definition: LinkCache.php:67
public
we sometimes make exceptions for this Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally NO WARRANTY BECAUSE THE PROGRAM IS LICENSED FREE OF THERE IS NO WARRANTY FOR THE TO THE EXTENT PERMITTED BY APPLICABLE LAW EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND OR OTHER PARTIES PROVIDE THE PROGRAM AS IS WITHOUT WARRANTY OF ANY EITHER EXPRESSED OR BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU SHOULD THE PROGRAM PROVE YOU ASSUME THE COST OF ALL NECESSARY REPAIR OR CORRECTION IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT OR ANY OTHER PARTY WHO MAY MODIFY AND OR REDISTRIBUTE THE PROGRAM AS PERMITTED BE LIABLE TO YOU FOR INCLUDING ANY INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new and you want it to be of the greatest possible use to the public
Definition: COPYING.txt:284
NS_USER
const NS_USER
Definition: Defines.php:67
TitleMethodsTest\testSiteConfigPage
testSiteConfigPage( $title, $expectedBool)
provideIsSiteConfigPage Title::isSiteConfigPage
Definition: TitleMethodsTest.php:200
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1987
NS_TALK
const NS_TALK
Definition: Defines.php:66
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:237
TitleMethodsTest\testInNamespace
testInNamespace( $title, $ns, $expectedBool)
provideInNamespace Title::inNamespace
Definition: TitleMethodsTest.php:86
TitleMethodsTest\testIsUserConfigPage
testIsUserConfigPage( $title, $expectedBool)
provideIsUserConfigPage Title::isUserConfigPage
Definition: TitleMethodsTest.php:237
$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