MediaWiki  REL1_19
TitleTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class TitleTest extends MediaWikiTestCase {
00004 
00005         function testLegalChars() {
00006                 $titlechars = Title::legalChars();
00007 
00008                 foreach ( range( 1, 255 ) as $num ) {
00009                         $chr = chr( $num );
00010                         if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
00011                                 $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
00012                         } else {
00013                                 $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
00014                         }
00015                 }
00016         }
00017 
00021         function testBug31100FixSpecialName( $text, $expectedParam ) {
00022                 $title = Title::newFromText( $text );
00023                 $fixed = $title->fixSpecialName();
00024                 $stuff = explode( '/', $fixed->getDbKey(), 2 );
00025                 if ( count( $stuff ) == 2 ) {
00026                         $par = $stuff[1];
00027                 } else {
00028                         $par = null;
00029                 }
00030                 $this->assertEquals( $expectedParam, $par, "Bug 31100 regression check: Title->fixSpecialName() should preserve parameter" );
00031         }
00032 
00033         function dataBug31100() {
00034                 return array(
00035                         array( 'Special:Version', null ),
00036                         array( 'Special:Version/', '' ),
00037                         array( 'Special:Version/param', 'param' ),
00038                 );
00039         }
00040         
00050         function testIsValidMoveOperation( $source, $target, $expected ) {
00051                 $title = Title::newFromText( $source );
00052                 $nt = Title::newFromText( $target );
00053                 $errors = $title->isValidMoveOperation( $nt, false );
00054                 if ( $expected === true ) {
00055                         $this->assertTrue( $errors );
00056                 } else {
00057                         $errors = $this->flattenErrorsArray( $errors );
00058                         foreach ( (array)$expected as $error ) {
00059                                 $this->assertContains( $error, $errors );
00060                         }
00061                 }
00062         }
00063         
00064         function flattenErrorsArray( $errors ) {
00065                 $result = array();
00066                 foreach ( $errors as $error ) {
00067                         $result[] = $error[0];
00068                 }
00069                 return $result;
00070         }
00071         
00072         function dataTestIsValidMoveOperation() {
00073                 return array( 
00074                         array( 'Test', 'Test', 'selfmove' ),
00075                         array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' )
00076                 );
00077         }
00078         
00079         
00080 }