Fix r71751 problems with textual parameters.
authorPlatonides <platonides@users.mediawiki.org>
Thu, 30 Dec 2010 16:10:42 +0000 (16:10 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Thu, 30 Dec 2010 16:10:42 +0000 (16:10 +0000)
Add a test for checking the problems which appeared in r71751

includes/GlobalFunctions.php
tests/phpunit/includes/GlobalTest.php

index a7b0696..04b0e6b 100644 (file)
@@ -1948,7 +1948,7 @@ function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
        $da = array();
        $strtime = '';
 
-       if ( $ts == 0 ) { // This intentionally catches $ts === '' and $ts === null too, so DON'T change this to ===
+       if ( !$ts ) { // We want to catch 0, '', null... but not date strings starting with a letter.
                $uts = time();
                $strtime = "@$uts";
        } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
@@ -1988,7 +1988,7 @@ function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
                # asctime
                $strtime = $ts;
        } else {
-               # Bogus value; fall back to the epoch...
+               # Bogus value...
                wfDebug("wfTimestamp() fed bogus time value: TYPE=$outputtype; VALUE=$ts\n");
 
                return false;
index f0deabd..51b0040 100644 (file)
@@ -348,6 +348,27 @@ class GlobalTest extends MediaWikiTestCase {
 
        }
 
+       function testTimestampParameter() {
+               // There are a number of assumptions in our codebase where wfTimestamp() should give 
+               // the current date but it is not given a 0 there. See r71751 CR
+
+               $now = wfTimestamp( TS_UNIX );
+               // We check that wfTimestamp doesn't return false (error) and use a LessThan assert 
+               // for the cases where the test is run in a second boundary.
+               
+               $zero = wfTimestamp( TS_UNIX, 0 );
+               $this->assertNotEquals( false, $zero );
+               $this->assertLessThan( 5, $zero - $now );
+
+               $empty = wfTimestamp( TS_UNIX, '' );
+               $this->assertNotEquals( false, $empty );
+               $this->assertLessThan( 5, $empty - $now );
+
+               $null = wfTimestamp( TS_UNIX, null );
+               $this->assertNotEquals( false, $null );
+               $this->assertLessThan( 5, $null - $now );
+       }
+
        function testBasename() {
                $sets = array(
                        '' => '',