From e641b06f0f216030097a5621eb36e59041e09055 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 5 Mar 2025 13:13:14 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@59936 602fd350-edb4-49c9-b593-d223f7449a82 --- .../functions/wpTimezoneOverrideOffset.php | 56 +++++++------------ 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/tests/phpunit/tests/functions/wpTimezoneOverrideOffset.php b/tests/phpunit/tests/functions/wpTimezoneOverrideOffset.php index 3b92e8c6fe..33a740c243 100644 --- a/tests/phpunit/tests/functions/wpTimezoneOverrideOffset.php +++ b/tests/phpunit/tests/functions/wpTimezoneOverrideOffset.php @@ -1,53 +1,39 @@ assertSame( '', get_option( 'timezone_string' ) ); - $this->assertFalse( wp_timezone_override_offset() ); - } /** * @ticket 59980 + * + * @dataProvider data_wp_timezone_override_offset */ - public function test_wp_timezone_override_offset_with_bad_option_set() { - update_option( 'timezone_string', 'BAD_TIME_ZONE' ); - $this->assertFalse( wp_timezone_override_offset() ); + public function test_wp_timezone_override_offset( $timezone_string, $expected ) { + update_option( 'timezone_string', $timezone_string ); + $this->assertSame( $expected, wp_timezone_override_offset() ); } /** - * @ticket 59980 + * Data provider. + * + * @return array[] Test parameters { + * @type string $timezone_string Test value. + * @type string $expected Expected return value. + * } */ - public function test_wp_timezone_override_offset_with_UTC_option_set() { - update_option( 'timezone_string', 'UTC' ); - $offset = wp_timezone_override_offset(); - $this->assertSame( 0.0, $offset ); - } - - /** - * @ticket 59980 - */ - public function test_wp_timezone_override_offset_with_EST_option_set() { - update_option( 'timezone_string', 'EST' ); - $offset = wp_timezone_override_offset(); - $this->assertSame( -5.0, $offset ); - } - - /** - * @ticket 59980 - */ - public function test_wp_timezone_override_offset_with_NST_option_set() { - update_option( 'timezone_string', 'America/St_Johns' ); - $offset = wp_timezone_override_offset(); - $this->assertSame( -3.5, $offset ); + public function data_wp_timezone_override_offset() { + return array( + 'no timezone string option set' => array( '', false ), + 'bad option set' => array( 'BAD_TIME_ZONE', false ), + 'UTC option set' => array( 'UTC', 0.0 ), + 'EST option set' => array( 'EST', -5.0 ), + 'NST option set' => array( 'America/St_Johns', -3.5 ), + ); } }