Skip to content

Commit 6e5eee3

Browse files
committed
Tests: reset timezone related options if the tests change them
The `options` table is **not** reset after each test/test class, so if an option is changed during a tests, it should be reset to the default value _after_ the test. This commit does so for those tests which didn't have such resetting in place yet, while one or more tests in the class _do_ change the value of the `timezone_string` option. Follow up on Trac#45821, [45857]
1 parent 2030b22 commit 6e5eee3

File tree

10 files changed

+79
-2
lines changed

10 files changed

+79
-2
lines changed

tests/phpunit/tests/date/currentTime.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
*/
88
class Tests_Date_CurrentTime extends WP_UnitTestCase {
99

10+
/**
11+
* Clean up.
12+
*/
13+
public function tear_down() {
14+
// Reset changed options to their default value.
15+
update_option( 'gmt_offset', 0 );
16+
update_option( 'timezone_string', '' );
17+
18+
parent::tear_down();
19+
}
20+
1021
/**
1122
* @ticket 34378
1223
*/

tests/phpunit/tests/date/dateI18n.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
*/
88
class Tests_Date_DateI18n extends WP_UnitTestCase {
99

10+
/**
11+
* Clean up.
12+
*/
13+
public function tear_down() {
14+
// Reset changed options to their default value.
15+
update_option( 'gmt_offset', 0 );
16+
update_option( 'timezone_string', '' );
17+
18+
parent::tear_down();
19+
}
20+
1021
/**
1122
* @ticket 28636
1223
*/

tests/phpunit/tests/date/getFeedBuildDate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Tests_Date_GetFeedBuildDate extends WP_UnitTestCase {
1111
public function tear_down() {
1212
global $wp_query;
1313

14-
update_option( 'timezone_string', 'UTC' );
14+
update_option( 'timezone_string', '' );
1515

1616
unset( $wp_query );
1717

tests/phpunit/tests/date/getPermalink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Tests_Date_GetPermalink extends WP_UnitTestCase {
1010

1111
public function tear_down() {
1212
delete_option( 'permalink_structure' );
13-
update_option( 'timezone_string', 'UTC' );
13+
update_option( 'timezone_string', '' );
1414
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
1515
date_default_timezone_set( 'UTC' );
1616

tests/phpunit/tests/date/getPostTime.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
*/
1010
class Tests_Date_GetPostTime extends WP_UnitTestCase {
1111

12+
/**
13+
* Clean up.
14+
*/
15+
public function tear_down() {
16+
// Reset the timezone option to the default value.
17+
update_option( 'timezone_string', '' );
18+
19+
parent::tear_down();
20+
}
21+
1222
/**
1323
* @ticket 28310
1424
*/

tests/phpunit/tests/date/mysql2date.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public function tear_down() {
1111
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
1212
date_default_timezone_set( 'UTC' );
1313

14+
// Reset the timezone option to the default value.
15+
update_option( 'timezone_string', '' );
16+
1417
parent::tear_down();
1518
}
1619

tests/phpunit/tests/date/query.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public function set_up() {
2121
$this->q = new WP_Date_Query( array( 'm' => 2 ) );
2222
}
2323

24+
/**
25+
* Clean up.
26+
*/
27+
public function tear_down() {
28+
// Reset the timezone option to the default value.
29+
update_option( 'timezone_string', '' );
30+
31+
parent::tear_down();
32+
}
33+
2434
public function test_construct_date_query_empty() {
2535
$q = new WP_Date_Query( array() );
2636
$this->assertSame( 'AND', $q->relation );

tests/phpunit/tests/date/wpTimezone.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
*/
99
class Tests_Date_wpTimezone extends WP_UnitTestCase {
1010

11+
/**
12+
* Clean up.
13+
*/
14+
public function tear_down() {
15+
// Reset changed options to their default value.
16+
update_option( 'gmt_offset', 0 );
17+
update_option( 'timezone_string', '' );
18+
19+
parent::tear_down();
20+
}
21+
1122
/**
1223
* @ticket 24730
1324
*

tests/phpunit/tests/date/xmlrpc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
*/
99
class Tests_Date_XMLRPC extends WP_XMLRPC_UnitTestCase {
1010

11+
/**
12+
* Clean up.
13+
*/
14+
public function tear_down() {
15+
// Reset the timezone option to the default value.
16+
update_option( 'timezone_string', '' );
17+
18+
parent::tear_down();
19+
}
20+
1121
/**
1222
* @ticket 30429
1323
*

tests/phpunit/tests/formatting/date.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
*/
77
class Tests_Formatting_Date extends WP_UnitTestCase {
88

9+
/**
10+
* Clean up.
11+
*/
12+
public function tear_down() {
13+
// Reset changed options to their default value.
14+
update_option( 'gmt_offset', 0 );
15+
update_option( 'timezone_string', '' );
16+
17+
parent::tear_down();
18+
}
19+
920
/**
1021
* Unpatched, this test passes only when Europe/London is not observing DST.
1122
*

0 commit comments

Comments
 (0)