2011-11-22 13:34:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class TitleMethodsTest extends MediaWikiTestCase {
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideEquals() {
|
2011-11-22 13:34:55 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'Main Page', 'Main Page', true ),
|
|
|
|
|
array( 'Main Page', 'Not The Main Page', false ),
|
|
|
|
|
array( 'Main Page', 'Project:Main Page', false ),
|
|
|
|
|
array( 'File:Example.png', 'Image:Example.png', true ),
|
|
|
|
|
array( 'Special:Version', 'Special:Version', true ),
|
|
|
|
|
array( 'Special:Version', 'Special:Recentchanges', false ),
|
|
|
|
|
array( 'Special:Version', 'Main Page', false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideEquals
|
2011-11-22 13:34:55 +00:00
|
|
|
*/
|
|
|
|
|
public function testEquals( $titleA, $titleB, $expectedBool ) {
|
|
|
|
|
$titleA = Title::newFromText( $titleA );
|
|
|
|
|
$titleB = Title::newFromText( $titleB );
|
|
|
|
|
|
assertEquals is $expected, $actual, not $actual, $expected
Fix Title related tests that are the wrong way round (noticed by Daniel Kinzler
when creating more tests, and wondering why phpunit was making error messages
that didn't make any sense!)
public static function assertEquals($expected, $actual, $message = '',
$delta = 0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE)
Change-Id: I09aeb7cb7edb8e486ccf2f54673f91cd9704cd3b
2012-04-18 12:50:39 +00:00
|
|
|
$this->assertEquals( $expectedBool, $titleA->equals( $titleB ) );
|
|
|
|
|
$this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
|
2011-11-22 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideInNamespace() {
|
2011-11-22 13:34:55 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'Main Page', NS_MAIN, true ),
|
|
|
|
|
array( 'Main Page', NS_TALK, false ),
|
|
|
|
|
array( 'Main Page', NS_USER, false ),
|
|
|
|
|
array( 'User:Foo', NS_USER, true ),
|
|
|
|
|
array( 'User:Foo', NS_USER_TALK, false ),
|
|
|
|
|
array( 'User:Foo', NS_TEMPLATE, false ),
|
|
|
|
|
array( 'User_talk:Foo', NS_USER_TALK, true ),
|
|
|
|
|
array( 'User_talk:Foo', NS_USER, false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideInNamespace
|
2011-11-22 13:34:55 +00:00
|
|
|
*/
|
|
|
|
|
public function testInNamespace( $title, $ns, $expectedBool ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
2012-05-02 17:30:09 +00:00
|
|
|
$this->assertEquals( $expectedBool, $title->inNamespace( $ns ) );
|
2011-11-22 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInNamespaces() {
|
|
|
|
|
$mainpage = Title::newFromText( 'Main Page' );
|
|
|
|
|
$this->assertTrue( $mainpage->inNamespaces( NS_MAIN, NS_USER ) );
|
|
|
|
|
$this->assertTrue( $mainpage->inNamespaces( array( NS_MAIN, NS_USER ) ) );
|
|
|
|
|
$this->assertTrue( $mainpage->inNamespaces( array( NS_USER, NS_MAIN ) ) );
|
|
|
|
|
$this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT, NS_TEMPLATE ) ) );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideHasSubjectNamespace() {
|
2011-11-22 13:34:55 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'Main Page', NS_MAIN, true ),
|
|
|
|
|
array( 'Main Page', NS_TALK, true ),
|
|
|
|
|
array( 'Main Page', NS_USER, false ),
|
|
|
|
|
array( 'User:Foo', NS_USER, true ),
|
|
|
|
|
array( 'User:Foo', NS_USER_TALK, true ),
|
|
|
|
|
array( 'User:Foo', NS_TEMPLATE, false ),
|
|
|
|
|
array( 'User_talk:Foo', NS_USER_TALK, true ),
|
|
|
|
|
array( 'User_talk:Foo', NS_USER, true ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideHasSubjectNamespace
|
2011-11-22 13:34:55 +00:00
|
|
|
*/
|
|
|
|
|
public function testHasSubjectNamespace( $title, $ns, $expectedBool ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
assertEquals is $expected, $actual, not $actual, $expected
Fix Title related tests that are the wrong way round (noticed by Daniel Kinzler
when creating more tests, and wondering why phpunit was making error messages
that didn't make any sense!)
public static function assertEquals($expected, $actual, $message = '',
$delta = 0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE)
Change-Id: I09aeb7cb7edb8e486ccf2f54673f91cd9704cd3b
2012-04-18 12:50:39 +00:00
|
|
|
$this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) );
|
2011-11-22 13:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideIsCssOrJsPage() {
|
2012-05-02 17:30:09 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'Foo', false ),
|
|
|
|
|
array( 'Foo.js', false ),
|
|
|
|
|
array( 'Foo/bar.js', false ),
|
|
|
|
|
array( 'User:Foo', false ),
|
|
|
|
|
array( 'User:Foo.js', false ),
|
|
|
|
|
array( 'User:Foo/bar.js', false ),
|
|
|
|
|
array( 'User:Foo/bar.css', false ),
|
|
|
|
|
array( 'User talk:Foo/bar.css', false ),
|
|
|
|
|
array( 'User:Foo/bar.js.xxx', false ),
|
|
|
|
|
array( 'User:Foo/bar.xxx', false ),
|
|
|
|
|
array( 'MediaWiki:Foo.js', true ),
|
|
|
|
|
array( 'MediaWiki:Foo.css', true ),
|
|
|
|
|
array( 'MediaWiki:Foo.JS', false ),
|
|
|
|
|
array( 'MediaWiki:Foo.CSS', false ),
|
|
|
|
|
array( 'MediaWiki:Foo.css.xxx', false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideIsCssOrJsPage
|
2012-05-02 17:30:09 +00:00
|
|
|
*/
|
|
|
|
|
public function testIsCssOrJsPage( $title, $expectedBool ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
$this->assertEquals( $expectedBool, $title->isCssOrJsPage() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideIsCssJsSubpage() {
|
2012-05-02 17:30:09 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'Foo', false ),
|
|
|
|
|
array( 'Foo.js', false ),
|
|
|
|
|
array( 'Foo/bar.js', false ),
|
|
|
|
|
array( 'User:Foo', false ),
|
|
|
|
|
array( 'User:Foo.js', false ),
|
|
|
|
|
array( 'User:Foo/bar.js', true ),
|
|
|
|
|
array( 'User:Foo/bar.css', true ),
|
|
|
|
|
array( 'User talk:Foo/bar.css', false ),
|
|
|
|
|
array( 'User:Foo/bar.js.xxx', false ),
|
|
|
|
|
array( 'User:Foo/bar.xxx', false ),
|
|
|
|
|
array( 'MediaWiki:Foo.js', false ),
|
|
|
|
|
array( 'User:Foo/bar.JS', false ),
|
|
|
|
|
array( 'User:Foo/bar.CSS', false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideIsCssJsSubpage
|
2012-05-02 17:30:09 +00:00
|
|
|
*/
|
|
|
|
|
public function testIsCssJsSubpage( $title, $expectedBool ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
$this->assertEquals( $expectedBool, $title->isCssJsSubpage() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideIsCssSubpage() {
|
2012-05-02 17:30:09 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'Foo', false ),
|
|
|
|
|
array( 'Foo.css', false ),
|
|
|
|
|
array( 'User:Foo', false ),
|
|
|
|
|
array( 'User:Foo.js', false ),
|
|
|
|
|
array( 'User:Foo.css', false ),
|
|
|
|
|
array( 'User:Foo/bar.js', false ),
|
|
|
|
|
array( 'User:Foo/bar.css', true ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideIsCssSubpage
|
2012-05-02 17:30:09 +00:00
|
|
|
*/
|
|
|
|
|
public function testIsCssSubpage( $title, $expectedBool ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
$this->assertEquals( $expectedBool, $title->isCssSubpage() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideIsJsSubpage() {
|
2012-05-02 17:30:09 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'Foo', false ),
|
|
|
|
|
array( 'Foo.css', false ),
|
|
|
|
|
array( 'User:Foo', false ),
|
|
|
|
|
array( 'User:Foo.js', false ),
|
|
|
|
|
array( 'User:Foo.css', false ),
|
|
|
|
|
array( 'User:Foo/bar.js', true ),
|
|
|
|
|
array( 'User:Foo/bar.css', false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideIsJsSubpage
|
2012-05-02 17:30:09 +00:00
|
|
|
*/
|
|
|
|
|
public function testIsJsSubpage( $title, $expectedBool ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
$this->assertEquals( $expectedBool, $title->isJsSubpage() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideIsWikitextPage() {
|
2012-05-02 17:30:09 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'Foo', true ),
|
|
|
|
|
array( 'Foo.js', true ),
|
|
|
|
|
array( 'Foo/bar.js', true ),
|
|
|
|
|
array( 'User:Foo', true ),
|
|
|
|
|
array( 'User:Foo.js', true ),
|
|
|
|
|
array( 'User:Foo/bar.js', false ),
|
|
|
|
|
array( 'User:Foo/bar.css', false ),
|
|
|
|
|
array( 'User talk:Foo/bar.css', true ),
|
|
|
|
|
array( 'User:Foo/bar.js.xxx', true ),
|
|
|
|
|
array( 'User:Foo/bar.xxx', true ),
|
|
|
|
|
array( 'MediaWiki:Foo.js', false ),
|
|
|
|
|
array( 'MediaWiki:Foo.css', false ),
|
|
|
|
|
array( 'MediaWiki:Foo/bar.css', false ),
|
|
|
|
|
array( 'User:Foo/bar.JS', true ),
|
|
|
|
|
array( 'User:Foo/bar.CSS', true ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideIsWikitextPage
|
2012-05-02 17:30:09 +00:00
|
|
|
*/
|
|
|
|
|
public function testIsWikitextPage( $title, $expectedBool ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
$this->assertEquals( $expectedBool, $title->isWikitextPage() );
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-22 13:34:55 +00:00
|
|
|
}
|