mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
The `Europe/Kiev` timezone has been deprecated in PHP 8.2 and replaced with `Europe/Kyiv`. The tests updated in this commit are testing the WordPress date/time functionality. They are **not** testing whether WP or PHP can handle deprecated timezone names correctly. To ensure the tests follow the original purpose, the use of `Europe/Kiev` within these tests is now replaced with the `Europe/Helsinki` timezone, which is within the same timezone as `Europe/Kyiv`. This should ensure that these tests run without issue and test what they are supposed to be testing on every supported PHP version (unless at some point in the future `Europe/Helsinki` would be renamed, but that's a bridge to cross if and when). Note: Separate tests should/will be added to ensure that relevant date/time related functions handle a deprecated timezone correctly, but that is not something ''these'' tests are supposed to be testing. Follow-up to [45853], [45856], [45876], [45882], [45887], [45908], [45914], [46577], [46154], [46580], [46864], [46974], [54207]. Props jrf, costdev. See #56468. git-svn-id: https://develop.svn.wordpress.org/trunk@54217 602fd350-edb4-49c9-b593-d223f7449a82
86 lines
2.0 KiB
PHP
86 lines
2.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group date
|
|
* @group datetime
|
|
* @group feed
|
|
* @covers ::get_feed_build_date
|
|
*/
|
|
class Tests_Date_GetFeedBuildDate extends WP_UnitTestCase {
|
|
|
|
public function tear_down() {
|
|
global $wp_query;
|
|
|
|
update_option( 'timezone_string', '' );
|
|
|
|
unset( $wp_query );
|
|
|
|
parent::tear_down();
|
|
}
|
|
|
|
/**
|
|
* @ticket 48675
|
|
*/
|
|
public function test_should_return_correct_feed_build_date() {
|
|
global $wp_query;
|
|
|
|
$timezone = 'America/Chicago';
|
|
update_option( 'timezone_string', $timezone );
|
|
|
|
$post_id = self::factory()->post->create(
|
|
array(
|
|
'post_date' => '2018-07-22 21:13:23',
|
|
'post_date_gmt' => '2018-07-23 03:13:23',
|
|
)
|
|
);
|
|
|
|
$wp_query = new WP_Query( array( 'p' => $post_id ) );
|
|
|
|
$this->assertSame( '2018-07-23T03:13:23+00:00', get_feed_build_date( DATE_RFC3339 ) );
|
|
}
|
|
|
|
/**
|
|
* Test that get_feed_build_date() works with invalid post dates.
|
|
*
|
|
* @ticket 48957
|
|
*/
|
|
public function test_should_fall_back_to_last_post_modified() {
|
|
global $wp_query;
|
|
|
|
update_option( 'timezone_string', 'Europe/Helsinki' );
|
|
$datetime = new DateTimeImmutable( 'now', wp_timezone() );
|
|
$datetime_utc = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
|
|
|
|
$wp_query->posts = array();
|
|
|
|
$this->assertFalse( get_feed_build_date( DATE_RFC3339 ), 'False when unable to determine valid time' );
|
|
|
|
self::factory()->post->create(
|
|
array(
|
|
'post_date' => $datetime->format( 'Y-m-d H:i:s' ),
|
|
)
|
|
);
|
|
|
|
$this->assertEqualsWithDelta(
|
|
strtotime( $datetime_utc->format( DATE_RFC3339 ) ),
|
|
strtotime( get_feed_build_date( DATE_RFC3339 ) ),
|
|
2,
|
|
'Fall back to time of last post modified with no posts'
|
|
);
|
|
|
|
$post_id_broken = self::factory()->post->create();
|
|
$post_broken = get_post( $post_id_broken );
|
|
|
|
$post_broken->post_modified_gmt = 0;
|
|
|
|
$wp_query->posts = array( $post_broken );
|
|
|
|
$this->assertEqualsWithDelta(
|
|
strtotime( $datetime_utc->format( DATE_RFC3339 ) ),
|
|
strtotime( get_feed_build_date( DATE_RFC3339 ) ),
|
|
2,
|
|
'Fall back to time of last post modified with broken post object'
|
|
);
|
|
}
|
|
}
|