/**
* @group Database
* ^--- needed for language cache stuff
+ *
+ * @group Title
*/
class TitleTest extends MediaWikiTestCase {
protected function setUp() {
foreach ( range( 1, 255 ) as $num ) {
$chr = chr( $num );
if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
- $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
+ $this->assertFalse(
+ (bool)preg_match( "/[$titlechars]/", $chr ),
+ "chr($num) = $chr is not a valid titlechar"
+ );
} else {
- $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
+ $this->assertTrue(
+ (bool)preg_match( "/[$titlechars]/", $chr ),
+ "chr($num) = $chr is a valid titlechar"
+ );
}
}
}
* See also mediawiki.Title.test.js
* @covers Title::secureAndSplit
* @todo This method should be split into 2 separate tests each with a provider
+ * @note: This mainly tests MediaWikiTitleCodec::parseTitle().
*/
public function testSecureAndSplit() {
$this->setMwGlobals( array(
'A \'B\'',
'.com',
'~',
+ '#',
'"',
'\'',
'Talk:Sandbox',
'Foo/.../Sandbox',
'Sandbox/...',
'A~~',
+ ':A',
// Length is 256 total, but only title part matters
'Category:' . str_repeat( 'x', 248 ),
str_repeat( 'x', 252 ),
'remotetestiw: Talk: # anchor',
'remotetestiw: #bar',
'remotetestiw: Talk:',
- 'remotetestiw: Talk: Foo'
+ 'remotetestiw: Talk: Foo',
+ 'localtestiw:remotetestiw:',
+ 'localtestiw:remotetestiw:foo'
) as $text ) {
$this->assertInstanceOf( 'Title', Title::newFromText( $text ), "Valid: $text" );
}
str_repeat( 'x', 256 ),
// Namespace prefix without actual title
'Talk:',
+ 'Talk:#',
'Category: ',
'Category: #bar',
// interwiki prefix
} else {
$par = null;
}
- $this->assertEquals( $expectedParam, $par, "Bug 31100 regression check: Title->fixSpecialName() should preserve parameter" );
+ $this->assertEquals(
+ $expectedParam,
+ $par,
+ "Bug 31100 regression check: Title->fixSpecialName() should preserve parameter"
+ );
}
public static function provideBug31100() {
$allowableness = $expected
? " should be allowed"
: " should NOT be allowed";
- $this->assertEquals( $expected, $errors, "User action '$action' on [[$source]] $allowableness." );
+ $this->assertEquals(
+ $expected,
+ $errors,
+ "User action '$action' on [[$source]] $allowableness."
+ );
} else {
$errors = $this->flattenErrorsArray( $errors );
foreach ( (array)$expected as $error ) {
* @dataProvider provideGetPageViewLanguage
* @covers Title::getPageViewLanguage
*/
- public function testGetPageViewLanguage( $expected, $titleText, $contLang, $lang, $variant, $msg = '' ) {
+ public function testGetPageViewLanguage( $expected, $titleText, $contLang,
+ $lang, $variant, $msg = ''
+ ) {
global $wgLanguageCode, $wgContLang, $wgLang, $wgDefaultLanguageVariant, $wgAllowUserJs;
// Setup environnement for this test
array( 'User:John_Doe/subOne', 'subOne' ),
);
}
+
+ public function provideNewFromTitleValue() {
+ return array(
+ array( new TitleValue( NS_MAIN, 'Foo' ) ),
+ array( new TitleValue( NS_MAIN, 'Foo', 'bar' ) ),
+ array( new TitleValue( NS_USER, 'Hansi_Maier' ) ),
+ );
+ }
+
+ /**
+ * @dataProvider provideNewFromTitleValue
+ */
+ public function testNewFromTitleValue( TitleValue $value ) {
+ $title = Title::newFromTitleValue( $value );
+
+ $dbkey = str_replace( ' ', '_', $value->getText() );
+ $this->assertEquals( $dbkey, $title->getDBkey() );
+ $this->assertEquals( $value->getNamespace(), $title->getNamespace() );
+ $this->assertEquals( $value->getFragment(), $title->getFragment() );
+ }
+
+ public function provideGetTitleValue() {
+ return array(
+ array( 'Foo' ),
+ array( 'Foo#bar' ),
+ array( 'User:Hansi_Maier' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetTitleValue
+ */
+ public function testGetTitleValue( $text ) {
+ $title = Title::newFromText( $text );
+ $value = $title->getTitleValue();
+
+ $dbkey = str_replace( ' ', '_', $value->getText() );
+ $this->assertEquals( $title->getDBkey(), $dbkey );
+ $this->assertEquals( $title->getNamespace(), $value->getNamespace() );
+ $this->assertEquals( $title->getFragment(), $value->getFragment() );
+ }
+
+ public function provideGetFragment() {
+ return array(
+ array( 'Foo', '' ),
+ array( 'Foo#bar', 'bar' ),
+ array( 'Foo#bär', 'bär' ),
+
+ // Inner whitespace is normalized
+ array( 'Foo#bar_bar', 'bar bar' ),
+ array( 'Foo#bar bar', 'bar bar' ),
+ array( 'Foo#bar bar', 'bar bar' ),
+
+ // Leading whitespace is kept, trailing whitespace is trimmed.
+ // XXX: Is this really want we want?
+ array( 'Foo#_bar_bar_', ' bar bar' ),
+ array( 'Foo# bar bar ', ' bar bar' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetFragment
+ *
+ * @param string $full
+ * @param string $fragment
+ */
+ public function testGetFragment( $full, $fragment ) {
+ $title = Title::newFromText( $full );
+ $this->assertEquals( $fragment, $title->getFragment() );
+ }
}