Skip to content

Commit 69c05ff

Browse files
committed
Tests: Make formatting test data providers static.
Declare the data providers in `tests/phpunit/tests/formatting/` as `public static` for compatibility with newer PHPUnit versions. Preserve their datasets and assertions. Use static properties for the emoji CDN fixture values. Developed in: #14381 Props rejaulalomkhan, mukesh27. See #66211. git-svn-id: https://develop.svn.wordpress.org/trunk@64439 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5fad21a commit 69c05ff

42 files changed

Lines changed: 118 additions & 118 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎tests/phpunit/tests/formatting/antispambot.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function test_returns_valid_utf8( $email ) {
2828
*
2929
* return array[]
3030
*/
31-
public function data_returns_valid_utf8() {
31+
public static function data_returns_valid_utf8() {
3232
return array(
3333
'plain' => array( 'bob@example.com' ),
3434
'plain with ip' => array( 'ace@204.32.222.14' ),
@@ -76,7 +76,7 @@ public function test_antispambot_obfuscates( $provided ) {
7676
*
7777
* @return Generator
7878
*/
79-
public function data_antispambot_obfuscates() {
79+
public static function data_antispambot_obfuscates() {
8080
$addresses = array(
8181
'example@example.com',
8282
'#@example.com',

‎tests/phpunit/tests/formatting/autopNewlinePreservationHelper.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function test_should_replace_newlines_with_placeholders( $matches, $expec
2626
*
2727
* @return array[]
2828
*/
29-
public function data_should_replace_newlines_with_placeholders() {
29+
public static function data_should_replace_newlines_with_placeholders() {
3030
return array(
3131
'an empty string' => array(
3232
'matches' => array( '' ),
@@ -89,7 +89,7 @@ public function test_should_only_replace_line_feeds( $matches, $expected ) {
8989
*
9090
* @return array[]
9191
*/
92-
public function data_should_only_replace_line_feeds() {
92+
public static function data_should_only_replace_line_feeds() {
9393
return array(
9494
'a carriage return' => array(
9595
'matches' => array( "a\rb" ),
@@ -151,7 +151,7 @@ public function test_should_preserve_newlines_as_a_preg_replace_callback( $text,
151151
*
152152
* @return array[]
153153
*/
154-
public function data_should_preserve_newlines_as_a_preg_replace_callback() {
154+
public static function data_should_preserve_newlines_as_a_preg_replace_callback() {
155155
return array(
156156
'a script element' => array(
157157
'text' => "<script>\nvar a = 1;\n</script>",

‎tests/phpunit/tests/formatting/balanceTags.php‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function test_detects_traditional_tag_names( $tag ) {
1717
$this->assertSame( "<$normalized>inside</$normalized>", balanceTags( "<$tag>inside", true ) );
1818
}
1919

20-
public function data_supported_traditional_tag_names() {
20+
public static function data_supported_traditional_tag_names() {
2121
return array(
2222
array( 'a' ),
2323
array( 'div' ),
@@ -37,7 +37,7 @@ public function test_detects_supported_custom_element_tag_names( $tag ) {
3737
$this->assertSame( "<$tag>inside</$tag>", balanceTags( "<$tag>inside", true ) );
3838
}
3939

40-
public function data_supported_custom_element_tag_names() {
40+
public static function data_supported_custom_element_tag_names() {
4141
return array(
4242
array( 'custom-element' ),
4343
array( 'my-custom-element' ),
@@ -57,7 +57,7 @@ public function test_ignores_invalid_tag_names( $input, $output ) {
5757
$this->assertSame( $output, balanceTags( $input, true ) );
5858
}
5959

60-
public function data_invalid_tag_names() {
60+
public static function data_invalid_tag_names() {
6161
return array(
6262
array( '<0-day>inside', '&lt;0-day>inside' ), // Can't start with a number - handled by the "<3" fix.
6363
array( '<UPPERCASE-TAG>inside', '<UPPERCASE-TAG>inside' ), // Custom elements cannot be uppercase.
@@ -77,7 +77,7 @@ public function test_ignores_unsupported_custom_tag_names( $tag ) {
7777
*
7878
* @link https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
7979
*/
80-
public function data_unsupported_valid_tag_names() {
80+
public static function data_unsupported_valid_tag_names() {
8181
return array(
8282
// We don't allow ending in a dash.
8383
array( '<what->inside' ),
@@ -145,7 +145,7 @@ public function test_detects_supported_invalid_tag_names( $tag ) {
145145
*
146146
* @link https://w3c.github.io/webcomponents/spec/custom/#valid-custom-element-name
147147
*/
148-
public function data_supported_invalid_tag_names() {
148+
public static function data_supported_invalid_tag_names() {
149149
return array(
150150
// Reserved names for custom elements.
151151
array( 'annotation-xml' ),
@@ -181,7 +181,7 @@ public function test_selfcloses_known_single_tags_having_closing_tag( $tag ) {
181181
}
182182

183183
// This is a complete(?) listing of valid single/self-closing tags.
184-
public function data_single_tags() {
184+
public static function data_single_tags() {
185185
return array(
186186
array( 'area' ),
187187
array( 'base' ),
@@ -219,7 +219,7 @@ public function test_closes_unknown_single_tags_with_closing_tag( $input, $expec
219219
*
220220
* @return array<string, array<string, string>>
221221
*/
222-
public function data_unknown_single_tags_with_closing_tag() {
222+
public static function data_unknown_single_tags_with_closing_tag() {
223223
return array(
224224
'default' => array( '<strong/>', '<strong></strong>' ),
225225
'with-space' => array( '<em />', '<em></em>' ),
@@ -278,7 +278,7 @@ public function test_balances_nestable_tags( $tag ) {
278278
}
279279
}
280280

281-
public function data_nestable_tags() {
281+
public static function data_nestable_tags() {
282282
return array(
283283
array( 'article' ),
284284
array( 'aside' ),
@@ -390,7 +390,7 @@ public function test_removes_extraneous_closing_tags() {
390390
*
391391
* @return array Data.
392392
*/
393-
public function data_custom_elements() {
393+
public static function data_custom_elements() {
394394
return array(
395395
// Valid custom element tags.
396396
array(

‎tests/phpunit/tests/formatting/convertSmilies.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function test_convert_standard_smilies( $input, $converted ) {
3939
* }
4040
* }
4141
*/
42-
public function data_convert_standard_smilies() {
42+
public static function data_convert_standard_smilies() {
4343
$includes_path = includes_url( 'images/smilies/' );
4444

4545
return array(
@@ -109,7 +109,7 @@ public function test_convert_custom_smilies( $input, $converted ) {
109109
* }
110110
* }
111111
*/
112-
public function data_convert_custom_smilies() {
112+
public static function data_convert_custom_smilies() {
113113
$includes_path = includes_url( 'images/smilies/' );
114114

115115
return array(
@@ -153,7 +153,7 @@ public function test_ignore_smilies_in_tags( $element ) {
153153
* }
154154
* }
155155
*/
156-
public function data_ignore_smilies_in_tags() {
156+
public static function data_ignore_smilies_in_tags() {
157157
return array(
158158
array( 'pre' ),
159159
array( 'code' ),
@@ -189,7 +189,7 @@ public function test_smilies_combinations( $input, $converted ) {
189189
* }
190190
* }
191191
*/
192-
public function data_smilies_combinations() {
192+
public static function data_smilies_combinations() {
193193
$includes_path = includes_url( 'images/smilies/' );
194194

195195
return array(
@@ -258,7 +258,7 @@ public function test_single_smilies_in_wpsmiliestrans( $input, $converted ) {
258258
* }
259259
* }
260260
*/
261-
public function data_single_smilies_in_wpsmiliestrans() {
261+
public static function data_single_smilies_in_wpsmiliestrans() {
262262
$includes_path = includes_url( 'images/smilies/' );
263263

264264
return array(
@@ -301,7 +301,7 @@ public function test_spaces_around_smilies( $input, $converted ) {
301301
* }
302302
* }
303303
*/
304-
public function data_spaces_around_smilies() {
304+
public static function data_spaces_around_smilies() {
305305
$nbsp = "\xC2\xA0";
306306

307307
return array(

‎tests/phpunit/tests/formatting/date.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public function test_is8601_to_datetime_correct_time( $timezone_string, $gmt_off
231231
*
232232
* @return array
233233
*/
234-
public function data_timezone_provider() {
234+
public static function data_timezone_provider() {
235235
return array(
236236
'valid timezone string and GMT offset' => array(
237237
'timezone_string' => 'Europe/Helsinki',

‎tests/phpunit/tests/formatting/emoji.php‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77
class Tests_Formatting_Emoji extends WP_UnitTestCase {
88

9-
private $png_cdn = 'https://s.w.org/images/core/emoji/17.0.2/72x72/';
10-
private $svg_cdn = 'https://s.w.org/images/core/emoji/17.0.2/svg/';
9+
private static $png_cdn = 'https://s.w.org/images/core/emoji/17.0.2/72x72/';
10+
private static $svg_cdn = 'https://s.w.org/images/core/emoji/17.0.2/svg/';
1111

1212
/**
1313
* Tests that the emoji detection script is hooked onto the front end footer
@@ -192,9 +192,9 @@ public function test_script_tag_printing() {
192192
array( 'baseUrl', 'ext', 'svgUrl', 'svgExt', 'source' ),
193193
array_keys( $settings )
194194
);
195-
$this->assertSame( $this->png_cdn, $settings['baseUrl'] );
195+
$this->assertSame( self::$png_cdn, $settings['baseUrl'] );
196196
$this->assertSame( '.png', $settings['ext'] );
197-
$this->assertSame( $this->svg_cdn, $settings['svgUrl'] );
197+
$this->assertSame( self::$svg_cdn, $settings['svgUrl'] );
198198
$this->assertSame( '.svg', $settings['svgExt'] );
199199
$this->assertIsArray( $settings['source'] );
200200
$this->assertArrayHasKey( 'wpemoji', $settings['source'] );
@@ -216,8 +216,8 @@ public function test_unfiltered_emoji_cdns() {
216216
self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
217217
$output = get_echo( '_print_emoji_detection_script' );
218218

219-
$this->assertStringContainsString( wp_json_encode( $this->png_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
220-
$this->assertStringContainsString( wp_json_encode( $this->svg_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
219+
$this->assertStringContainsString( wp_json_encode( self::$png_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
220+
$this->assertStringContainsString( wp_json_encode( self::$svg_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
221221
}
222222

223223
public function _filtered_emoji_svg_cdn( $cdn = '' ) {
@@ -238,8 +238,8 @@ public function test_filtered_emoji_svn_cdn() {
238238
self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
239239
$output = get_echo( '_print_emoji_detection_script' );
240240

241-
$this->assertStringContainsString( wp_json_encode( $this->png_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
242-
$this->assertStringNotContainsString( wp_json_encode( $this->svg_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
241+
$this->assertStringContainsString( wp_json_encode( self::$png_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
242+
$this->assertStringNotContainsString( wp_json_encode( self::$svg_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
243243
$this->assertStringContainsString( wp_json_encode( $filtered_svn_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
244244

245245
remove_filter( 'emoji_svg_url', array( $this, '_filtered_emoji_svg_cdn' ) );
@@ -264,8 +264,8 @@ public function test_filtered_emoji_png_cdn() {
264264
$output = get_echo( '_print_emoji_detection_script' );
265265

266266
$this->assertStringContainsString( wp_json_encode( $filtered_png_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
267-
$this->assertStringNotContainsString( wp_json_encode( $this->png_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
268-
$this->assertStringContainsString( wp_json_encode( $this->svg_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
267+
$this->assertStringNotContainsString( wp_json_encode( self::$png_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
268+
$this->assertStringContainsString( wp_json_encode( self::$svg_cdn, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $output );
269269

270270
remove_filter( 'emoji_url', array( $this, '_filtered_emoji_png_cdn' ) );
271271
}
@@ -295,7 +295,7 @@ public function test_wp_emoji_list_returns_data() {
295295
$this->assertNotSame( $default, $partials );
296296
}
297297

298-
public function data_wp_encode_emoji() {
298+
public static function data_wp_encode_emoji() {
299299
return array(
300300
array(
301301
// Not emoji.
@@ -335,7 +335,7 @@ public function test_wp_encode_emoji( $emoji, $expected ) {
335335
$this->assertSame( $expected, wp_encode_emoji( $emoji ) );
336336
}
337337

338-
public function data_wp_staticize_emoji() {
338+
public static function data_wp_staticize_emoji() {
339339
$data = array(
340340
array(
341341
// Not emoji.
@@ -345,22 +345,22 @@ public function data_wp_staticize_emoji() {
345345
array(
346346
// Simple emoji.
347347
'🙂',
348-
'<img src="' . $this->png_cdn . '1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
348+
'<img src="' . self::$png_cdn . '1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
349349
),
350350
array(
351351
// Skin tone, gender, ZWJ, emoji selector.
352352
'👮🏼‍♀️',
353-
'<img src="' . $this->png_cdn . '1f46e-1f3fc-200d-2640-fe0f.png" alt="👮🏼‍♀️" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
353+
'<img src="' . self::$png_cdn . '1f46e-1f3fc-200d-2640-fe0f.png" alt="👮🏼‍♀️" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
354354
),
355355
array(
356356
// Unicode 10.
357357
'🧚',
358-
'<img src="' . $this->png_cdn . '1f9da.png" alt="🧚" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
358+
'<img src="' . self::$png_cdn . '1f9da.png" alt="🧚" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
359359
),
360360
array(
361361
// Hairy creature (Unicode 17).
362362
'🫈',
363-
'<img src="' . $this->png_cdn . '1fac8.png" alt="🫈" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
363+
'<img src="' . self::$png_cdn . '1fac8.png" alt="🫈" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
364364
),
365365
);
366366

‎tests/phpunit/tests/formatting/ent2ncr.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function test_converts_named_entities_to_numeric_character_references( $e
1919
* Get test data from files, one test per line.
2020
* Comments start with "###".
2121
*/
22-
public function data_entities() {
22+
public static function data_entities() {
2323
$entities = file( DIR_TESTDATA . '/formatting/entities.txt' );
2424
$data_provided = array();
2525
foreach ( $entities as $line ) {

‎tests/phpunit/tests/formatting/escXml.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function test_esc_xml_basics( $source, $expected ) {
2727
* @type string $expected The expected escaped value of `$source`.
2828
* }
2929
*/
30-
public function data_esc_xml_basics() {
30+
public static function data_esc_xml_basics() {
3131
return array(
3232
// Simple string.
3333
array(
@@ -102,7 +102,7 @@ public function test_ignores_cdata_sections( $source, $expected ) {
102102
* @type string $expected The expected escaped value of `$source`.
103103
* }
104104
*/
105-
public function data_ignores_cdata_sections() {
105+
public static function data_ignores_cdata_sections() {
106106
return array(
107107
// basic CDATA Section containing chars that would otherwise be escaped if not in a CDATA Section
108108
// not to mention the CDATA Section markup itself :-)

‎tests/phpunit/tests/formatting/excerptRemoveFootnotes.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function test_remove_footnotes( $expected, $content ) {
2424
*
2525
* @return array
2626
*/
27-
public function data_remove_footnotes() {
27+
public static function data_remove_footnotes() {
2828
return array(
2929
'no footnote' => array(
3030
'expected' => '<p>This is a paragraph<sup class="fn" id="1"><a href="#1" id="1a">1</a></sup>.</p>',

‎tests/phpunit/tests/formatting/getBloginfo.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function test_get_bloginfo_language( $test_locale, $expected ) {
2222
$locale = $old_locale;
2323
}
2424

25-
public function data_get_bloginfo_language() {
25+
public static function data_get_bloginfo_language() {
2626
return array(
2727
// Locale, language code.
2828
array( 'en_US', 'en-US' ),

0 commit comments

Comments
 (0)