Make WordPress Core

Changeset 54207


Ignore:
Timestamp:
09/19/2022 05:43:55 PM (22 months ago)
Author:
SergeyBiryukov
Message:

Tests: Reset timezone-related options if the tests change them.

The options table is not explicitly reset after each test or test class, so if an option is changed during a test, it should be reset to the default value after the test.

This commit does so for those tests which did not have such resetting in place yet, while one or more tests in the class do change the value of the timezone_string option.

Note: The test suite executes a ROLLBACK query after each test, which should reset the options table in theory, however that appears to not always be enough, as some timezone-related tests can fail in a complete test suite run, while not failing when run in isolation. This commit aims to improve stability of the tests.

Follow-up to [45857] / #45821.

Props jrf, costdev.
See #56468.

Location:
trunk/tests/phpunit/tests
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/date/currentTime.php

    r51331 r54207  
    77 */
    88class Tests_Date_CurrentTime extends WP_UnitTestCase {
     9
     10    /**
     11     * Cleans 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    }
    920
    1021    /**
  • trunk/tests/phpunit/tests/date/dateI18n.php

    r50291 r54207  
    77 */
    88class Tests_Date_DateI18n extends WP_UnitTestCase {
     9
     10    /**
     11     * Cleans 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    }
    920
    1021    /**
  • trunk/tests/phpunit/tests/date/getFeedBuildDate.php

    r54090 r54207  
    1212        global $wp_query;
    1313
    14         update_option( 'timezone_string', 'UTC' );
     14        update_option( 'timezone_string', '' );
    1515
    1616        unset( $wp_query );
  • trunk/tests/phpunit/tests/date/getPermalink.php

    r52010 r54207  
    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' );
  • trunk/tests/phpunit/tests/date/getPostTime.php

    r50291 r54207  
    99 */
    1010class Tests_Date_GetPostTime extends WP_UnitTestCase {
     11
     12    /**
     13     * Cleans 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    }
    1121
    1222    /**
  • trunk/tests/phpunit/tests/date/mysql2date.php

    r52010 r54207  
    1111        // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
    1212        date_default_timezone_set( 'UTC' );
     13
     14        // Reset the timezone option to the default value.
     15        update_option( 'timezone_string', '' );
    1316
    1417        parent::tear_down();
  • trunk/tests/phpunit/tests/date/query.php

    r51568 r54207  
    2020        unset( $this->q );
    2121        $this->q = new WP_Date_Query( array( 'm' => 2 ) );
     22    }
     23
     24    /**
     25     * Cleans 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();
    2232    }
    2333
  • trunk/tests/phpunit/tests/date/wpTimezone.php

    r50291 r54207  
    88 */
    99class Tests_Date_wpTimezone extends WP_UnitTestCase {
     10
     11    /**
     12     * Cleans 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    }
    1021
    1122    /**
  • trunk/tests/phpunit/tests/date/xmlrpc.php

    r54090 r54207  
    88 */
    99class Tests_Date_XMLRPC extends WP_XMLRPC_UnitTestCase {
     10
     11    /**
     12     * Cleans 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    }
    1020
    1121    /**
  • trunk/tests/phpunit/tests/formatting/date.php

    r53562 r54207  
    66 */
    77class Tests_Formatting_Date extends WP_UnitTestCase {
     8
     9    /**
     10     * Cleans 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    }
    819
    920    /**
Note: See TracChangeset for help on using the changeset viewer.