3 class GlobalTest
extends MediaWikiTestCase
{
5 global $wgReadOnlyFile, $wgUrlProtocols;
6 $this->originals
['wgReadOnlyFile'] = $wgReadOnlyFile;
7 $this->originals
['wgUrlProtocols'] = $wgUrlProtocols;
8 $wgReadOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" );
9 $wgUrlProtocols[] = 'file://';
10 unlink( $wgReadOnlyFile );
14 global $wgReadOnlyFile, $wgUrlProtocols;
15 if ( file_exists( $wgReadOnlyFile ) ) {
16 unlink( $wgReadOnlyFile );
18 $wgReadOnlyFile = $this->originals
['wgReadOnlyFile'];
19 $wgUrlProtocols = $this->originals
['wgUrlProtocols'];
22 /** @dataProvider provideForWfArrayDiff2 */
23 public function testWfArrayDiff2( $a, $b, $expected ) {
25 wfArrayDiff2( $a, $b), $expected
29 // @todo Provide more tests
30 public function provideForWfArrayDiff2() {
39 array( array( 'a'), array( 'a', 'b', 'c' )),
40 array( array( 'a'), array( 'a', 'b' )),
41 array( 1 => array( 'a', 'b', 'c' ) ),
46 function testRandom() {
47 # This could hypothetically fail, but it shouldn't ;)
49 wfRandom() == wfRandom() );
52 function testUrlencode() {
54 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
55 wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
58 function testReadOnlyEmpty() {
62 $this->assertFalse( wfReadOnly() );
63 $this->assertFalse( wfReadOnly() );
66 function testReadOnlySet() {
67 global $wgReadOnly, $wgReadOnlyFile;
69 $f = fopen( $wgReadOnlyFile, "wt" );
70 fwrite( $f, 'Message' );
72 $wgReadOnly = null; # Check on $wgReadOnlyFile
74 $this->assertTrue( wfReadOnly() );
75 $this->assertTrue( wfReadOnly() ); # Check cached
77 unlink( $wgReadOnlyFile );
78 $wgReadOnly = null; # Clean cache
80 $this->assertFalse( wfReadOnly() );
81 $this->assertFalse( wfReadOnly() );
84 function testQuotedPrintable() {
86 "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
87 UserMailer
::quotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
92 $this->assertInternalType( 'float', $start );
94 $this->assertTrue( $end > $start, "Time is running backwards!" );
97 function testArrayToCGI() {
101 array( 'baz' => 'AT&T', 'ignore' => '' ),
102 array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
104 "path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost",
106 'path' => array( 'wiki', 'test' ),
107 'cfg' => array( 'servers' => array( 'http' => 'localhost' ) ) ) ) );
110 function testCgiToArray() {
112 array( 'path' => array( 'wiki', 'test' ),
113 'cfg' => array( 'servers' => array( 'http' => 'localhost' ) ) ),
114 wfCgiToArray( 'path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost' ) );
117 function testMimeTypeMatch() {
120 mimeTypeMatch( 'text/html',
121 array( 'application/xhtml+xml' => 1.0,
123 'text/plain' => 0.3 ) ) );
126 mimeTypeMatch( 'text/html',
127 array( 'image/*' => 1.0,
128 'text/*' => 0.5 ) ) );
131 mimeTypeMatch( 'text/html',
132 array( '*/*' => 1.0 ) ) );
134 mimeTypeMatch( 'text/html',
135 array( 'image/png' => 1.0,
136 'image/svg+xml' => 0.5 ) ) );
139 function testNegotiateType() {
143 array( 'application/xhtml+xml' => 1.0,
147 array( 'text/html' => 1.0 ) ) );
149 'application/xhtml+xml',
151 array( 'application/xhtml+xml' => 1.0,
155 array( 'application/xhtml+xml' => 1.0,
156 'text/html' => 0.5 ) ) );
160 array( 'text/html' => 1.0,
163 'application/xhtml+xml' => 0.2 ),
164 array( 'application/xhtml+xml' => 1.0,
165 'text/html' => 0.5 ) ) );
169 array( 'text/*' => 1.0,
172 array( 'application/xhtml+xml' => 1.0,
173 'text/html' => 0.5 ) ) );
176 array( 'text/*' => 1.0 ),
177 array( 'application/xhtml+xml' => 1.0 ) ) );
180 function testTimestamp() {
181 $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
184 wfTimestamp( TS_MW
, $t ),
185 'TS_UNIX to TS_MW' );
188 wfTimestamp( TS_MW
, -30281104 ),
189 'Negative TS_UNIX to TS_MW' );
192 wfTimestamp( TS_UNIX
, $t ),
193 'TS_UNIX to TS_UNIX' );
195 '2001-01-15 12:34:56',
196 wfTimestamp( TS_DB
, $t ),
197 'TS_UNIX to TS_DB' );
200 wfTimestamp( TS_ISO_8601_BASIC
, $t ),
201 'TS_ISO_8601_BASIC to TS_DB' );
205 wfTimestamp( TS_MW
, '20010115123456' ),
209 wfTimestamp( TS_UNIX
, '20010115123456' ),
210 'TS_MW to TS_UNIX' );
212 '2001-01-15 12:34:56',
213 wfTimestamp( TS_DB
, '20010115123456' ),
217 wfTimestamp( TS_ISO_8601_BASIC
, '20010115123456' ),
218 'TS_MW to TS_ISO_8601_BASIC' );
222 wfTimestamp( TS_MW
, '2001-01-15 12:34:56' ),
226 wfTimestamp( TS_UNIX
, '2001-01-15 12:34:56' ),
227 'TS_DB to TS_UNIX' );
229 '2001-01-15 12:34:56',
230 wfTimestamp( TS_DB
, '2001-01-15 12:34:56' ),
234 wfTimestamp( TS_ISO_8601_BASIC
, '2001-01-15 12:34:56' ),
235 'TS_DB to TS_ISO_8601_BASIC' );
237 # rfc2822 section 3.3
240 'Mon, 15 Jan 2001 12:34:56 GMT',
241 wfTimestamp( TS_RFC2822
, '20010115123456' ),
242 'TS_MW to TS_RFC2822' );
246 wfTimestamp( TS_MW
, 'Mon, 15 Jan 2001 12:34:56 GMT' ),
247 'TS_RFC2822 to TS_MW' );
251 wfTimestamp( TS_MW
, ' Mon, 15 Jan 2001 12:34:56 GMT' ),
252 'TS_RFC2822 with leading space to TS_MW' );
256 wfTimestamp( TS_MW
, '15 Jan 2001 12:34:56 GMT' ),
257 'TS_RFC2822 without optional day-of-week to TS_MW' );
259 # FWS = ([*WSP CRLF] 1*WSP) / obs-FWS ; Folding white space
260 # obs-FWS = 1*WSP *(CRLF 1*WSP) ; Section 4.2
263 wfTimestamp( TS_MW
, 'Mon, 15 Jan 2001 12:34:56 GMT' ),
264 'TS_RFC2822 to TS_MW' );
266 # WSP = SP / HTAB ; rfc2234
269 wfTimestamp( TS_MW
, "Mon, 15 Jan\x092001 12:34:56 GMT" ),
270 'TS_RFC2822 with HTAB to TS_MW' );
274 wfTimestamp( TS_MW
, "Mon, 15 Jan\x09 \x09 2001 12:34:56 GMT" ),
275 'TS_RFC2822 with HTAB and SP to TS_MW' );
279 wfTimestamp( TS_MW
, "Sun, 6 Nov 94 08:49:37 GMT" ),
280 'TS_RFC2822 with obsolete year to TS_MW' );
284 * This test checks wfTimestamp() with values outside.
285 * It needs PHP 64 bits or PHP > 5.1.
286 * See r74778 and bug 25451
288 function testOldTimestamps() {
289 $this->assertEquals( 'Fri, 13 Dec 1901 20:45:54 GMT',
290 wfTimestamp( TS_RFC2822
, '19011213204554' ),
291 'Earliest time according to php documentation' );
293 $this->assertEquals( 'Tue, 19 Jan 2038 03:14:07 GMT',
294 wfTimestamp( TS_RFC2822
, '20380119031407' ),
295 'Latest 32 bit time' );
297 $this->assertEquals( '-2147483648',
298 wfTimestamp( TS_UNIX
, '19011213204552' ),
299 'Earliest 32 bit unix time' );
301 $this->assertEquals( '2147483647',
302 wfTimestamp( TS_UNIX
, '20380119031407' ),
303 'Latest 32 bit unix time' );
305 $this->assertEquals( 'Fri, 13 Dec 1901 20:45:52 GMT',
306 wfTimestamp( TS_RFC2822
, '19011213204552' ),
307 'Earliest 32 bit time' );
309 $this->assertEquals( 'Fri, 13 Dec 1901 20:45:51 GMT',
310 wfTimestamp( TS_RFC2822
, '19011213204551' ),
311 'Earliest 32 bit time - 1' );
313 $this->assertEquals( 'Tue, 19 Jan 2038 03:14:08 GMT',
314 wfTimestamp( TS_RFC2822
, '20380119031408' ),
315 'Latest 32 bit time + 1' );
317 $this->assertEquals( '19011212000000',
318 wfTimestamp(TS_MW
, '19011212000000'),
319 'Convert to itself r74778#c10645' );
321 $this->assertEquals( '-2147483649',
322 wfTimestamp( TS_UNIX
, '19011213204551' ),
323 'Earliest 32 bit unix time - 1' );
325 $this->assertEquals( '2147483648',
326 wfTimestamp( TS_UNIX
, '20380119031408' ),
327 'Latest 32 bit unix time + 1' );
329 $this->assertEquals( '19011213204551',
330 wfTimestamp( TS_MW
, '-2147483649' ),
331 '1901 negative unix time to MediaWiki' );
333 $this->assertEquals( '18010115123456',
334 wfTimestamp( TS_MW
, '-5331871504' ),
335 '1801 negative unix time to MediaWiki' );
337 $this->assertEquals( 'Tue, 09 Aug 0117 12:34:56 GMT',
338 wfTimestamp( TS_RFC2822
, '0117-08-09 12:34:56'),
339 'Death of Roman Emperor [[Trajan]]');
341 /* @todo FIXME: 00 to 101 years are taken as being in [1970-2069] */
343 $this->assertEquals( 'Sun, 01 Jan 0101 00:00:00 GMT',
344 wfTimestamp( TS_RFC2822
, '-58979923200'),
347 $this->assertEquals( 'Mon, 01 Jan 0001 00:00:00 GMT',
348 wfTimestamp( TS_RFC2822
, '-62135596800'),
351 /* It is not clear if we should generate a year 0 or not
352 * We are completely off RFC2822 requirement of year being
355 $this->assertEquals( 'Wed, 18 Oct 0000 00:00:00 GMT',
356 wfTimestamp( TS_RFC2822
, '-62142076800'),
357 'ISO 8601:2004 [[year 0]], also called [[1 BC]]');
360 function testHttpDate() {
361 # The Resource Loader uses wfTimestamp() to convert timestamps
362 # from If-Modified-Since header.
363 # Thus it must be able to parse all rfc2616 date formats
364 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
368 wfTimestamp( TS_MW
, 'Sun, 06 Nov 1994 08:49:37 GMT' ),
373 wfTimestamp( TS_MW
, 'Sunday, 06-Nov-94 08:49:37 GMT' ),
378 wfTimestamp( TS_MW
, 'Sun Nov 6 08:49:37 1994' ),
379 "ANSI C's asctime() format" );
381 // See http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html and r77171
384 wfTimestamp( TS_MW
, 'Mon, 22 Nov 2010 14:12:42 GMT; length=52626' ),
385 "Netscape extension to HTTP/1.0" );
389 function testTimestampParameter() {
390 // There are a number of assumptions in our codebase where wfTimestamp() should give
391 // the current date but it is not given a 0 there. See r71751 CR
393 $now = wfTimestamp( TS_UNIX
);
394 // We check that wfTimestamp doesn't return false (error) and use a LessThan assert
395 // for the cases where the test is run in a second boundary.
397 $zero = wfTimestamp( TS_UNIX
, 0 );
398 $this->assertNotEquals( false, $zero );
399 $this->assertLessThan( 5, $zero - $now );
401 $empty = wfTimestamp( TS_UNIX
, '' );
402 $this->assertNotEquals( false, $empty );
403 $this->assertLessThan( 5, $empty - $now );
405 $null = wfTimestamp( TS_UNIX
, null );
406 $this->assertNotEquals( false, $null );
407 $this->assertLessThan( 5, $null - $now );
410 function testBasename() {
424 '\\aaaa\\' => 'aaaa',
425 '\\aaaa\\' => 'aaaa',
426 '/mnt/upload3/wikipedia/en/thumb/8/8b/Zork_Grand_Inquisitor_box_cover.jpg/93px-Zork_Grand_Inquisitor_box_cover.jpg' => '93px-Zork_Grand_Inquisitor_box_cover.jpg',
427 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
428 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
430 foreach ( $sets as $from => $to ) {
431 $this->assertEquals( $to, wfBaseName( $from ),
432 "wfBaseName('$from') => '$to'" );
437 function testFallbackMbstringFunctions() {
439 if( !extension_loaded( 'mbstring' ) ) {
440 $this->markTestSkipped( "The mb_string functions must be installed to test the fallback functions" );
443 $sampleUTF = "Östergötland_coat_of_arms.png";
447 $substr_params = array(
457 foreach( $substr_params as $param_set ) {
458 $old_param_set = $param_set;
459 array_unshift( $param_set, $sampleUTF );
462 MWFunction
::callArray( 'mb_substr', $param_set ),
463 MWFunction
::callArray( 'Fallback::mb_substr', $param_set ),
464 'Fallback mb_substr with params ' . implode( ', ', $old_param_set )
471 mb_strlen( $sampleUTF ),
472 Fallback
::mb_strlen( $sampleUTF ),
478 $strpos_params = array(
482 //array( 'oat_', 100 ),
487 foreach( $strpos_params as $param_set ) {
488 $old_param_set = $param_set;
489 array_unshift( $param_set, $sampleUTF );
492 MWFunction
::callArray( 'mb_strpos', $param_set ),
493 MWFunction
::callArray( 'Fallback::mb_strpos', $param_set ),
494 'Fallback mb_strpos with params ' . implode( ', ', $old_param_set )
498 MWFunction
::callArray( 'mb_strrpos', $param_set ),
499 MWFunction
::callArray( 'Fallback::mb_strrpos', $param_set ),
500 'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set )
507 function testDebugFunctionTest() {
509 global $wgDebugLogFile, $wgOut, $wgShowDebug, $wgDebugTimestamps;
511 $old_log_file = $wgDebugLogFile;
512 $wgDebugLogFile = tempnam( wfTempDir(), 'mw-' );
513 #Â @todo FIXME: This setting should be tested
514 $wgDebugTimestamps = false;
518 wfDebug( "This is a normal string" );
519 $this->assertEquals( "This is a normal string", file_get_contents( $wgDebugLogFile ) );
520 unlink( $wgDebugLogFile );
523 wfDebug( "This is nöt an ASCII string" );
524 $this->assertEquals( "This is nöt an ASCII string", file_get_contents( $wgDebugLogFile ) );
525 unlink( $wgDebugLogFile );
528 wfDebug( "\00305This has böth UTF and control chars\003" );
529 $this->assertEquals( " 05This has böth UTF and control chars ", file_get_contents( $wgDebugLogFile ) );
530 unlink( $wgDebugLogFile );
535 $old_wgShowDebug = $wgShowDebug;
537 $wgOut = new MockOutputPage
;
541 $message = "\00305This has böth UTF and control chars\003";
545 if( $wgOut->message
== "JAJA is a stupid error message. Anyway, here's your message: $message" ) {
546 $this->assertTrue( true, 'MockOutputPage called, set the proper message.' );
549 $this->assertTrue( false, 'MockOutputPage was not called.' );
553 $wgShowDebug = $old_wgShowDebug;
554 unlink( $wgDebugLogFile );
559 $this->assertGreaterThan( 5000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) );
560 unlink( $wgDebugLogFile );
563 $this->assertGreaterThan( 5000000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) );
564 unlink( $wgDebugLogFile );
568 $wgDebugLogFile = $old_log_file;
572 function testClientAcceptsGzipTest() {
578 'compress, gzip' => true,
579 'gzip;q=1.0' => true,
582 'gzip;q=abcde' => true, //is this REALLY valid?
583 'gzip;q=12345678.9' => true,
587 if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
589 foreach ( $settings as $encoding => $expect ) {
590 $_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;
592 $this->assertEquals( $expect, wfClientAcceptsGzip( true ),
593 "'$encoding' => " . wfBoolToStr( $expect ) );
596 if( isset( $old_server_setting ) ) $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
602 function testSwapVarsTest() {
608 $this->assertEquals( $var1, 1, 'var1 is set originally' );
609 $this->assertEquals( $var2, 2, 'var1 is set originally' );
611 swap( $var1, $var2 );
613 $this->assertEquals( $var1, 2, 'var1 is swapped' );
614 $this->assertEquals( $var2, 1, 'var2 is swapped' );
619 function testWfPercentTest() {
622 array( 6/7, '0.86%', 2, false ),
624 array( 22/7, '3.14286%', 5 ),
625 array( 3/6, '0.5%' ),
626 array( 1/3, '0%', 0 ),
627 array( 10/3, '0%', -1 ),
628 array( 3/4/5, '0.1%', 1 ),
629 array( 6/7*8, '6.8571428571%', 10 ),
632 foreach( $pcts as $pct ) {
633 if( !isset( $pct[2] ) ) $pct[2] = 2;
634 if( !isset( $pct[3] ) ) $pct[3] = true;
636 $this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
642 function testInStringTest() {
644 $this->assertTrue( in_string( 'foo', 'foobar' ), 'foo is in foobar' );
645 $this->assertFalse( in_string( 'Bar', 'foobar' ), 'Case-sensitive by default' );
646 $this->assertTrue( in_string( 'Foo', 'foobar', true ), 'Case-insensitive when asked' );
651 * test @see wfShorthandToInteger()
652 * @dataProvider provideShorthand
654 public function testWfShorthandToInteger( $shorthand, $expected ) {
655 $this->assertEquals( $expected,
656 wfShorthandToInteger( $shorthand )
660 /** array( shorthand, expected integer ) */
661 public function provideShorthand() {
668 # Failures returns 0 :(
669 array( 'ABCDEFG', 0 ),
672 # Int, strings with spaces
676 array( ' 1023 ', 1023 ),
681 array( '1m', 1024 * 1024 ),
682 array( '1M', 1024 * 1024 ),
683 array( '1g', 1024 * 1024 * 1024 ),
684 array( '1G', 1024 * 1024 * 1024 ),
689 array( '-500', -500 ),
690 array( '-1k', -1024 ),
706 * test @see wfBCP47().
707 * Please note the BCP explicitly state that language codes are case
708 * insensitive, there are some exceptions to the rule :)
709 * This test is used to verify our formatting against all lower and
710 * all upper cases language code.
712 * @see http://tools.ietf.org/html/bcp47
713 * @dataProvider provideLanguageCodes()
715 function testBCP47( $code, $expected ) {
716 $code = strtolower( $code );
717 $this->assertEquals( $expected, wfBCP47($code),
718 "Applying BCP47 standard to lower case '$code'"
721 $code = strtoupper( $code );
722 $this->assertEquals( $expected, wfBCP47($code),
723 "Applying BCP47 standard to upper case '$code'"
728 * Array format is ($code, $expected)
730 function provideLanguageCodes() {
732 // Extracted from BCP47 (list not exhaustive)
734 array( 'en-ca-x-ca' , 'en-CA-x-ca' ),
735 array( 'sgn-be-fr' , 'sgn-BE-FR' ),
736 array( 'az-latn-x-latn', 'az-Latn-x-latn' ),
738 array( 'sr-Latn-RS', 'sr-Latn-RS' ),
739 array( 'az-arab-ir', 'az-Arab-IR' ),
742 array( 'sl-nedis' , 'sl-nedis' ),
743 array( 'de-ch-1996', 'de-CH-1996' ),
747 'en-latn-gb-boont-r-extended-sequence-x-private',
748 'en-Latn-GB-boont-r-extended-sequence-x-private'
751 // Examples from BCP47 Appendix A
752 # Simple language subtag:
757 # Language subtag plus script subtag:
758 array( 'zh-hans', 'zh-Hans'),
759 array( 'sr-cyrl', 'sr-Cyrl'),
760 array( 'sr-latn', 'sr-Latn'),
762 # Extended language subtags and their primary language subtag
764 array( 'zh-cmn-hans-cn', 'zh-cmn-Hans-CN' ),
765 array( 'cmn-hans-cn' , 'cmn-Hans-CN' ),
766 array( 'zh-yue-hk' , 'zh-yue-HK' ),
767 array( 'yue-hk' , 'yue-HK' ),
769 # Language-Script-Region:
770 array( 'zh-hans-cn', 'zh-Hans-CN' ),
771 array( 'sr-latn-RS', 'sr-Latn-RS' ),
774 array( 'sl-rozaj' , 'sl-rozaj' ),
775 array( 'sl-rozaj-biske', 'sl-rozaj-biske' ),
776 array( 'sl-nedis' , 'sl-nedis' ),
778 # Language-Region-Variant:
779 array( 'de-ch-1901' , 'de-CH-1901' ),
780 array( 'sl-it-nedis' , 'sl-IT-nedis' ),
782 # Language-Script-Region-Variant:
783 array( 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ),
786 array( 'de-de' , 'de-DE' ),
787 array( 'en-us' , 'en-US' ),
788 array( 'es-419', 'es-419'),
790 # Private use subtags:
791 array( 'de-ch-x-phonebk' , 'de-CH-x-phonebk' ),
792 array( 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ),
794 * Previous test does not reflect the BCP which states:
795 * az-Arab-x-AZE-derbend
796 * AZE being private, it should be lower case, hence the test above
797 * should probably be:
798 #array( 'az-arab-x-aze-derbend', 'az-Arab-x-AZE-derbend' ),
801 # Private use registry values:
802 array( 'x-whatever', 'x-whatever' ),
803 array( 'qaa-qaaa-qm-x-southern', 'qaa-Qaaa-QM-x-southern' ),
804 array( 'de-qaaa' , 'de-Qaaa' ),
805 array( 'sr-latn-qm', 'sr-Latn-QM' ),
806 array( 'sr-qaaa-rs', 'sr-Qaaa-RS' ),
808 # Tags that use extensions
809 array( 'en-us-u-islamcal', 'en-US-u-islamcal' ),
810 array( 'zh-cn-a-myext-x-private', 'zh-CN-a-myext-x-private' ),
811 array( 'en-a-myext-b-another', 'en-a-myext-b-another' ),
816 // ar-a-aaa-b-bbb-a-ccc
820 array( 'sr-Cyrl', 'sr-Cyrl' ),
821 # @todo FIXME: Fix our function?
822 array( 'SR-lATN', 'sr-Latn' ),
823 array( 'fr-latn', 'fr-Latn' ),
824 // Use lowercase for single segment
825 // ISO 3166-1-alpha-2 code
826 array( 'US', 'us' ), # USA
827 array( 'uS', 'us' ), # USA
828 array( 'Fr', 'fr' ), # France
829 array( 'va', 'va' ), # Holy See (Vatican City State)
834 * @dataProvider provideMakeUrlIndexes()
836 function testMakeUrlIndexes( $url, $expected ) {
837 $index = wfMakeUrlIndexes( $url );
838 $this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" );
841 function provideMakeUrlIndexes() {
845 'https://bugzilla.wikimedia.org/show_bug.cgi?id=28627',
846 array( 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627' )
849 // mailtos are handled special
850 // is this really right though? that final . probably belongs earlier?
851 'mailto:wiki@wikimedia.org',
852 array( 'mailto:org.wikimedia@wiki.' )
855 // file URL cases per bug 28627...
857 // three slashes: local filesystem path Unix-style
858 'file:///whatever/you/like.txt',
859 array( 'file://./whatever/you/like.txt' )
862 // three slashes: local filesystem path Windows-style
863 'file:///c:/whatever/you/like.txt',
864 array( 'file://./c:/whatever/you/like.txt' )
867 // two slashes: UNC filesystem path Windows-style
868 'file://intranet/whatever/you/like.txt',
869 array( 'file://intranet./whatever/you/like.txt' )
871 // Multiple-slash cases that can sorta work on Mozilla
872 // if you hack it just right are kinda pathological,
873 // and unreliable cross-platform or on IE which means they're
874 // unlikely to appear on intranets.
876 // Those will survive the algorithm but with results that
877 // are less consistent.
879 // protocol-relative URL cases per bug 29854...
881 '//bugzilla.wikimedia.org/show_bug.cgi?id=28627',
883 'http://org.wikimedia.bugzilla./show_bug.cgi?id=28627',
884 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627'
891 * @dataProvider provideWfMatchesDomainList
893 function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
894 $actual = wfMatchesDomainList( $url, $domains );
895 $this->assertEquals( $expected, $actual, $description );
898 function provideWfMatchesDomainList() {
900 $protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' );
901 foreach ( $protocols as $pDesc => $p ) {
902 $a = array_merge( $a, array(
903 array( "$p//www.example.com", array(), false, "No matches for empty domains array, $pDesc URL" ),
904 array( "$p//www.example.com", array( 'www.example.com' ), true, "Exact match in domains array, $pDesc URL" ),
905 array( "$p//www.example.com", array( 'example.com' ), true, "Match without subdomain in domains array, $pDesc URL" ),
906 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" ),
907 array( "$p//www.example2.com", array( 'example.com', 'example2.com', 'example3,com' ), true, "Match without subdomain with other domains in array, $pDesc URL" ),
908 array( "$p//www.example4.com", array( 'example.com', 'example2.com', 'example3,com' ), false, "Domain not in array, $pDesc URL" ),
910 // FIXME: This is a bug in wfMatchesDomainList(). If and when this is fixed, update this test case
911 array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), true, "Substrings of domains match while they shouldn't, $pDesc URL" ),
918 * @dataProvider provideWfShellMaintenanceCmdList
920 function testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description ) {
921 if( wfIsWindows() ) {
922 // Approximation that's good enough for our purposes just now
923 $expected = str_replace( "'", '"', $expected );
925 $actual = wfShellMaintenanceCmd( $script, $parameters, $options );
926 $this->assertEquals( $expected, $actual, $description );
929 function provideWfShellMaintenanceCmdList() {
932 array( 'eval.php', array( '--help', '--test' ), array(),
933 "'$wgPhpCli' 'eval.php' '--help' '--test'",
934 "Called eval.php --help --test" ),
935 array( 'eval.php', array( '--help', '--test space' ), array('php' => 'php5'),
936 "'php5' 'eval.php' '--help' '--test space'",
937 "Called eval.php --help --test with php option" ),
938 array( 'eval.php', array( '--help', '--test', 'X' ), array('wrapper' => 'MWScript.php'),
939 "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
940 "Called eval.php --help --test with wrapper option" ),
941 array( 'eval.php', array( '--help', '--test', 'y' ), array('php' => 'php5', 'wrapper' => 'MWScript.php'),
942 "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
943 "Called eval.php --help --test with wrapper and php option" ),
946 /* TODO: many more! */
950 class MockOutputPage
{
954 function debug( $message ) {
955 $this->message
= "JAJA is a stupid error message. Anyway, here's your message: $message";