8
8
* @covers ::is_wp_version_compatible
9
9
*/
10
10
class Tests_Functions_IsWpVersionCompatible extends WP_UnitTestCase {
11
+ /**
12
+ * The current WordPress version.
13
+ *
14
+ * @var string
15
+ */
16
+ private static $ wp_version ;
17
+
18
+ /**
19
+ * Sets the test WordPress version property and global before any tests run.
20
+ */
21
+ public static function set_up_before_class () {
22
+ parent ::set_up_before_class ();
23
+ self ::$ wp_version = wp_get_wp_version ();
24
+ $ GLOBALS ['_wp_tests_wp_version ' ] = self ::$ wp_version ;
25
+ }
26
+
27
+ /**
28
+ * Resets the test WordPress version global after each test runs.
29
+ */
30
+ public function tear_down () {
31
+ $ GLOBALS ['_wp_tests_wp_version ' ] = self ::$ wp_version ;
32
+ parent ::tear_down ();
33
+ }
34
+
35
+ /**
36
+ * Unsets the test WordPress version global after all tests run.
37
+ */
38
+ public static function tear_down_after_class () {
39
+ unset( $ GLOBALS ['_wp_tests_wp_version ' ] );
40
+ parent ::tear_down_after_class ();
41
+ }
42
+
11
43
/**
12
44
* Tests is_wp_version_compatible().
13
45
*
14
46
* @dataProvider data_is_wp_version_compatible
15
47
*
16
48
* @ticket 54257
49
+ * @ticket 61781
17
50
*
18
51
* @param mixed $required The minimum required WordPress version.
19
52
* @param bool $expected The expected result.
@@ -28,8 +61,7 @@ public function test_is_wp_version_compatible( $required, $expected ) {
28
61
* @return array[]
29
62
*/
30
63
public function data_is_wp_version_compatible () {
31
- global $ wp_version ;
32
-
64
+ $ wp_version = wp_get_wp_version ();
33
65
$ version_parts = explode ( '. ' , $ wp_version );
34
66
$ lower_version = $ version_parts ;
35
67
$ higher_version = $ version_parts ;
@@ -104,22 +136,15 @@ public function data_is_wp_version_compatible() {
104
136
* @dataProvider data_is_wp_version_compatible_should_gracefully_handle_trailing_point_zero_version_numbers
105
137
*
106
138
* @ticket 59448
139
+ * @ticket 61781
107
140
*
108
141
* @param mixed $required The minimum required WordPress version.
109
142
* @param string $wp The value for the $wp_version global variable.
110
143
* @param bool $expected The expected result.
111
144
*/
112
145
public function test_is_wp_version_compatible_should_gracefully_handle_trailing_point_zero_version_numbers ( $ required , $ wp , $ expected ) {
113
- global $ wp_version ;
114
- $ original_version = $ wp_version ;
115
- $ wp_version = $ wp ;
116
-
117
- $ actual = is_wp_version_compatible ( $ required );
118
-
119
- // Reset the version before the assertion in case of failure.
120
- $ wp_version = $ original_version ;
121
-
122
- $ this ->assertSame ( $ expected , $ actual , 'The expected result was not returned. ' );
146
+ $ GLOBALS ['_wp_tests_wp_version ' ] = $ wp ;
147
+ $ this ->assertSame ( $ expected , is_wp_version_compatible ( $ required ), 'The expected result was not returned. ' );
123
148
}
124
149
125
150
/**
@@ -183,22 +208,15 @@ public function data_is_wp_version_compatible_should_gracefully_handle_trailing_
183
208
* @dataProvider data_is_wp_version_compatible_with_development_versions
184
209
*
185
210
* @ticket 54257
211
+ * @ticket 61781
186
212
*
187
213
* @param string $required The minimum required WordPress version.
188
214
* @param string $wp The value for the $wp_version global variable.
189
215
* @param bool $expected The expected result.
190
216
*/
191
217
public function test_is_wp_version_compatible_with_development_versions ( $ required , $ wp , $ expected ) {
192
- global $ wp_version ;
193
-
194
- $ original_version = $ wp_version ;
195
- $ wp_version = $ wp ;
196
- $ actual = is_wp_version_compatible ( $ required );
197
-
198
- // Reset the version before the assertion in case of failure.
199
- $ wp_version = $ original_version ;
200
-
201
- $ this ->assertSame ( $ expected , $ actual );
218
+ $ GLOBALS ['_wp_tests_wp_version ' ] = $ wp ;
219
+ $ this ->assertSame ( $ expected , is_wp_version_compatible ( $ required ) );
202
220
}
203
221
204
222
/**
@@ -207,10 +225,8 @@ public function test_is_wp_version_compatible_with_development_versions( $requir
207
225
* @return array[]
208
226
*/
209
227
public function data_is_wp_version_compatible_with_development_versions () {
210
- global $ wp_version ;
211
-
212
228
// For consistent results, remove possible suffixes.
213
- list ( $ version ) = explode ( '- ' , $ wp_version );
229
+ list ( $ version ) = explode ( '- ' , wp_get_wp_version () );
214
230
215
231
$ version_parts = explode ( '. ' , $ version );
216
232
$ lower_version = $ version_parts ;
0 commit comments