mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-14 01:24:27 +00:00
Date/Time: Make get_permalink() more resilient against PHP timezone changes.
Overriding default PHP timezone with `date_default_timezone_set()`, while not recommended, should not inadvertently result in changing existing permalinks. Add a unit test. Props Rarst, steevithak, archon810, maciejmackowiak, Ov3rfly, Cybr, hometowntrailers, scvleon, miette49. Fixes #48623. git-svn-id: https://develop.svn.wordpress.org/trunk@46795 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
39
tests/phpunit/tests/date/getPermalink.php
Normal file
39
tests/phpunit/tests/date/getPermalink.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group date
|
||||
* @group datetime
|
||||
* @group post
|
||||
*/
|
||||
class Tests_Date_Get_Permalink extends WP_UnitTestCase {
|
||||
|
||||
function tearDown() {
|
||||
delete_option( 'permalink_structure' );
|
||||
update_option( 'timezone_string', 'UTC' );
|
||||
date_default_timezone_set( 'UTC' );
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 48623
|
||||
*/
|
||||
public function test_should_return_correct_date_permalink_with_changed_time_zone() {
|
||||
$timezone = 'America/Chicago';
|
||||
update_option( 'timezone_string', $timezone );
|
||||
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%hour%/%minute%/%second%' );
|
||||
date_default_timezone_set( 'UTC' );
|
||||
|
||||
$post_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_date' => '2018-07-22 21:13:23',
|
||||
'post_date_gmt' => '2018-07-23 03:13:23',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( 'http://example.org/2018/07/22/21/13/23', get_permalink( $post_id ) );
|
||||
|
||||
date_default_timezone_set( $timezone );
|
||||
$this->assertEquals( 'http://example.org/2018/07/22/21/13/23', get_permalink( $post_id ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user