From 62f2f7b879fbbe4249172dae488687cafc26f462 Mon Sep 17 00:00:00 2001 From: Platonides Date: Thu, 30 Dec 2010 16:10:42 +0000 Subject: [PATCH] Fix r71751 problems with textual parameters. Add a test for checking the problems which appeared in r71751 --- includes/GlobalFunctions.php | 4 ++-- tests/phpunit/includes/GlobalTest.php | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index a7b06963e8..04b0e6b9f3 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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; diff --git a/tests/phpunit/includes/GlobalTest.php b/tests/phpunit/includes/GlobalTest.php index f0deabdea3..51b0040952 100644 --- a/tests/phpunit/includes/GlobalTest.php +++ b/tests/phpunit/includes/GlobalTest.php @@ -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( '' => '', -- 2.20.1