Make WordPress Core


Ignore:
Timestamp:
03/05/2025 01:13:14 PM (21 months ago)
Author:
SergeyBiryukov
Message:

Tests: Improve wp_timezone_override_offset() unit tests.

Includes:

  • Using a data provider to reduce code repetition.
  • Correcting the group annotation.

Follow-up to [59931].

See #59980.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/wpTimezoneOverrideOffset.php

    r59931 r59936  
    22
    33/**
    4  * Tests for the wp_timezone_override_offset function.
     4 * Tests for the wp_timezone_override_offset() function.
    55 *
    6  * @group Functions.php
     6 * @group functions
    77 *
    88 * @covers ::wp_timezone_override_offset
    99 */
    1010class Tests_Functions_wpTimezoneOverrideOffset extends WP_UnitTestCase {
     11
    1112        /**
    1213         * @ticket 59980
     14         *
     15         * @dataProvider data_wp_timezone_override_offset
    1316         */
    14         public function test_wp_timezone_override_offset_with_no_timezone_string_option_set() {
    15                 $this->assertSame( '', get_option( 'timezone_string' ) );
    16                 $this->assertFalse( wp_timezone_override_offset() );
     17        public function test_wp_timezone_override_offset( $timezone_string, $expected ) {
     18                update_option( 'timezone_string', $timezone_string );
     19                $this->assertSame( $expected, wp_timezone_override_offset() );
    1720        }
    1821
    1922        /**
    20          * @ticket 59980
     23         * Data provider.
     24         *
     25         * @return array[] Test parameters {
     26         *     @type string $timezone_string Test value.
     27         *     @type string $expected        Expected return value.
     28         * }
    2129         */
    22         public function test_wp_timezone_override_offset_with_bad_option_set() {
    23                 update_option( 'timezone_string', 'BAD_TIME_ZONE' );
    24                 $this->assertFalse( wp_timezone_override_offset() );
    25         }
    26 
    27         /**
    28          * @ticket 59980
    29          */
    30         public function test_wp_timezone_override_offset_with_UTC_option_set() {
    31                 update_option( 'timezone_string', 'UTC' );
    32                 $offset = wp_timezone_override_offset();
    33                 $this->assertSame( 0.0, $offset );
    34         }
    35 
    36         /**
    37          * @ticket 59980
    38          */
    39         public function test_wp_timezone_override_offset_with_EST_option_set() {
    40                 update_option( 'timezone_string', 'EST' );
    41                 $offset = wp_timezone_override_offset();
    42                 $this->assertSame( -5.0, $offset );
    43         }
    44 
    45         /**
    46          * @ticket 59980
    47          */
    48         public function test_wp_timezone_override_offset_with_NST_option_set() {
    49                 update_option( 'timezone_string', 'America/St_Johns' );
    50                 $offset = wp_timezone_override_offset();
    51                 $this->assertSame( -3.5, $offset );
     30        public function data_wp_timezone_override_offset() {
     31                return array(
     32                        'no timezone string option set' => array( '', false ),
     33                        'bad option set'                => array( 'BAD_TIME_ZONE', false ),
     34                        'UTC option set'                => array( 'UTC', 0.0 ),
     35                        'EST option set'                => array( 'EST', -5.0 ),
     36                        'NST option set'                => array( 'America/St_Johns', -3.5 ),
     37                );
    5238        }
    5339}
Note: See TracChangeset for help on using the changeset viewer.