MediaWiki  master
GlobalTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class GlobalTest extends MediaWikiTestCase {
00004         protected function setUp() {
00005                 parent::setUp();
00006 
00007                 $readOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" );
00008                 unlink( $readOnlyFile );
00009 
00010                 $this->setMwGlobals( array(
00011                         'wgReadOnlyFile' => $readOnlyFile,
00012                         'wgUrlProtocols' => array(
00013                                 'http://',
00014                                 'https://',
00015                                 'mailto:',
00016                                 '//',
00017                                 'file://', # Non-default
00018                         ),
00019                 ) );
00020         }
00021 
00022         protected function tearDown() {
00023                 global $wgReadOnlyFile;
00024 
00025                 if ( file_exists( $wgReadOnlyFile ) ) {
00026                         unlink( $wgReadOnlyFile );
00027                 }
00028 
00029                 parent::tearDown();
00030         }
00031 
00033         public function testWfArrayDiff2( $a, $b, $expected ) {
00034                 $this->assertEquals(
00035                         wfArrayDiff2( $a, $b), $expected
00036                 );
00037         }
00038 
00039         // @todo Provide more tests
00040         public static function provideForWfArrayDiff2() {
00041                 // $a $b $expected
00042                 return array(
00043                         array(
00044                                 array( 'a', 'b'),
00045                                 array( 'a', 'b'),
00046                                 array(),
00047                         ),
00048                         array(
00049                                 array( array( 'a'), array( 'a', 'b', 'c' )),
00050                                 array( array( 'a'), array( 'a', 'b' )),
00051                                 array( 1 => array( 'a', 'b', 'c' ) ),
00052                         ),
00053                 );
00054         }
00055 
00056         function testRandom() {
00057                 # This could hypothetically fail, but it shouldn't ;)
00058                 $this->assertFalse(
00059                         wfRandom() == wfRandom() );
00060         }
00061 
00062         function testUrlencode() {
00063                 $this->assertEquals(
00064                         "%E7%89%B9%E5%88%A5:Contributions/Foobar",
00065                         wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
00066         }
00067 
00068         function testExpandIRI() {
00069                 $this->assertEquals(
00070                         "https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
00071                         wfExpandIRI( "https://te.wikibooks.org/wiki/%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
00072         }
00073 
00074         function testReadOnlyEmpty() {
00075                 global $wgReadOnly;
00076                 $wgReadOnly = null;
00077 
00078                 $this->assertFalse( wfReadOnly() );
00079                 $this->assertFalse( wfReadOnly() );
00080         }
00081 
00082         function testReadOnlySet() {
00083                 global $wgReadOnly, $wgReadOnlyFile;
00084 
00085                 $f = fopen( $wgReadOnlyFile, "wt" );
00086                 fwrite( $f, 'Message' );
00087                 fclose( $f );
00088                 $wgReadOnly = null; # Check on $wgReadOnlyFile
00089 
00090                 $this->assertTrue( wfReadOnly() );
00091                 $this->assertTrue( wfReadOnly() ); # Check cached
00092 
00093                 unlink( $wgReadOnlyFile );
00094                 $wgReadOnly = null; # Clean cache
00095 
00096                 $this->assertFalse( wfReadOnly() );
00097                 $this->assertFalse( wfReadOnly() );
00098         }
00099 
00100         function testQuotedPrintable() {
00101                 $this->assertEquals(
00102                         "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
00103                         UserMailer::quotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
00104         }
00105 
00106         function testTime() {
00107                 $start = wfTime();
00108                 $this->assertInternalType( 'float', $start );
00109                 $end = wfTime();
00110                 $this->assertTrue( $end > $start, "Time is running backwards!" );
00111         }
00112 
00113         public static function provideArrayToCGI() {
00114                 return array(
00115                         array( array(), '' ), // empty
00116                         array( array( 'foo' => 'bar' ), 'foo=bar' ), // string test
00117                         array( array( 'foo' => '' ), 'foo=' ), // empty string test
00118                         array( array( 'foo' => 1 ), 'foo=1' ), // number test
00119                         array( array( 'foo' => true ), 'foo=1' ), // true test
00120                         array( array( 'foo' => false ), '' ), // false test
00121                         array( array( 'foo' => null ), '' ), // null test
00122                         array( array( 'foo' => 'A&B=5+6@!"\'' ), 'foo=A%26B%3D5%2B6%40%21%22%27' ), // urlencoding test
00123                         array( array( 'foo' => 'bar', 'baz' => 'is', 'asdf' => 'qwerty' ), 'foo=bar&baz=is&asdf=qwerty' ), // multi-item test
00124                         array( array( 'foo' => array( 'bar' => 'baz' ) ), 'foo%5Bbar%5D=baz' ),
00125                         array( array( 'foo' => array( 'bar' => 'baz', 'qwerty' => 'asdf' ) ), 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf' ),
00126                         array( array( 'foo' => array( 'bar', 'baz' ) ), 'foo%5B0%5D=bar&foo%5B1%5D=baz' ),
00127                         array( array( 'foo' => array( 'bar' => array( 'bar' => 'baz' ) ) ), 'foo%5Bbar%5D%5Bbar%5D=baz' ),
00128                 );
00129         }
00130 
00134         function testArrayToCGI( $array, $result ) {
00135                 $this->assertEquals( $result, wfArrayToCGI( $array ) );
00136         }
00137 
00138 
00139         function testArrayToCGI2() {
00140                 $this->assertEquals(
00141                         "baz=bar&foo=bar",
00142                         wfArrayToCGI(
00143                                 array( 'baz' => 'bar' ),
00144                                 array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
00145         }
00146 
00147         public static function provideCgiToArray() {
00148                 return array(
00149                         array( '', array() ), // empty
00150                         array( 'foo=bar', array( 'foo' => 'bar' ) ), // string
00151                         array( 'foo=', array( 'foo' => '' ) ), // empty string
00152                         array( 'foo', array( 'foo' => '' ) ), // missing =
00153                         array( 'foo=bar&qwerty=asdf', array( 'foo' => 'bar', 'qwerty' => 'asdf' ) ), // multiple value
00154                         array( 'foo=A%26B%3D5%2B6%40%21%22%27', array( 'foo' => 'A&B=5+6@!"\'' ) ), // urldecoding test
00155                         array( 'foo%5Bbar%5D=baz', array( 'foo' => array( 'bar' => 'baz' ) ) ),
00156                         array( 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf', array( 'foo' => array( 'bar' => 'baz', 'qwerty' => 'asdf' ) ) ),
00157                         array( 'foo%5B0%5D=bar&foo%5B1%5D=baz', array( 'foo' => array( 0 => 'bar', 1 => 'baz' ) ) ),
00158                         array( 'foo%5Bbar%5D%5Bbar%5D=baz', array( 'foo' => array( 'bar' => array( 'bar' => 'baz' ) ) ) ),
00159                 );
00160         }
00161 
00165         function testCgiToArray( $cgi, $result ) {
00166                 $this->assertEquals( $result, wfCgiToArray( $cgi ) );
00167         }
00168 
00169         public static function provideCgiRoundTrip() {
00170                 return array(
00171                         array( '' ),
00172                         array( 'foo=bar' ),
00173                         array( 'foo=' ),
00174                         array( 'foo=bar&baz=biz' ),
00175                         array( 'foo=A%26B%3D5%2B6%40%21%22%27' ),
00176                         array( 'foo%5Bbar%5D=baz' ),
00177                         array( 'foo%5B0%5D=bar&foo%5B1%5D=baz' ),
00178                         array( 'foo%5Bbar%5D%5Bbar%5D=baz' ),
00179                 );
00180         }
00181 
00185         function testCgiRoundTrip( $cgi ) {
00186                 $this->assertEquals( $cgi, wfArrayToCGI( wfCgiToArray( $cgi ) ) );
00187         }
00188 
00189         function testMimeTypeMatch() {
00190                 $this->assertEquals(
00191                         'text/html',
00192                         mimeTypeMatch( 'text/html',
00193                                 array( 'application/xhtml+xml' => 1.0,
00194                                        'text/html'             => 0.7,
00195                                        'text/plain'            => 0.3 ) ) );
00196                 $this->assertEquals(
00197                         'text/*',
00198                         mimeTypeMatch( 'text/html',
00199                                 array( 'image/*' => 1.0,
00200                                        'text/*'  => 0.5 ) ) );
00201                 $this->assertEquals(
00202                         '*/*',
00203                         mimeTypeMatch( 'text/html',
00204                                 array( '*/*' => 1.0 ) ) );
00205                 $this->assertNull(
00206                         mimeTypeMatch( 'text/html',
00207                                 array( 'image/png'     => 1.0,
00208                                        'image/svg+xml' => 0.5 ) ) );
00209         }
00210 
00211         function testNegotiateType() {
00212                 $this->assertEquals(
00213                         'text/html',
00214                         wfNegotiateType(
00215                                 array( 'application/xhtml+xml' => 1.0,
00216                                        'text/html'             => 0.7,
00217                                        'text/plain'            => 0.5,
00218                                        'text/*'                => 0.2 ),
00219                                 array( 'text/html'             => 1.0 ) ) );
00220                 $this->assertEquals(
00221                         'application/xhtml+xml',
00222                         wfNegotiateType(
00223                                 array( 'application/xhtml+xml' => 1.0,
00224                                        'text/html'             => 0.7,
00225                                        'text/plain'            => 0.5,
00226                                        'text/*'                => 0.2 ),
00227                                 array( 'application/xhtml+xml' => 1.0,
00228                                        'text/html'             => 0.5 ) ) );
00229                 $this->assertEquals(
00230                         'text/html',
00231                         wfNegotiateType(
00232                                 array( 'text/html'             => 1.0,
00233                                        'text/plain'            => 0.5,
00234                                        'text/*'                => 0.5,
00235                                        'application/xhtml+xml' => 0.2 ),
00236                                 array( 'application/xhtml+xml' => 1.0,
00237                                        'text/html'             => 0.5 ) ) );
00238                 $this->assertEquals(
00239                         'text/html',
00240                         wfNegotiateType(
00241                                 array( 'text/*'                => 1.0,
00242                                        'image/*'               => 0.7,
00243                                        '*/*'                   => 0.3 ),
00244                                 array( 'application/xhtml+xml' => 1.0,
00245                                        'text/html'             => 0.5 ) ) );
00246                 $this->assertNull(
00247                         wfNegotiateType(
00248                                 array( 'text/*'                => 1.0 ),
00249                                 array( 'application/xhtml+xml' => 1.0 ) ) );
00250         }
00251         
00252         function testFallbackMbstringFunctions() {
00253                 
00254                 if( !extension_loaded( 'mbstring' ) ) {
00255                         $this->markTestSkipped( "The mb_string functions must be installed to test the fallback functions" );
00256                 }
00257                 
00258                 $sampleUTF = "Östergötland_coat_of_arms.png";
00259                 
00260                 
00261                 //mb_substr
00262                 $substr_params = array(
00263                         array( 0, 0 ),
00264                         array( 5, -4 ),
00265                         array( 33 ),
00266                         array( 100, -5 ),
00267                         array( -8, 10 ),
00268                         array( 1, 1 ),
00269                         array( 2, -1 )
00270                 );
00271                 
00272                 foreach( $substr_params as $param_set ) {
00273                         $old_param_set = $param_set;
00274                         array_unshift( $param_set, $sampleUTF );
00275                         
00276                         $this->assertEquals(
00277                                 MWFunction::callArray( 'mb_substr', $param_set ),
00278                                 MWFunction::callArray( 'Fallback::mb_substr', $param_set ),
00279                                 'Fallback mb_substr with params ' . implode( ', ', $old_param_set )
00280                         );                      
00281                 }
00282                 
00283                 
00284                 //mb_strlen
00285                 $this->assertEquals(
00286                         mb_strlen( $sampleUTF ),
00287                         Fallback::mb_strlen( $sampleUTF ),
00288                         'Fallback mb_strlen'
00289                 );                      
00290                 
00291                 
00292                 //mb_str(r?)pos
00293                 $strpos_params = array(
00294                         //array( 'ter' ),
00295                         //array( 'Ö' ),
00296                         //array( 'Ö', 3 ),
00297                         //array( 'oat_', 100 ),
00298                         //array( 'c', -10 ),
00299                         //Broken for now
00300                 );
00301                 
00302                 foreach( $strpos_params as $param_set ) {
00303                         $old_param_set = $param_set;
00304                         array_unshift( $param_set, $sampleUTF );
00305                         
00306                         $this->assertEquals(
00307                                 MWFunction::callArray( 'mb_strpos', $param_set ),
00308                                 MWFunction::callArray( 'Fallback::mb_strpos', $param_set ),
00309                                 'Fallback mb_strpos with params ' . implode( ', ', $old_param_set )
00310                         );              
00311                         
00312                         $this->assertEquals(
00313                                 MWFunction::callArray( 'mb_strrpos', $param_set ),
00314                                 MWFunction::callArray( 'Fallback::mb_strrpos', $param_set ),
00315                                 'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set )
00316                         );      
00317                 }
00318                 
00319         }
00320 
00321 
00322         function testDebugFunctionTest() {
00323 
00324                 global $wgDebugLogFile, $wgDebugTimestamps;
00325 
00326                 $old_log_file = $wgDebugLogFile;
00327                 $wgDebugLogFile = tempnam( wfTempDir(), 'mw-' );
00328                 # @todo FIXME: $wgDebugTimestamps should be tested
00329                 $old_wgDebugTimestamps = $wgDebugTimestamps;
00330                 $wgDebugTimestamps = false;
00331 
00332 
00333                 wfDebug( "This is a normal string" );
00334                 $this->assertEquals( "This is a normal string", file_get_contents( $wgDebugLogFile ) );
00335                 unlink( $wgDebugLogFile );
00336 
00337                 wfDebug( "This is nöt an ASCII string" );
00338                 $this->assertEquals( "This is nöt an ASCII string", file_get_contents( $wgDebugLogFile ) );
00339                 unlink( $wgDebugLogFile );
00340 
00341 
00342                 wfDebug( "\00305This has böth UTF and control chars\003" );
00343                 $this->assertEquals( " 05This has böth UTF and control chars ", file_get_contents( $wgDebugLogFile ) );
00344                 unlink( $wgDebugLogFile );
00345 
00346                 wfDebugMem();
00347                 $this->assertGreaterThan( 5000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) );
00348                 unlink( $wgDebugLogFile );
00349 
00350                 wfDebugMem(true);
00351                 $this->assertGreaterThan( 5000000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) );
00352                 unlink( $wgDebugLogFile );
00353 
00354 
00355                 $wgDebugLogFile = $old_log_file;
00356                 $wgDebugTimestamps = $old_wgDebugTimestamps;
00357         }
00358 
00359         function testClientAcceptsGzipTest() {
00360                 
00361                 $settings = array(
00362                         'gzip' => true,
00363                         'bzip' => false,
00364                         '*' => false,
00365                         'compress, gzip' => true,
00366                         'gzip;q=1.0' => true,
00367                         'foozip' => false,
00368                         'foo*zip' => false,
00369                         'gzip;q=abcde' => true, //is this REALLY valid?
00370                         'gzip;q=12345678.9' => true,
00371                         ' gzip' => true,
00372                 );
00373                 
00374                 if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
00375                 
00376                 foreach ( $settings as $encoding => $expect ) {
00377                         $_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;
00378                         
00379                         $this->assertEquals( $expect, wfClientAcceptsGzip( true ),
00380                                 "'$encoding' => " . wfBoolToStr( $expect ) );
00381                 }
00382                 
00383                 if( isset( $old_server_setting ) ) $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
00384 
00385         }
00386         
00387         
00388         
00389         function testSwapVarsTest() {
00390         
00391 
00392                 $var1 = 1;
00393                 $var2 = 2;
00394 
00395                 $this->assertEquals( $var1, 1, 'var1 is set originally' );
00396                 $this->assertEquals( $var2, 2, 'var1 is set originally' );
00397 
00398                 swap( $var1, $var2 );
00399 
00400                 $this->assertEquals( $var1, 2, 'var1 is swapped' );
00401                 $this->assertEquals( $var2, 1, 'var2 is swapped' );
00402 
00403         }
00404 
00405 
00406         function testWfPercentTest() {
00407 
00408                 $pcts = array(
00409                         array( 6/7, '0.86%', 2, false ),
00410                         array( 3/3, '1%' ),
00411                         array( 22/7, '3.14286%', 5 ),
00412                         array( 3/6, '0.5%' ),
00413                         array( 1/3, '0%', 0 ),
00414                         array( 10/3, '0%', -1 ),
00415                         array( 3/4/5, '0.1%', 1 ),
00416                         array( 6/7*8, '6.8571428571%', 10 ),
00417                 );
00418                 
00419                 foreach( $pcts as $pct ) {
00420                         if( !isset( $pct[2] ) ) $pct[2] = 2;
00421                         if( !isset( $pct[3] ) ) $pct[3] = true;
00422                         
00423                         $this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
00424                 }
00425 
00426         }
00427 
00428 
00429         function testInStringTest() {
00430         
00431                 $this->assertTrue( in_string( 'foo', 'foobar' ), 'foo is in foobar' );
00432                 $this->assertFalse( in_string( 'Bar', 'foobar' ), 'Case-sensitive by default' );
00433                 $this->assertTrue( in_string( 'Foo', 'foobar', true ), 'Case-insensitive when asked' );
00434         
00435         }
00436 
00441         public function testWfShorthandToInteger( $shorthand, $expected ) {
00442                 $this->assertEquals( $expected,
00443                         wfShorthandToInteger( $shorthand )
00444                 );      
00445         }
00446 
00448         public static function provideShorthand() {
00449                 return array(
00450                         # Null, empty ... 
00451                         array(     '', -1),
00452                         array(   '  ', -1),
00453                         array(   null, -1),
00454 
00455                         # Failures returns 0 :(
00456                         array( 'ABCDEFG', 0 ),
00457                         array( 'Ak',      0 ),
00458 
00459                         # Int, strings with spaces
00460                         array(        1,    1 ),
00461                         array(    ' 1 ',    1 ),
00462                         array(     1023, 1023 ),
00463                         array( ' 1023 ', 1023 ),
00464 
00465                         # kilo, Mega, Giga
00466                         array(   '1k', 1024 ),
00467                         array(   '1K', 1024 ),
00468                         array(   '1m', 1024 * 1024 ),
00469                         array(   '1M', 1024 * 1024 ),
00470                         array(   '1g', 1024 * 1024 * 1024 ),
00471                         array(   '1G', 1024 * 1024 * 1024 ),
00472 
00473                         # Negatives
00474                         array(     -1,    -1 ),
00475                         array(   -500,  -500 ),
00476                         array( '-500',  -500 ),
00477                         array(  '-1k', -1024 ),
00478 
00479                         # Zeroes
00480                         array(   '0', 0 ),
00481                         array(  '0k', 0 ),
00482                         array(  '0M', 0 ),
00483                         array(  '0G', 0 ),
00484                         array(  '-0', 0 ),
00485                         array( '-0k', 0 ),
00486                         array( '-0M', 0 ),
00487                         array( '-0G', 0 ),
00488                 );
00489         }
00490 
00500         public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText ) {
00501                 $mergedText = null;
00502                 $isMerged = wfMerge( $old, $mine, $yours, $mergedText );
00503 
00504                 $msg = 'Merge should be a ';
00505                 $msg .= $expectedMergeResult ? 'success' : 'failure';
00506                 $this->assertEquals( $expectedMergeResult, $isMerged, $msg );
00507 
00508                 if( $isMerged ) {
00509                         // Verify the merged text
00510                         $this->assertEquals( $expectedText, $mergedText,
00511                                 'is merged text as expected?' );
00512                 }
00513         }
00514 
00515         public static function provideMerge() {
00516                 $EXPECT_MERGE_SUCCESS = true;
00517                 $EXPECT_MERGE_FAILURE = false;
00518 
00519                 return array(
00520 
00521                         // #0: clean merge
00522                         array(
00523                                 // old:
00524                                 "one one one\n" . // trimmed
00525                                 "\n" .
00526                                 "two two two",
00527 
00528                                 // mine:
00529                                 "one one one ONE ONE\n" .
00530                                 "\n" .
00531                                 "two two two\n", // with tailing whitespace
00532 
00533                                 // yours:
00534                                 "one one one\n" .
00535                                 "\n" .
00536                                 "two two TWO TWO", // trimmed
00537 
00538                                 // ok:
00539                                 $EXPECT_MERGE_SUCCESS,
00540 
00541                                 // result:
00542                                 "one one one ONE ONE\n" .
00543                                 "\n" .
00544                                 "two two TWO TWO\n", // note: will always end in a newline
00545                         ),
00546 
00547                         // #1: conflict, fail
00548                         array(
00549                                 // old:
00550                                 "one one one", // trimmed
00551 
00552                                 // mine:
00553                                 "one one one ONE ONE\n" .
00554                                 "\n" .
00555                                 "bla bla\n" .
00556                                 "\n", // with tailing whitespace
00557 
00558                                 // yours:
00559                                 "one one one\n" .
00560                                 "\n" .
00561                                 "two two", // trimmed
00562 
00563                                 $EXPECT_MERGE_FAILURE,
00564 
00565                                 // result:
00566                                 null,
00567                         ),
00568                 );
00569         }
00570 
00574         function testMakeUrlIndexes( $url, $expected ) {
00575                 $index = wfMakeUrlIndexes( $url );
00576                 $this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" );
00577         }
00578 
00579         function provideMakeUrlIndexes() {
00580                 return array(
00581                         array(
00582                                 // just a regular :)
00583                                 'https://bugzilla.wikimedia.org/show_bug.cgi?id=28627',
00584                                 array( 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627' )
00585                         ),
00586                         array(
00587                                 // mailtos are handled special
00588                                 // is this really right though? that final . probably belongs earlier?
00589                                 'mailto:[email protected]',
00590                                 array( 'mailto:org.wikimedia@wiki.' )
00591                         ),
00592 
00593                         // file URL cases per bug 28627...
00594                         array(
00595                                 // three slashes: local filesystem path Unix-style
00596                                 'file:///whatever/you/like.txt',
00597                                 array( 'file://./whatever/you/like.txt' )
00598                         ),
00599                         array(
00600                                 // three slashes: local filesystem path Windows-style
00601                                 'file:///c:/whatever/you/like.txt',
00602                                 array( 'file://./c:/whatever/you/like.txt' )
00603                         ),
00604                         array(
00605                                 // two slashes: UNC filesystem path Windows-style
00606                                 'file://intranet/whatever/you/like.txt',
00607                                 array( 'file://intranet./whatever/you/like.txt' )
00608                         ),
00609                         // Multiple-slash cases that can sorta work on Mozilla
00610                         // if you hack it just right are kinda pathological,
00611                         // and unreliable cross-platform or on IE which means they're
00612                         // unlikely to appear on intranets.
00613                         //
00614                         // Those will survive the algorithm but with results that
00615                         // are less consistent.
00616 
00617                         // protocol-relative URL cases per bug 29854...
00618                         array(
00619                                 '//bugzilla.wikimedia.org/show_bug.cgi?id=28627',
00620                                 array(
00621                                         'http://org.wikimedia.bugzilla./show_bug.cgi?id=28627',
00622                                         'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627'
00623                                 )
00624                         ),
00625                 );
00626         }
00627         
00631         function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
00632                 $actual = wfMatchesDomainList( $url, $domains );
00633                 $this->assertEquals( $expected, $actual, $description );
00634         }
00635         
00636         function provideWfMatchesDomainList() {
00637                 $a = array();
00638                 $protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' );
00639                 foreach ( $protocols as $pDesc => $p ) {
00640                         $a = array_merge( $a, array(
00641                                 array( "$p//www.example.com", array(), false, "No matches for empty domains array, $pDesc URL" ),
00642                                 array( "$p//www.example.com", array( 'www.example.com' ), true, "Exact match in domains array, $pDesc URL" ),
00643                                 array( "$p//www.example.com", array( 'example.com' ), true, "Match without subdomain in domains array, $pDesc URL" ),
00644                                 array( "$p//www.example2.com", array( 'www.example.com', 'www.example2.com', 'www.example3.com' ), true, "Exact match with other domains in array, $pDesc URL" ),
00645                                 array( "$p//www.example2.com", array( 'example.com', 'example2.com', 'example3,com' ), true, "Match without subdomain with other domains in array, $pDesc URL" ),
00646                                 array( "$p//www.example4.com", array( 'example.com', 'example2.com', 'example3,com' ), false, "Domain not in array, $pDesc URL" ),
00647                                 
00648                                 // FIXME: This is a bug in wfMatchesDomainList(). If and when this is fixed, update this test case
00649                                 array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), true, "Substrings of domains match while they shouldn't, $pDesc URL" ),
00650                         ) );
00651                 }
00652                 return $a;
00653         }
00654 
00658         function testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description ) {
00659                 if( wfIsWindows() ) {
00660                         // Approximation that's good enough for our purposes just now
00661                         $expected = str_replace( "'", '"', $expected );
00662                 }
00663                 $actual = wfShellMaintenanceCmd( $script, $parameters, $options );
00664                 $this->assertEquals( $expected, $actual, $description );
00665         }
00666 
00667         function provideWfShellMaintenanceCmdList() {
00668                 global $wgPhpCli;
00669                 return array(
00670                         array( 'eval.php', array( '--help', '--test' ), array(),
00671                                 "'$wgPhpCli' 'eval.php' '--help' '--test'",
00672                                 "Called eval.php --help --test" ),
00673                         array( 'eval.php', array( '--help', '--test space' ), array('php' => 'php5'),
00674                                 "'php5' 'eval.php' '--help' '--test space'",
00675                                 "Called eval.php --help --test with php option" ),
00676                         array( 'eval.php', array( '--help', '--test', 'X' ), array('wrapper' => 'MWScript.php'),
00677                                 "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
00678                                 "Called eval.php --help --test with wrapper option" ),
00679                         array( 'eval.php', array( '--help', '--test', 'y' ), array('php' => 'php5', 'wrapper' => 'MWScript.php'),
00680                                 "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
00681                                 "Called eval.php --help --test with wrapper and php option" ),
00682                 );
00683         }
00684         /* TODO: many more! */
00685 }
00686