2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
2010-12-28 18:17:16 +00:00
|
|
|
class TitleTest extends MediaWikiTestCase {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
function testLegalChars() {
|
|
|
|
|
$titlechars = Title::legalChars();
|
|
|
|
|
|
|
|
|
|
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" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-13 11:41:17 +00:00
|
|
|
|
2011-09-22 21:35:24 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataBug31100
|
|
|
|
|
*/
|
|
|
|
|
function testBug31100FixSpecialName( $text, $expectedParam ) {
|
|
|
|
|
$title = Title::newFromText( $text );
|
|
|
|
|
$fixed = $title->fixSpecialName();
|
|
|
|
|
$stuff = explode( '/', $fixed->getDbKey(), 2 );
|
|
|
|
|
if ( count( $stuff ) == 2 ) {
|
|
|
|
|
$par = $stuff[1];
|
|
|
|
|
} else {
|
|
|
|
|
$par = null;
|
|
|
|
|
}
|
|
|
|
|
$this->assertEquals( $expectedParam, $par, "Bug 31100 regression check: Title->fixSpecialName() should preserve parameter" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function dataBug31100() {
|
|
|
|
|
return array(
|
|
|
|
|
array( 'Special:Version', null ),
|
|
|
|
|
array( 'Special:Version/', '' ),
|
|
|
|
|
array( 'Special:Version/param', 'param' ),
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-09-29 18:35:34 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Auth-less test of Title::isValidMoveOperation
|
|
|
|
|
*
|
2011-10-02 21:07:17 +00:00
|
|
|
* @group Database
|
2011-09-29 18:35:34 +00:00
|
|
|
* @param string $source
|
|
|
|
|
* @param string $target
|
|
|
|
|
* @param array|string|true $requiredErrors
|
|
|
|
|
* @dataProvider dataTestIsValidMoveOperation
|
|
|
|
|
*/
|
|
|
|
|
function testIsValidMoveOperation( $source, $target, $expected ) {
|
|
|
|
|
$title = Title::newFromText( $source );
|
|
|
|
|
$nt = Title::newFromText( $target );
|
|
|
|
|
$errors = $title->isValidMoveOperation( $nt, false );
|
|
|
|
|
if ( $expected === true ) {
|
|
|
|
|
$this->assertTrue( $errors );
|
|
|
|
|
} else {
|
|
|
|
|
$errors = $this->flattenErrorsArray( $errors );
|
|
|
|
|
foreach ( (array)$expected as $error ) {
|
|
|
|
|
$this->assertContains( $error, $errors );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function flattenErrorsArray( $errors ) {
|
|
|
|
|
$result = array();
|
|
|
|
|
foreach ( $errors as $error ) {
|
|
|
|
|
$result[] = $error[0];
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function dataTestIsValidMoveOperation() {
|
|
|
|
|
return array(
|
|
|
|
|
array( 'Test', 'Test', 'selfmove' ),
|
|
|
|
|
array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|