mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 20:54:29 +00:00
Date/Time: Restore the previous behavior of date_i18n() where invalid input would result in current time.
Make `wp_date()` return `false` on invalid timestamp input, for consistency with upstream PHP `date()` function. Props Rarst. Fixes #28636. git-svn-id: https://develop.svn.wordpress.org/trunk@45914 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* @group date
|
||||
* @group datetime
|
||||
*/
|
||||
class Tests_Date_CurrentTime extends WP_UnitTestCase {
|
||||
class Tests_Date_Current_Time extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 37440
|
||||
|
||||
@@ -5,6 +5,20 @@
|
||||
* @group datetime
|
||||
*/
|
||||
class Tests_Date_I18n extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 28636
|
||||
*/
|
||||
public function test_should_return_current_time_on_invalid_timestamp() {
|
||||
$timezone = 'Europe/Kiev';
|
||||
update_option( 'timezone_string', $timezone );
|
||||
|
||||
$datetime = new DateTime( 'now', new DateTimeZone( $timezone ) );
|
||||
$wp_timestamp = $datetime->getTimestamp() + $datetime->getOffset();
|
||||
|
||||
$this->assertEquals( $wp_timestamp, date_i18n( 'U', 'invalid' ), '', 5 );
|
||||
}
|
||||
|
||||
public function test_should_format_date() {
|
||||
$this->assertEquals( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 'The dates should be equal', 2 );
|
||||
}
|
||||
@@ -74,6 +88,7 @@ class Tests_Date_I18n extends WP_UnitTestCase {
|
||||
update_option( 'timezone_string', '' );
|
||||
$offset = $datetimezone->getOffset( new DateTime() ) / 3600;
|
||||
update_option( 'gmt_offset', $offset );
|
||||
|
||||
$datetime = new DateTime( 'now', $datetimezone );
|
||||
$datetime = new DateTime( $datetime->format( 'P' ) );
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @group date
|
||||
* @group datetime
|
||||
*/
|
||||
class Tests_Date_TheDate extends WP_UnitTestCase {
|
||||
class Tests_Date_The_Date extends WP_UnitTestCase {
|
||||
|
||||
/** @var array $hooks_called Count of hooks called. */
|
||||
protected $hooks_called = array(
|
||||
|
||||
15
tests/phpunit/tests/date/wpDate.php
Normal file
15
tests/phpunit/tests/date/wpDate.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group date
|
||||
* @group datetime
|
||||
*/
|
||||
class Tests_Date_WP_Date extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 28636
|
||||
*/
|
||||
public function test_should_return_false_on_invalid_timestamp() {
|
||||
$this->assertFalse( wp_date( DATE_RFC3339, 'invalid' ) );
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
* @group date
|
||||
* @group datetime
|
||||
*/
|
||||
class Tests_WP_Timezone extends WP_UnitTestCase {
|
||||
class Tests_Date_WP_Timezone extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 24730
|
||||
|
||||
Reference in New Issue
Block a user