<?php
+/**
+ *
+ * @group Database
+ * ^--- needed for language cache stuff
+ */
class TitleTest extends MediaWikiTestCase {
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( array(
+ 'wgLanguageCode' => 'en',
+ 'wgContLang' => Language::factory( 'en' ),
+ // User language
+ 'wgLang' => Language::factory( 'en' ),
+ 'wgAllowUserJs' => false,
+ 'wgDefaultLanguageVariant' => false,
+ ) );
+ }
+
function testLegalChars() {
$titlechars = Title::legalChars();
}
/**
- * @dataProvider dataBug31100
+ * @dataProvider provideBug31100
*/
function testBug31100FixSpecialName( $text, $expectedParam ) {
$title = Title::newFromText( $text );
$this->assertEquals( $expectedParam, $par, "Bug 31100 regression check: Title->fixSpecialName() should preserve parameter" );
}
- function dataBug31100() {
+ public static function provideBug31100() {
return array(
array( 'Special:Version', null ),
array( 'Special:Version/', '' ),
* @param string $source
* @param string $target
* @param array|string|true $expected Required error
- * @dataProvider dataTestIsValidMoveOperation
+ * @dataProvider provideTestIsValidMoveOperation
*/
function testIsValidMoveOperation( $source, $target, $expected ) {
$title = Title::newFromText( $source );
return $result;
}
- function dataTestIsValidMoveOperation() {
+ public static function provideTestIsValidMoveOperation() {
return array(
array( 'Test', 'Test', 'selfmove' ),
array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' )
);
}
-
-
+
/**
* @dataProvider provideCasesForGetpageviewlanguage
*/
- function testGetpageviewlanguage( $expected, $titleText, $contLang, $lang, $variant, $msg='' ) {
- // Save globals
- global $wgContLang, $wgLang, $wgAllowUserJs, $wgLanguageCode, $wgDefaultLanguageVariant;
- $save['wgContLang'] = $wgContLang;
- $save['wgLang'] = $wgLang;
- $save['wgAllowUserJs'] = $wgAllowUserJs;
- $save['wgLanguageCode'] = $wgLanguageCode;
- $save['wgDefaultLanguageVariant'] = $wgDefaultLanguageVariant;
-
- // Setup test environnement:
- $wgContLang = Language::factory( $contLang );
- $wgLang = Language::factory( $lang );
- # To test out .js titles:
- $wgAllowUserJs = true;
+ function testGetpageviewlanguage( $expected, $titleText, $contLang, $lang, $variant, $msg = '' ) {
+ global $wgLanguageCode, $wgContLang, $wgLang, $wgDefaultLanguageVariant, $wgAllowUserJs;
+
+ // Setup environnement for this test
$wgLanguageCode = $contLang;
+ $wgContLang = Language::factory( $contLang );
+ $wgLang = Language::factory( $lang );
$wgDefaultLanguageVariant = $variant;
+ $wgAllowUserJs = true;
$title = Title::newFromText( $titleText );
$this->assertInstanceOf( 'Title', $title,
$title->getPageViewLanguage()->getCode(),
$msg
);
-
- // Restore globals
- $wgContLang = $save['wgContLang'];
- $wgLang = $save['wgLang'];
- $wgAllowUserJs = $save['wgAllowUserJs'];
- $wgLanguageCode = $save['wgLanguageCode'];
- $wgDefaultLanguageVariant = $save['wgDefaultLanguageVariant'];
}
function provideCasesForGetpageviewlanguage() {
# - wgDefaultLanguageVariant
# - Optional message
return array(
- array( 'fr', 'Main_page', 'fr', 'fr', false ),
- array( 'es', 'Main_page', 'es', 'zh-tw', false ),
- array( 'zh', 'Main_page', 'zh', 'zh-tw', false ),
+ array( 'fr', 'Help:I_need_somebody', 'fr', 'fr', false ),
+ array( 'es', 'Help:I_need_somebody', 'es', 'zh-tw', false ),
+ array( 'zh', 'Help:I_need_somebody', 'zh', 'zh-tw', false ),
- array( 'es', 'Main_page', 'es', 'zh-tw', 'zh-cn' ),
+ array( 'es', 'Help:I_need_somebody', 'es', 'zh-tw', 'zh-cn' ),
array( 'es', 'MediaWiki:About', 'es', 'zh-tw', 'zh-cn' ),
array( 'es', 'MediaWiki:About/', 'es', 'zh-tw', 'zh-cn' ),
array( 'de', 'MediaWiki:About/de', 'es', 'zh-tw', 'zh-cn' ),
array( 'en', 'User:JohnDoe/Common.js', 'es', 'zh-tw', 'zh-cn' ),
array( 'en', 'User:JohnDoe/Monobook.css', 'es', 'zh-tw', 'zh-cn' ),
- array( 'zh-cn', 'Main_page', 'zh', 'zh-tw', 'zh-cn' ),
+ array( 'zh-cn', 'Help:I_need_somebody', 'zh', 'zh-tw', 'zh-cn' ),
array( 'zh', 'MediaWiki:About', 'zh', 'zh-tw', 'zh-cn' ),
+ array( 'zh', 'MediaWiki:About/', 'zh', 'zh-tw', 'zh-cn' ),
array( 'de', 'MediaWiki:About/de', 'zh', 'zh-tw', 'zh-cn' ),
array( 'zh-cn', 'MediaWiki:About/zh-cn', 'zh', 'zh-tw', 'zh-cn' ),
array( 'zh-tw', 'MediaWiki:About/zh-tw', 'zh', 'zh-tw', 'zh-cn' ),
);
}
+
+ /**
+ * @dataProvider provideBaseTitleCases
+ */
+ function testExtractingBaseTextFromTitle( $title, $expected, $msg='' ) {
+ $title = Title::newFromText( $title );
+ $this->assertEquals( $expected,
+ $title->getBaseText(),
+ $msg
+ );
+ }
+
+ function provideBaseTitleCases() {
+ return array(
+ # Title, expected base, optional message
+ array('User:John_Doe/subOne/subTwo', 'John Doe/subOne' ),
+ array('User:Foo/Bar/Baz', 'Foo/Bar' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideRootTitleCases
+ */
+ function testExtractingRootTextFromTitle( $title, $expected, $msg='' ) {
+ $title = Title::newFromText( $title );
+ $this->assertEquals( $expected,
+ $title->getRootText(),
+ $msg
+ );
+ }
+
+ public static function provideRootTitleCases() {
+ return array(
+ # Title, expected base, optional message
+ array('User:John_Doe/subOne/subTwo', 'John Doe' ),
+ array('User:Foo/Bar/Baz', 'Foo' ),
+ );
+ }
+
+ /**
+ * @todo Handle $wgNamespacesWithSubpages cases
+ * @dataProvider provideSubpageTitleCases
+ */
+ function testExtractingSubpageTextFromTitle( $title, $expected, $msg='' ) {
+ $title = Title::newFromText( $title );
+ $this->assertEquals( $expected,
+ $title->getSubpageText(),
+ $msg
+ );
+ }
+
+ function provideSubpageTitleCases() {
+ return array(
+ # Title, expected base, optional message
+ array('User:John_Doe/subOne/subTwo', 'subTwo' ),
+ array('User:John_Doe/subOne', 'subOne' ),
+ );
+ }
+
}