Index: trunk/phase3/tests/phpunit/includes/GlobalTest.php |
— | — | @@ -348,6 +348,27 @@ |
349 | 349 | |
350 | 350 | } |
351 | 351 | |
| 352 | + function testTimestampParameter() { |
| 353 | + // There are a number of assumptions in our codebase where wfTimestamp() should give |
| 354 | + // the current date but it is not given a 0 there. See r71751 CR |
| 355 | + |
| 356 | + $now = wfTimestamp( TS_UNIX ); |
| 357 | + // We check that wfTimestamp doesn't return false (error) and use a LessThan assert |
| 358 | + // for the cases where the test is run in a second boundary. |
| 359 | + |
| 360 | + $zero = wfTimestamp( TS_UNIX, 0 ); |
| 361 | + $this->assertNotEquals( false, $zero ); |
| 362 | + $this->assertLessThan( 5, $zero - $now ); |
| 363 | + |
| 364 | + $empty = wfTimestamp( TS_UNIX, '' ); |
| 365 | + $this->assertNotEquals( false, $empty ); |
| 366 | + $this->assertLessThan( 5, $empty - $now ); |
| 367 | + |
| 368 | + $null = wfTimestamp( TS_UNIX, null ); |
| 369 | + $this->assertNotEquals( false, $null ); |
| 370 | + $this->assertLessThan( 5, $null - $now ); |
| 371 | + } |
| 372 | + |
352 | 373 | function testBasename() { |
353 | 374 | $sets = array( |
354 | 375 | '' => '', |
Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -1948,7 +1948,7 @@ |
1949 | 1949 | $da = array(); |
1950 | 1950 | $strtime = ''; |
1951 | 1951 | |
1952 | | - if ( $ts == 0 ) { // This intentionally catches $ts === '' and $ts === null too, so DON'T change this to === |
| 1952 | + if ( !$ts ) { // We want to catch 0, '', null... but not date strings starting with a letter. |
1953 | 1953 | $uts = time(); |
1954 | 1954 | $strtime = "@$uts"; |
1955 | 1955 | } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) { |
— | — | @@ -1988,7 +1988,7 @@ |
1989 | 1989 | # asctime |
1990 | 1990 | $strtime = $ts; |
1991 | 1991 | } else { |
1992 | | - # Bogus value; fall back to the epoch... |
| 1992 | + # Bogus value... |
1993 | 1993 | wfDebug("wfTimestamp() fed bogus time value: TYPE=$outputtype; VALUE=$ts\n"); |
1994 | 1994 | |
1995 | 1995 | return false; |