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 dataArrayToCGI() {
99 array( array(), '' ), // empty
100 array( array( 'foo' => 'bar' ), 'foo=bar' ), // string test
101 array( array( 'foo' => '' ), 'foo=' ), // empty string test
102 array( array( 'foo' => 1 ), 'foo=1' ), // number test
103 array( array( 'foo' => true ), 'foo=1' ), // true test
104 array( array( 'foo' => false ), '' ), // false test
105 array( array( 'foo' => null ), '' ), // null test
106 array( array( 'foo' => 'A&B=5+6@!"\'' ), 'foo=A%26B%3D5%2B6%40%21%22%27' ), // urlencoding test
107 array( array( 'foo' => 'bar', 'baz' => 'is', 'asdf' => 'qwerty' ), 'foo=bar&baz=is&asdf=qwerty' ), // multi-item test
108 array( array( 'foo' => array( 'bar' => 'baz' ) ), 'foo%5Bbar%5D=baz' ),
109 array( array( 'foo' => array( 'bar' => 'baz', 'qwerty' => 'asdf' ) ), 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf' ),
110 array( array( 'foo' => array( 'bar', 'baz' ) ), 'foo%5B0%5D=bar&foo%5B1%5D=baz' ),
111 array( array( 'foo' => array( 'bar' => array( 'bar' => 'baz' ) ) ), 'foo%5Bbar%5D%5Bbar%5D=baz' ),
116 * @dataProvider dataArrayToCGI
118 function testArrayToCGI( $array, $result ) {
119 $this->assertEquals( $result, wfArrayToCGI( $array ) );
123 function testArrayToCGI2() {
127 array( 'baz' => 'bar' ),
128 array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
131 function dataCgiToArray() {
133 array( '', array() ), // empty
134 array( 'foo=bar', array( 'foo' => 'bar' ) ), // string
135 array( 'foo=', array( 'foo' => '' ) ), // empty string
136 array( 'foo', array( 'foo' => '' ) ), // missing =
137 array( 'foo=bar&qwerty=asdf', array( 'foo' => 'bar', 'qwerty' => 'asdf' ) ), // multiple value
138 array( 'foo=A%26B%3D5%2B6%40%21%22%27', array( 'foo' => 'A&B=5+6@!"\'' ) ), // urldecoding test
139 array( 'foo%5Bbar%5D=baz', array( 'foo' => array( 'bar' => 'baz' ) ) ),
140 array( 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf', array( 'foo' => array( 'bar' => 'baz', 'qwerty' => 'asdf' ) ) ),
141 array( 'foo%5B0%5D=bar&foo%5B1%5D=baz', array( 'foo' => array( 0 => 'bar', 1 => 'baz' ) ) ),
142 array( 'foo%5Bbar%5D%5Bbar%5D=baz', array( 'foo' => array( 'bar' => array( 'bar' => 'baz' ) ) ) ),
147 * @dataProvider dataCgiToArray
149 function testCgiToArray( $cgi, $result ) {
150 $this->assertEquals( $result, wfCgiToArray( $cgi ) );
153 function dataCgiRoundTrip() {
158 array( 'foo=bar&baz=biz' ),
159 array( 'foo=A%26B%3D5%2B6%40%21%22%27' ),
160 array( 'foo%5Bbar%5D=baz' ),
161 array( 'foo%5B0%5D=bar&foo%5B1%5D=baz' ),
162 array( 'foo%5Bbar%5D%5Bbar%5D=baz' ),
167 * @dataProvider dataCgiRoundTrip
169 function testCgiRoundTrip( $cgi ) {
170 $this->assertEquals( $cgi, wfArrayToCGI( wfCgiToArray( $cgi ) ) );
173 function testMimeTypeMatch() {
176 mimeTypeMatch( 'text/html',
177 array( 'application/xhtml+xml' => 1.0,
179 'text/plain' => 0.3 ) ) );
182 mimeTypeMatch( 'text/html',
183 array( 'image/*' => 1.0,
184 'text/*' => 0.5 ) ) );
187 mimeTypeMatch( 'text/html',
188 array( '*/*' => 1.0 ) ) );
190 mimeTypeMatch( 'text/html',
191 array( 'image/png' => 1.0,
192 'image/svg+xml' => 0.5 ) ) );
195 function testNegotiateType() {
199 array( 'application/xhtml+xml' => 1.0,
203 array( 'text/html' => 1.0 ) ) );
205 'application/xhtml+xml',
207 array( 'application/xhtml+xml' => 1.0,
211 array( 'application/xhtml+xml' => 1.0,
212 'text/html' => 0.5 ) ) );
216 array( 'text/html' => 1.0,
219 'application/xhtml+xml' => 0.2 ),
220 array( 'application/xhtml+xml' => 1.0,
221 'text/html' => 0.5 ) ) );
225 array( 'text/*' => 1.0,
228 array( 'application/xhtml+xml' => 1.0,
229 'text/html' => 0.5 ) ) );
232 array( 'text/*' => 1.0 ),
233 array( 'application/xhtml+xml' => 1.0 ) ) );
236 function testTimestamp() {
237 $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
240 wfTimestamp( TS_MW
, $t ),
241 'TS_UNIX to TS_MW' );
244 wfTimestamp( TS_MW
, -30281104 ),
245 'Negative TS_UNIX to TS_MW' );
248 wfTimestamp( TS_UNIX
, $t ),
249 'TS_UNIX to TS_UNIX' );
251 '2001-01-15 12:34:56',
252 wfTimestamp( TS_DB
, $t ),
253 'TS_UNIX to TS_DB' );
256 wfTimestamp( TS_ISO_8601_BASIC
, $t ),
257 'TS_ISO_8601_BASIC to TS_DB' );
261 wfTimestamp( TS_MW
, '20010115123456' ),
265 wfTimestamp( TS_UNIX
, '20010115123456' ),
266 'TS_MW to TS_UNIX' );
268 '2001-01-15 12:34:56',
269 wfTimestamp( TS_DB
, '20010115123456' ),
273 wfTimestamp( TS_ISO_8601_BASIC
, '20010115123456' ),
274 'TS_MW to TS_ISO_8601_BASIC' );
278 wfTimestamp( TS_MW
, '2001-01-15 12:34:56' ),
282 wfTimestamp( TS_UNIX
, '2001-01-15 12:34:56' ),
283 'TS_DB to TS_UNIX' );
285 '2001-01-15 12:34:56',
286 wfTimestamp( TS_DB
, '2001-01-15 12:34:56' ),
290 wfTimestamp( TS_ISO_8601_BASIC
, '2001-01-15 12:34:56' ),
291 'TS_DB to TS_ISO_8601_BASIC' );
293 # rfc2822 section 3.3
296 'Mon, 15 Jan 2001 12:34:56 GMT',
297 wfTimestamp( TS_RFC2822
, '20010115123456' ),
298 'TS_MW to TS_RFC2822' );
302 wfTimestamp( TS_MW
, 'Mon, 15 Jan 2001 12:34:56 GMT' ),
303 'TS_RFC2822 to TS_MW' );
307 wfTimestamp( TS_MW
, ' Mon, 15 Jan 2001 12:34:56 GMT' ),
308 'TS_RFC2822 with leading space to TS_MW' );
312 wfTimestamp( TS_MW
, '15 Jan 2001 12:34:56 GMT' ),
313 'TS_RFC2822 without optional day-of-week to TS_MW' );
315 # FWS = ([*WSP CRLF] 1*WSP) / obs-FWS ; Folding white space
316 # obs-FWS = 1*WSP *(CRLF 1*WSP) ; Section 4.2
319 wfTimestamp( TS_MW
, 'Mon, 15 Jan 2001 12:34:56 GMT' ),
320 'TS_RFC2822 to TS_MW' );
322 # WSP = SP / HTAB ; rfc2234
325 wfTimestamp( TS_MW
, "Mon, 15 Jan\x092001 12:34:56 GMT" ),
326 'TS_RFC2822 with HTAB to TS_MW' );
330 wfTimestamp( TS_MW
, "Mon, 15 Jan\x09 \x09 2001 12:34:56 GMT" ),
331 'TS_RFC2822 with HTAB and SP to TS_MW' );
335 wfTimestamp( TS_MW
, "Sun, 6 Nov 94 08:49:37 GMT" ),
336 'TS_RFC2822 with obsolete year to TS_MW' );
340 * This test checks wfTimestamp() with values outside.
341 * It needs PHP 64 bits or PHP > 5.1.
342 * See r74778 and bug 25451
344 function testOldTimestamps() {
345 $this->assertEquals( 'Fri, 13 Dec 1901 20:45:54 GMT',
346 wfTimestamp( TS_RFC2822
, '19011213204554' ),
347 'Earliest time according to php documentation' );
349 $this->assertEquals( 'Tue, 19 Jan 2038 03:14:07 GMT',
350 wfTimestamp( TS_RFC2822
, '20380119031407' ),
351 'Latest 32 bit time' );
353 $this->assertEquals( '-2147483648',
354 wfTimestamp( TS_UNIX
, '19011213204552' ),
355 'Earliest 32 bit unix time' );
357 $this->assertEquals( '2147483647',
358 wfTimestamp( TS_UNIX
, '20380119031407' ),
359 'Latest 32 bit unix time' );
361 $this->assertEquals( 'Fri, 13 Dec 1901 20:45:52 GMT',
362 wfTimestamp( TS_RFC2822
, '19011213204552' ),
363 'Earliest 32 bit time' );
365 $this->assertEquals( 'Fri, 13 Dec 1901 20:45:51 GMT',
366 wfTimestamp( TS_RFC2822
, '19011213204551' ),
367 'Earliest 32 bit time - 1' );
369 $this->assertEquals( 'Tue, 19 Jan 2038 03:14:08 GMT',
370 wfTimestamp( TS_RFC2822
, '20380119031408' ),
371 'Latest 32 bit time + 1' );
373 $this->assertEquals( '19011212000000',
374 wfTimestamp(TS_MW
, '19011212000000'),
375 'Convert to itself r74778#c10645' );
377 $this->assertEquals( '-2147483649',
378 wfTimestamp( TS_UNIX
, '19011213204551' ),
379 'Earliest 32 bit unix time - 1' );
381 $this->assertEquals( '2147483648',
382 wfTimestamp( TS_UNIX
, '20380119031408' ),
383 'Latest 32 bit unix time + 1' );
385 $this->assertEquals( '19011213204551',
386 wfTimestamp( TS_MW
, '-2147483649' ),
387 '1901 negative unix time to MediaWiki' );
389 $this->assertEquals( '18010115123456',
390 wfTimestamp( TS_MW
, '-5331871504' ),
391 '1801 negative unix time to MediaWiki' );
393 $this->assertEquals( 'Tue, 09 Aug 0117 12:34:56 GMT',
394 wfTimestamp( TS_RFC2822
, '0117-08-09 12:34:56'),
395 'Death of Roman Emperor [[Trajan]]');
397 /* @todo FIXME: 00 to 101 years are taken as being in [1970-2069] */
399 $this->assertEquals( 'Sun, 01 Jan 0101 00:00:00 GMT',
400 wfTimestamp( TS_RFC2822
, '-58979923200'),
403 $this->assertEquals( 'Mon, 01 Jan 0001 00:00:00 GMT',
404 wfTimestamp( TS_RFC2822
, '-62135596800'),
407 /* It is not clear if we should generate a year 0 or not
408 * We are completely off RFC2822 requirement of year being
411 $this->assertEquals( 'Wed, 18 Oct 0000 00:00:00 GMT',
412 wfTimestamp( TS_RFC2822
, '-62142076800'),
413 'ISO 8601:2004 [[year 0]], also called [[1 BC]]');
416 function testHttpDate() {
417 # The Resource Loader uses wfTimestamp() to convert timestamps
418 # from If-Modified-Since header.
419 # Thus it must be able to parse all rfc2616 date formats
420 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
424 wfTimestamp( TS_MW
, 'Sun, 06 Nov 1994 08:49:37 GMT' ),
429 wfTimestamp( TS_MW
, 'Sunday, 06-Nov-94 08:49:37 GMT' ),
434 wfTimestamp( TS_MW
, 'Sun Nov 6 08:49:37 1994' ),
435 "ANSI C's asctime() format" );
437 // See http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html and r77171
440 wfTimestamp( TS_MW
, 'Mon, 22 Nov 2010 14:12:42 GMT; length=52626' ),
441 "Netscape extension to HTTP/1.0" );
445 function testTimestampParameter() {
446 // There are a number of assumptions in our codebase where wfTimestamp() should give
447 // the current date but it is not given a 0 there. See r71751 CR
449 $now = wfTimestamp( TS_UNIX
);
450 // We check that wfTimestamp doesn't return false (error) and use a LessThan assert
451 // for the cases where the test is run in a second boundary.
453 $zero = wfTimestamp( TS_UNIX
, 0 );
454 $this->assertNotEquals( false, $zero );
455 $this->assertLessThan( 5, $zero - $now );
457 $empty = wfTimestamp( TS_UNIX
, '' );
458 $this->assertNotEquals( false, $empty );
459 $this->assertLessThan( 5, $empty - $now );
461 $null = wfTimestamp( TS_UNIX
, null );
462 $this->assertNotEquals( false, $null );
463 $this->assertLessThan( 5, $null - $now );
466 function testBasename() {
480 '\\aaaa\\' => 'aaaa',
481 '\\aaaa\\' => 'aaaa',
482 '/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',
483 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
484 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
486 foreach ( $sets as $from => $to ) {
487 $this->assertEquals( $to, wfBaseName( $from ),
488 "wfBaseName('$from') => '$to'" );
493 function testFallbackMbstringFunctions() {
495 if( !extension_loaded( 'mbstring' ) ) {
496 $this->markTestSkipped( "The mb_string functions must be installed to test the fallback functions" );
499 $sampleUTF = "Östergötland_coat_of_arms.png";
503 $substr_params = array(
513 foreach( $substr_params as $param_set ) {
514 $old_param_set = $param_set;
515 array_unshift( $param_set, $sampleUTF );
518 MWFunction
::callArray( 'mb_substr', $param_set ),
519 MWFunction
::callArray( 'Fallback::mb_substr', $param_set ),
520 'Fallback mb_substr with params ' . implode( ', ', $old_param_set )
527 mb_strlen( $sampleUTF ),
528 Fallback
::mb_strlen( $sampleUTF ),
534 $strpos_params = array(
538 //array( 'oat_', 100 ),
543 foreach( $strpos_params as $param_set ) {
544 $old_param_set = $param_set;
545 array_unshift( $param_set, $sampleUTF );
548 MWFunction
::callArray( 'mb_strpos', $param_set ),
549 MWFunction
::callArray( 'Fallback::mb_strpos', $param_set ),
550 'Fallback mb_strpos with params ' . implode( ', ', $old_param_set )
554 MWFunction
::callArray( 'mb_strrpos', $param_set ),
555 MWFunction
::callArray( 'Fallback::mb_strrpos', $param_set ),
556 'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set )
563 function testDebugFunctionTest() {
565 global $wgDebugLogFile, $wgOut, $wgShowDebug, $wgDebugTimestamps;
567 $old_log_file = $wgDebugLogFile;
568 $wgDebugLogFile = tempnam( wfTempDir(), 'mw-' );
569 #Â @todo FIXME: This setting should be tested
570 $wgDebugTimestamps = false;
574 wfDebug( "This is a normal string" );
575 $this->assertEquals( "This is a normal string", file_get_contents( $wgDebugLogFile ) );
576 unlink( $wgDebugLogFile );
579 wfDebug( "This is nöt an ASCII string" );
580 $this->assertEquals( "This is nöt an ASCII string", file_get_contents( $wgDebugLogFile ) );
581 unlink( $wgDebugLogFile );
584 wfDebug( "\00305This has böth UTF and control chars\003" );
585 $this->assertEquals( " 05This has böth UTF and control chars ", file_get_contents( $wgDebugLogFile ) );
586 unlink( $wgDebugLogFile );
591 $old_wgShowDebug = $wgShowDebug;
593 $wgOut = new MockOutputPage
;
597 $message = "\00305This has böth UTF and control chars\003";
601 if( $wgOut->message
== "JAJA is a stupid error message. Anyway, here's your message: $message" ) {
602 $this->assertTrue( true, 'MockOutputPage called, set the proper message.' );
605 $this->assertTrue( false, 'MockOutputPage was not called.' );
609 $wgShowDebug = $old_wgShowDebug;
610 unlink( $wgDebugLogFile );
615 $this->assertGreaterThan( 5000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) );
616 unlink( $wgDebugLogFile );
619 $this->assertGreaterThan( 5000000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) );
620 unlink( $wgDebugLogFile );
624 $wgDebugLogFile = $old_log_file;
628 function testClientAcceptsGzipTest() {
634 'compress, gzip' => true,
635 'gzip;q=1.0' => true,
638 'gzip;q=abcde' => true, //is this REALLY valid?
639 'gzip;q=12345678.9' => true,
643 if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
645 foreach ( $settings as $encoding => $expect ) {
646 $_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;
648 $this->assertEquals( $expect, wfClientAcceptsGzip( true ),
649 "'$encoding' => " . wfBoolToStr( $expect ) );
652 if( isset( $old_server_setting ) ) $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
658 function testSwapVarsTest() {
664 $this->assertEquals( $var1, 1, 'var1 is set originally' );
665 $this->assertEquals( $var2, 2, 'var1 is set originally' );
667 swap( $var1, $var2 );
669 $this->assertEquals( $var1, 2, 'var1 is swapped' );
670 $this->assertEquals( $var2, 1, 'var2 is swapped' );
675 function testWfPercentTest() {
678 array( 6/7, '0.86%', 2, false ),
680 array( 22/7, '3.14286%', 5 ),
681 array( 3/6, '0.5%' ),
682 array( 1/3, '0%', 0 ),
683 array( 10/3, '0%', -1 ),
684 array( 3/4/5, '0.1%', 1 ),
685 array( 6/7*8, '6.8571428571%', 10 ),
688 foreach( $pcts as $pct ) {
689 if( !isset( $pct[2] ) ) $pct[2] = 2;
690 if( !isset( $pct[3] ) ) $pct[3] = true;
692 $this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
698 function testInStringTest() {
700 $this->assertTrue( in_string( 'foo', 'foobar' ), 'foo is in foobar' );
701 $this->assertFalse( in_string( 'Bar', 'foobar' ), 'Case-sensitive by default' );
702 $this->assertTrue( in_string( 'Foo', 'foobar', true ), 'Case-insensitive when asked' );
707 * test @see wfShorthandToInteger()
708 * @dataProvider provideShorthand
710 public function testWfShorthandToInteger( $shorthand, $expected ) {
711 $this->assertEquals( $expected,
712 wfShorthandToInteger( $shorthand )
716 /** array( shorthand, expected integer ) */
717 public function provideShorthand() {
724 # Failures returns 0 :(
725 array( 'ABCDEFG', 0 ),
728 # Int, strings with spaces
732 array( ' 1023 ', 1023 ),
737 array( '1m', 1024 * 1024 ),
738 array( '1M', 1024 * 1024 ),
739 array( '1g', 1024 * 1024 * 1024 ),
740 array( '1G', 1024 * 1024 * 1024 ),
745 array( '-500', -500 ),
746 array( '-1k', -1024 ),
762 * test @see wfBCP47().
763 * Please note the BCP explicitly state that language codes are case
764 * insensitive, there are some exceptions to the rule :)
765 * This test is used to verify our formatting against all lower and
766 * all upper cases language code.
768 * @see http://tools.ietf.org/html/bcp47
769 * @dataProvider provideLanguageCodes()
771 function testBCP47( $code, $expected ) {
772 $code = strtolower( $code );
773 $this->assertEquals( $expected, wfBCP47($code),
774 "Applying BCP47 standard to lower case '$code'"
777 $code = strtoupper( $code );
778 $this->assertEquals( $expected, wfBCP47($code),
779 "Applying BCP47 standard to upper case '$code'"
784 * Array format is ($code, $expected)
786 function provideLanguageCodes() {
788 // Extracted from BCP47 (list not exhaustive)
790 array( 'en-ca-x-ca' , 'en-CA-x-ca' ),
791 array( 'sgn-be-fr' , 'sgn-BE-FR' ),
792 array( 'az-latn-x-latn', 'az-Latn-x-latn' ),
794 array( 'sr-Latn-RS', 'sr-Latn-RS' ),
795 array( 'az-arab-ir', 'az-Arab-IR' ),
798 array( 'sl-nedis' , 'sl-nedis' ),
799 array( 'de-ch-1996', 'de-CH-1996' ),
803 'en-latn-gb-boont-r-extended-sequence-x-private',
804 'en-Latn-GB-boont-r-extended-sequence-x-private'
807 // Examples from BCP47 Appendix A
808 # Simple language subtag:
813 # Language subtag plus script subtag:
814 array( 'zh-hans', 'zh-Hans'),
815 array( 'sr-cyrl', 'sr-Cyrl'),
816 array( 'sr-latn', 'sr-Latn'),
818 # Extended language subtags and their primary language subtag
820 array( 'zh-cmn-hans-cn', 'zh-cmn-Hans-CN' ),
821 array( 'cmn-hans-cn' , 'cmn-Hans-CN' ),
822 array( 'zh-yue-hk' , 'zh-yue-HK' ),
823 array( 'yue-hk' , 'yue-HK' ),
825 # Language-Script-Region:
826 array( 'zh-hans-cn', 'zh-Hans-CN' ),
827 array( 'sr-latn-RS', 'sr-Latn-RS' ),
830 array( 'sl-rozaj' , 'sl-rozaj' ),
831 array( 'sl-rozaj-biske', 'sl-rozaj-biske' ),
832 array( 'sl-nedis' , 'sl-nedis' ),
834 # Language-Region-Variant:
835 array( 'de-ch-1901' , 'de-CH-1901' ),
836 array( 'sl-it-nedis' , 'sl-IT-nedis' ),
838 # Language-Script-Region-Variant:
839 array( 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ),
842 array( 'de-de' , 'de-DE' ),
843 array( 'en-us' , 'en-US' ),
844 array( 'es-419', 'es-419'),
846 # Private use subtags:
847 array( 'de-ch-x-phonebk' , 'de-CH-x-phonebk' ),
848 array( 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ),
850 * Previous test does not reflect the BCP which states:
851 * az-Arab-x-AZE-derbend
852 * AZE being private, it should be lower case, hence the test above
853 * should probably be:
854 #array( 'az-arab-x-aze-derbend', 'az-Arab-x-AZE-derbend' ),
857 # Private use registry values:
858 array( 'x-whatever', 'x-whatever' ),
859 array( 'qaa-qaaa-qm-x-southern', 'qaa-Qaaa-QM-x-southern' ),
860 array( 'de-qaaa' , 'de-Qaaa' ),
861 array( 'sr-latn-qm', 'sr-Latn-QM' ),
862 array( 'sr-qaaa-rs', 'sr-Qaaa-RS' ),
864 # Tags that use extensions
865 array( 'en-us-u-islamcal', 'en-US-u-islamcal' ),
866 array( 'zh-cn-a-myext-x-private', 'zh-CN-a-myext-x-private' ),
867 array( 'en-a-myext-b-another', 'en-a-myext-b-another' ),
872 // ar-a-aaa-b-bbb-a-ccc
876 array( 'sr-Cyrl', 'sr-Cyrl' ),
877 # @todo FIXME: Fix our function?
878 array( 'SR-lATN', 'sr-Latn' ),
879 array( 'fr-latn', 'fr-Latn' ),
880 // Use lowercase for single segment
881 // ISO 3166-1-alpha-2 code
882 array( 'US', 'us' ), # USA
883 array( 'uS', 'us' ), # USA
884 array( 'Fr', 'fr' ), # France
885 array( 'va', 'va' ), # Holy See (Vatican City State)
890 * @dataProvider provideMakeUrlIndexes()
892 function testMakeUrlIndexes( $url, $expected ) {
893 $index = wfMakeUrlIndexes( $url );
894 $this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" );
897 function provideMakeUrlIndexes() {
901 'https://bugzilla.wikimedia.org/show_bug.cgi?id=28627',
902 array( 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627' )
905 // mailtos are handled special
906 // is this really right though? that final . probably belongs earlier?
907 'mailto:wiki@wikimedia.org',
908 array( 'mailto:org.wikimedia@wiki.' )
911 // file URL cases per bug 28627...
913 // three slashes: local filesystem path Unix-style
914 'file:///whatever/you/like.txt',
915 array( 'file://./whatever/you/like.txt' )
918 // three slashes: local filesystem path Windows-style
919 'file:///c:/whatever/you/like.txt',
920 array( 'file://./c:/whatever/you/like.txt' )
923 // two slashes: UNC filesystem path Windows-style
924 'file://intranet/whatever/you/like.txt',
925 array( 'file://intranet./whatever/you/like.txt' )
927 // Multiple-slash cases that can sorta work on Mozilla
928 // if you hack it just right are kinda pathological,
929 // and unreliable cross-platform or on IE which means they're
930 // unlikely to appear on intranets.
932 // Those will survive the algorithm but with results that
933 // are less consistent.
935 // protocol-relative URL cases per bug 29854...
937 '//bugzilla.wikimedia.org/show_bug.cgi?id=28627',
939 'http://org.wikimedia.bugzilla./show_bug.cgi?id=28627',
940 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627'
947 * @dataProvider provideWfMatchesDomainList
949 function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
950 $actual = wfMatchesDomainList( $url, $domains );
951 $this->assertEquals( $expected, $actual, $description );
954 function provideWfMatchesDomainList() {
956 $protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' );
957 foreach ( $protocols as $pDesc => $p ) {
958 $a = array_merge( $a, array(
959 array( "$p//www.example.com", array(), false, "No matches for empty domains array, $pDesc URL" ),
960 array( "$p//www.example.com", array( 'www.example.com' ), true, "Exact match in domains array, $pDesc URL" ),
961 array( "$p//www.example.com", array( 'example.com' ), true, "Match without subdomain in domains array, $pDesc URL" ),
962 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" ),
963 array( "$p//www.example2.com", array( 'example.com', 'example2.com', 'example3,com' ), true, "Match without subdomain with other domains in array, $pDesc URL" ),
964 array( "$p//www.example4.com", array( 'example.com', 'example2.com', 'example3,com' ), false, "Domain not in array, $pDesc URL" ),
966 // FIXME: This is a bug in wfMatchesDomainList(). If and when this is fixed, update this test case
967 array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), true, "Substrings of domains match while they shouldn't, $pDesc URL" ),
974 * @dataProvider provideWfShellMaintenanceCmdList
976 function testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description ) {
977 if( wfIsWindows() ) {
978 // Approximation that's good enough for our purposes just now
979 $expected = str_replace( "'", '"', $expected );
981 $actual = wfShellMaintenanceCmd( $script, $parameters, $options );
982 $this->assertEquals( $expected, $actual, $description );
985 function provideWfShellMaintenanceCmdList() {
988 array( 'eval.php', array( '--help', '--test' ), array(),
989 "'$wgPhpCli' 'eval.php' '--help' '--test'",
990 "Called eval.php --help --test" ),
991 array( 'eval.php', array( '--help', '--test space' ), array('php' => 'php5'),
992 "'php5' 'eval.php' '--help' '--test space'",
993 "Called eval.php --help --test with php option" ),
994 array( 'eval.php', array( '--help', '--test', 'X' ), array('wrapper' => 'MWScript.php'),
995 "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
996 "Called eval.php --help --test with wrapper option" ),
997 array( 'eval.php', array( '--help', '--test', 'y' ), array('php' => 'php5', 'wrapper' => 'MWScript.php'),
998 "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
999 "Called eval.php --help --test with wrapper and php option" ),
1002 /* TODO: many more! */
1006 class MockOutputPage
{
1010 function debug( $message ) {
1011 $this->message
= "JAJA is a stupid error message. Anyway, here's your message: $message";