Skip to content

Commit e641b06

Browse files
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
1 parent ac057e6 commit e641b06

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed
Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,39 @@
11
<?php
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
*/
1010
class Tests_Functions_wpTimezoneOverrideOffset extends WP_UnitTestCase {
11-
/**
12-
* @ticket 59980
13-
*/
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-
}
1811

1912
/**
2013
* @ticket 59980
14+
*
15+
* @dataProvider data_wp_timezone_override_offset
2116
*/
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() );
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() );
2520
}
2621

2722
/**
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
23+
* Data provider.
24+
*
25+
* @return array[] Test parameters {
26+
* @type string $timezone_string Test value.
27+
* @type string $expected Expected return value.
28+
* }
4729
*/
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
}

0 commit comments

Comments
 (0)