Add 'api' type to extension types for special version
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalTest.php
index a7ba796..b06dbf1 100644 (file)
@@ -2,19 +2,23 @@
 
 class GlobalTest extends MediaWikiTestCase {
        function setUp() {
-               global $wgReadOnlyFile, $wgContLang, $wgLang;
+               global $wgReadOnlyFile, $wgContLang, $wgLang, $wgUrlProtocols, $wgLanguageCode;
                $this->originals['wgReadOnlyFile'] = $wgReadOnlyFile;
+               $this->originals['wgUrlProtocols'] = $wgUrlProtocols;
                $wgReadOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" );
+               $wgUrlProtocols[] = 'file://';
                unlink( $wgReadOnlyFile );
+               $wgLanguageCode = 'en';
                $wgContLang = $wgLang = Language::factory( 'en' );
        }
 
        function tearDown() {
-               global $wgReadOnlyFile;
+               global $wgReadOnlyFile, $wgUrlProtocols;
                if ( file_exists( $wgReadOnlyFile ) ) {
                        unlink( $wgReadOnlyFile );
                }
                $wgReadOnlyFile = $this->originals['wgReadOnlyFile'];
+               $wgUrlProtocols = $this->originals['wgUrlProtocols'];
        }
 
        /** @dataProvider provideForWfArrayDiff2 */
@@ -98,6 +102,18 @@ class GlobalTest extends MediaWikiTestCase {
                        wfArrayToCGI(
                                array( 'baz' => 'AT&T', 'ignore' => '' ),
                                array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
+               $this->assertEquals(
+                       "path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost",
+                       wfArrayToCGI( array(
+                               'path' => array( 'wiki', 'test' ),
+                               'cfg' => array( 'servers' => array( 'http' => 'localhost' ) ) ) ) );
+       }
+
+       function testCgiToArray() {
+               $this->assertEquals(
+                       array( 'path' => array( 'wiki', 'test' ),
+                       'cfg' => array( 'servers' => array( 'http' => 'localhost' ) ) ),
+                       wfCgiToArray( 'path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost' ) );
        }
 
        function testMimeTypeMatch() {
@@ -324,7 +340,7 @@ class GlobalTest extends MediaWikiTestCase {
                        wfTimestamp( TS_RFC2822, '0117-08-09 12:34:56'),
                        'Death of Roman Emperor [[Trajan]]');
 
-               /* FIXME: 00 to 101 years are taken as being in [1970-2069] */
+               /* @todo FIXME: 00 to 101 years are taken as being in [1970-2069] */
 
                $this->assertEquals( 'Sun, 01 Jan 0101 00:00:00 GMT',
                        wfTimestamp( TS_RFC2822, '-58979923200'),
@@ -492,10 +508,12 @@ class GlobalTest extends MediaWikiTestCase {
        
        function testDebugFunctionTest() {
        
-               global $wgDebugLogFile, $wgOut, $wgShowDebug;
+               global $wgDebugLogFile, $wgOut, $wgShowDebug, $wgDebugTimestamps;
                
                $old_log_file = $wgDebugLogFile;
                $wgDebugLogFile = tempnam( wfTempDir(), 'mw-' );
+               # @todo FIXME: This setting should be tested
+               $wgDebugTimestamps = false;
                
                
                
@@ -518,8 +536,7 @@ class GlobalTest extends MediaWikiTestCase {
                $old_wgOut = $wgOut;
                $old_wgShowDebug = $wgShowDebug;
                
-               $wgOut = new StubObject( 'wgOut', 'MockOutputPage' );
-               $wgOut->doNothing(); //just to unstub it
+               $wgOut = new MockOutputPage;
                
                $wgShowDebug = true;
                
@@ -632,6 +649,61 @@ class GlobalTest extends MediaWikiTestCase {
        
        }
 
+       /**
+        * test @see wfShorthandToInteger()
+        * @dataProvider provideShorthand
+        */
+       public function testWfShorthandToInteger( $shorthand, $expected ) {
+               $this->assertEquals( $expected,
+                       wfShorthandToInteger( $shorthand )
+               );      
+       }
+
+       /** array( shorthand, expected integer ) */
+       public function provideShorthand() {
+               return array(
+                       # Null, empty ... 
+                       array(     '', -1),
+                       array(   '  ', -1),
+                       array(   null, -1),
+
+                       # Failures returns 0 :(
+                       array( 'ABCDEFG', 0 ),
+                       array( 'Ak',      0 ),
+
+                       # Int, strings with spaces
+                       array(        1,    1 ),
+                       array(    ' 1 ',    1 ),
+                       array(     1023, 1023 ),
+                       array( ' 1023 ', 1023 ),
+
+                       # kilo, Mega, Giga
+                       array(   '1k', 1024 ),
+                       array(   '1K', 1024 ),
+                       array(   '1m', 1024 * 1024 ),
+                       array(   '1M', 1024 * 1024 ),
+                       array(   '1g', 1024 * 1024 * 1024 ),
+                       array(   '1G', 1024 * 1024 * 1024 ),
+
+                       # Negatives
+                       array(     -1,    -1 ),
+                       array(   -500,  -500 ),
+                       array( '-500',  -500 ),
+                       array(  '-1k', -1024 ),
+
+                       # Zeroes
+                       array(   '0', 0 ),
+                       array(  '0k', 0 ),
+                       array(  '0M', 0 ),
+                       array(  '0G', 0 ),
+                       array(  '-0', 0 ),
+                       array( '-0k', 0 ),
+                       array( '-0M', 0 ),
+                       array( '-0G', 0 ),
+               );
+       }
+
+
        /**
         * test @see wfBCP47().
         * Please note the BCP explicitly state that language codes are case
@@ -748,7 +820,8 @@ class GlobalTest extends MediaWikiTestCase {
                /*      
                        // ISO 15924 :
                        array( 'sr-Cyrl', 'sr-Cyrl' ),
-                       array( 'SR-lATN', 'sr-Latn' ), # FIXME fix our function?
+                       # @todo FIXME: Fix our function?
+                       array( 'SR-lATN', 'sr-Latn' ),
                        array( 'fr-latn', 'fr-Latn' ),
                        // Use lowercase for single segment
                        // ISO 3166-1-alpha-2 code
@@ -759,6 +832,54 @@ class GlobalTest extends MediaWikiTestCase {
                 */);
        }
 
+       /**
+        * @dataProvider provideMakeUrlIndex()
+        */
+       function testMakeUrlIndex( $url, $expected ) {
+               $index = wfMakeUrlIndex( $url );
+               $this->assertEquals( $expected, $index, "wfMakeUrlIndex(\"$url\")" );
+       }
+
+       function provideMakeUrlIndex() {
+               return array(
+                       array(
+                               // just a regular :)
+                               'https://bugzilla.wikimedia.org/show_bug.cgi?id=28627',
+                               'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627'
+                       ),
+                       array(
+                               // mailtos are handled special
+                               // is this really right though? that final . probably belongs earlier?
+                               'mailto:wiki@wikimedia.org',
+                               'mailto:org.wikimedia@wiki.',
+                       ),
+
+                       // file URL cases per bug 28627...
+                       array(
+                               // three slashes: local filesystem path Unix-style
+                               'file:///whatever/you/like.txt',
+                               'file://./whatever/you/like.txt'
+                       ),
+                       array(
+                               // three slashes: local filesystem path Windows-style
+                               'file:///c:/whatever/you/like.txt',
+                               'file://./c:/whatever/you/like.txt'
+                       ),
+                       array(
+                               // two slashes: UNC filesystem path Windows-style
+                               'file://intranet/whatever/you/like.txt',
+                               'file://intranet./whatever/you/like.txt'
+                       ),
+                       // Multiple-slash cases that can sorta work on Mozilla
+                       // if you hack it just right are kinda pathological,
+                       // and unreliable cross-platform or on IE which means they're
+                       // unlikely to appear on intranets.
+                       //
+                       // Those will survive the algorithm but with results that
+                       // are less consistent.
+               );
+       }
+
        /* TODO: many more! */
 }
 
@@ -770,7 +891,5 @@ class MockOutputPage {
        function debug( $message ) {
                $this->message = "JAJA is a stupid error message. Anyway, here's your message: $message";
        }
-       
-       function doNothing() {}
 }