* Fix and fix
[lhc/web/wiklou.git] / tests / GlobalTest.php
index aa44a2b..1567a18 100644 (file)
@@ -2,13 +2,14 @@
 
 require_once( 'PHPUnit.php' );
 require_once( '../includes/Defines.php' );
+require_once( '../includes/Profiling.php' );
 require_once( '../includes/GlobalFunctions.php' );
 
 class GlobalTest extends PHPUnit_TestCase {
        function GlobalTest( $name ) {
                $this->PHPUnit_TestCase( $name );
        }
-       
+
        function setUp() {
                $this->save = array();
                $saveVars = array( 'wgReadOnlyFile' );
@@ -17,102 +18,54 @@ class GlobalTest extends PHPUnit_TestCase {
                                $this->save[$var] = $GLOBALS[$var];
                        }
                }
-               $GLOBALS['wgReadOnlyFile'] = '/tmp/testReadOnly-' . mt_rand();
+               $GLOBALS['wgReadOnlyFile'] = wfTempDir() . '/testReadOnly-' . mt_rand();
        }
-       
+
        function tearDown() {
                foreach( $this->save as $var => $data ) {
                        $GLOBALS[$var] = $data;
                }
        }
-       
-       function testDecodeLatin() {
-               $this->assertEquals(
-                       "\xe9cole",
-                       do_html_entity_decode( 'école', ENT_COMPAT, 'iso-8859-1' ) );
-       }
-
-       function testDecodeUnicode() {
-               $this->assertEquals(
-                       "\xc3\xa9cole",
-                       do_html_entity_decode( 'école', ENT_COMPAT, 'utf-8' ) );
-       }
 
        function testRandom() {
                # This could hypothetically fail, but it shouldn't ;)
                $this->assertFalse(
                        wfRandom() == wfRandom() );
        }
-       
+
        function testUrlencode() {
                $this->assertEquals(
                        "%E7%89%B9%E5%88%A5:Contributions/Foobar",
                        wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
        }
-       
-       function testUtf8Sequence1() {
-               $this->assertEquals(
-                       'A',
-                       wfUtf8Sequence( 65 ) );
-       }
-       
-       function testUtf8Sequence2() {
-               $this->assertEquals(
-                       "\xc4\x88",
-                       wfUtf8Sequence( 0x108 ) );
-       }
 
-       function testUtf8Sequence3() {
-               $this->assertEquals(
-                       "\xe3\x81\x8b",
-                       wfUtf8Sequence( 0x304b ) );
-       }
-
-       function testUtf8Sequence4() {
-               $this->assertEquals(
-                       "\xf0\x90\x91\x90",
-                       wfUtf8Sequence( 0x10450 ) );
-       }
-       
-       function testMungeToUtf8() {
-               $this->assertEquals(
-                       "\xc4\x88io bonas dans l'\xc3\xa9cole!",
-                       wfMungeToUtf8( "Ĉio bonas dans l'école!" ) );
-       }
-       
-       function testUtf8ToHTML() {
-               $this->assertEquals(
-                       "Ĉio bonas dans l'école!",
-                       wfUtf8ToHTML( "\xc4\x88io bonas dans l'\xc3\xa9cole!" ) );
-       }
-       
        function testReadOnlyEmpty() {
                $this->assertFalse( wfReadOnly() );
        }
-       
+
        function testReadOnlySet() {
                $f = fopen( $GLOBALS['wgReadOnlyFile'], "wt" );
                fwrite( $f, 'Message' );
                fclose( $f );
                $this->assertTrue( wfReadOnly() );
-               
+
                unlink( $GLOBALS['wgReadOnlyFile'] );
                $this->assertFalse( wfReadOnly() );
        }
-       
+
        function testQuotedPrintable() {
                $this->assertEquals(
                        "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
                        wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
        }
-       
+
        function testTime() {
                $start = wfTime();
                $this->assertType( 'double', $start );
                $end = wfTime();
                $this->assertTrue( $end > $start, "Time is running backwards!" );
        }
-       
+
        function testArrayToCGI() {
                $this->assertEquals(
                        "baz=AT%26T&foo=bar",
@@ -120,7 +73,7 @@ class GlobalTest extends PHPUnit_TestCase {
                                array( 'baz' => 'AT&T', 'ignore' => '' ),
                                array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
        }
-       
+
        function testMimeTypeMatch() {
                $this->assertEquals(
                        'text/html',
@@ -142,7 +95,7 @@ class GlobalTest extends PHPUnit_TestCase {
                                array( 'image/png'     => 1.0,
                                       'image/svg+xml' => 0.5 ) ) );
        }
-       
+
        function testNegotiateType() {
                $this->assertEquals(
                        'text/html',
@@ -183,7 +136,75 @@ class GlobalTest extends PHPUnit_TestCase {
                                array( 'text/*'                => 1.0 ),
                                array( 'application/xhtml+xml' => 1.0 ) ) );
        }
-       
+
+       function testTimestamp() {
+               $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
+               $this->assertEquals(
+                       '20010115123456',
+                       wfTimestamp( TS_MW, $t ),
+                       'TS_UNIX to TS_MW' );
+               $this->assertEquals(
+                       979562096,
+                       wfTimestamp( TS_UNIX, $t ),
+                       'TS_UNIX to TS_UNIX' );
+               $this->assertEquals(
+                       '2001-01-15 12:34:56',
+                       wfTimestamp( TS_DB, $t ),
+                       'TS_UNIX to TS_DB' );
+
+               $this->assertEquals(
+                       '20010115123456',
+                       wfTimestamp( TS_MW, '20010115123456' ),
+                       'TS_MW to TS_MW' );
+               $this->assertEquals(
+                       979562096,
+                       wfTimestamp( TS_UNIX, '20010115123456' ),
+                       'TS_MW to TS_UNIX' );
+               $this->assertEquals(
+                       '2001-01-15 12:34:56',
+                       wfTimestamp( TS_DB, '20010115123456' ),
+                       'TS_MW to TS_DB' );
+
+               $this->assertEquals(
+                       '20010115123456',
+                       wfTimestamp( TS_MW, '2001-01-15 12:34:56' ),
+                       'TS_DB to TS_MW' );
+               $this->assertEquals(
+                       979562096,
+                       wfTimestamp( TS_UNIX, '2001-01-15 12:34:56' ),
+                       'TS_DB to TS_UNIX' );
+               $this->assertEquals(
+                       '2001-01-15 12:34:56',
+                       wfTimestamp( TS_DB, '2001-01-15 12:34:56' ),
+                       'TS_DB to TS_DB' );
+       }
+       
+       function testBasename() {
+               $sets = array(
+                       '' => '',
+                       '/' => '',
+                       '\\' => '',
+                       '//' => '',
+                       '\\\\' => '',
+                       'a' => 'a',
+                       'aaaa' => 'aaaa',
+                       '/a' => 'a',
+                       '\\a' => 'a',
+                       '/aaaa' => 'aaaa',
+                       '\\aaaa' => 'aaaa',
+                       '/aaaa/' => 'aaaa',
+                       '\\aaaa\\' => 'aaaa',
+                       '\\aaaa\\' => 'aaaa',
+                       '/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',
+                       'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
+                       'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
+                       );
+               foreach( $sets as $from => $to ) {
+                       $this->assertEquals( $to, wfBaseName( $from ),
+                               "wfBaseName('$from') => '$to'");
+               }
+       }
+
        /* TODO: many more! */
 }