From d1046dc5f320ece8566c08977cbaf0ce574cde66 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 19 Mar 2023 12:03:30 +0000 Subject: [PATCH] Tests: Use the `data_` prefix for various data provider methods. This aims to bring more consistency to the test suite, as the vast majority of data providers already use that prefix. Includes moving some data providers next to the tests they are used in. Follow-up to [55464]. See #57841. git-svn-id: https://develop.svn.wordpress.org/trunk@55562 602fd350-edb4-49c9-b593-d223f7449a82 --- .../phpunit/tests/admin/includesTemplate.php | 4 +- .../tests/admin/wpPrivacyRequestsTable.php | 4 +- tests/phpunit/tests/compat/mbStrlen.php | 8 +- tests/phpunit/tests/compat/mbSubstr.php | 8 +- tests/phpunit/tests/date/dateI18n.php | 4 +- tests/phpunit/tests/date/query.php | 8 +- tests/phpunit/tests/date/wpTimezone.php | 62 ++--- tests/phpunit/tests/db.php | 8 +- tests/phpunit/tests/db/charset.php | 12 +- tests/phpunit/tests/feed/rss2.php | 4 +- .../phpunit/tests/formatting/balanceTags.php | 174 ++++++------- .../tests/formatting/convertSmilies.php | 243 +++++++++--------- tests/phpunit/tests/formatting/date.php | 12 +- tests/phpunit/tests/formatting/ent2ncr.php | 4 +- tests/phpunit/tests/formatting/escXml.php | 8 +- .../phpunit/tests/formatting/getBloginfo.php | 4 +- .../tests/formatting/getUrlInContent.php | 20 +- .../tests/formatting/humanTimeDiff.php | 4 +- .../tests/formatting/linksAddTarget.php | 33 +-- .../tests/formatting/normalizeWhitespace.php | 21 +- tests/phpunit/tests/formatting/redirect.php | 32 +-- .../tests/formatting/sanitizeOrderby.php | 12 +- .../tests/formatting/sanitizeTextField.php | 35 +-- .../formatting/sanitizeTrackbackUrls.php | 4 +- tests/phpunit/tests/formatting/seemsUtf8.php | 12 +- .../tests/formatting/urlencodeDeep.php | 6 +- tests/phpunit/tests/functions.php | 16 +- tests/phpunit/tests/functions/doEnclose.php | 12 +- .../tests/functions/getStatusHeaderDesc.php | 4 +- tests/phpunit/tests/functions/isNewDay.php | 4 +- .../tests/functions/removeQueryArg.php | 4 +- tests/phpunit/tests/functions/sizeFormat.php | 4 +- .../phpunit/tests/functions/wpListFilter.php | 4 +- tests/phpunit/tests/functions/wpListPluck.php | 4 +- tests/phpunit/tests/functions/wpListSort.php | 8 +- tests/phpunit/tests/http/http.php | 20 +- tests/phpunit/tests/image/editor.php | 4 +- tests/phpunit/tests/kses.php | 8 +- .../tests/l10n/loadScriptTextdomain.php | 4 +- tests/phpunit/tests/meta/isProtectedMeta.php | 12 +- tests/phpunit/tests/oembed/filterResult.php | 4 +- tests/phpunit/tests/option/sanitizeOption.php | 33 ++- tests/phpunit/tests/pomo/pluralForms.php | 88 +++---- tests/phpunit/tests/post/nav-menu.php | 30 +-- tests/phpunit/tests/post/query.php | 22 +- tests/phpunit/tests/post/wpUniquePostSlug.php | 4 +- tests/phpunit/tests/rest-api.php | 44 ++-- .../rest-api/rest-attachments-controller.php | 42 +-- .../rest-api/rest-comments-controller.php | 6 +- .../tests/rest-api/rest-post-meta-fields.php | 4 +- .../tests/rest-api/rest-posts-controller.php | 28 +- tests/phpunit/tests/rest-api/rest-request.php | 102 ++++---- tests/phpunit/tests/rest-api/rest-server.php | 12 +- .../rest-api/wpRestTemplatesController.php | 8 +- tests/phpunit/tests/rewrite/rewriteTags.php | 24 +- tests/phpunit/tests/shortcode.php | 26 +- tests/phpunit/tests/sitemaps/functions.php | 8 +- .../phpunit/tests/term/wpGenerateTagCloud.php | 6 +- tests/phpunit/tests/user/capabilities.php | 10 +- tests/phpunit/tests/user/query.php | 4 +- 60 files changed, 680 insertions(+), 679 deletions(-) diff --git a/tests/phpunit/tests/admin/includesTemplate.php b/tests/phpunit/tests/admin/includesTemplate.php index 6b61639c35..ca769eb8b7 100644 --- a/tests/phpunit/tests/admin/includesTemplate.php +++ b/tests/phpunit/tests/admin/includesTemplate.php @@ -222,7 +222,7 @@ class Tests_Admin_IncludesTemplate extends WP_UnitTestCase { * @ticket 44941 * @covers ::settings_errors * @global array $wp_settings_errors - * @dataProvider settings_errors_css_classes_provider + * @dataProvider data_settings_errors_css_classes */ public function test_settings_errors_css_classes( $type, $expected ) { global $wp_settings_errors; @@ -241,7 +241,7 @@ class Tests_Admin_IncludesTemplate extends WP_UnitTestCase { $this->assertStringNotContainsString( 'notice-notice-', $output ); } - public function settings_errors_css_classes_provider() { + public function data_settings_errors_css_classes() { return array( array( 'error', 'notice-error' ), array( 'success', 'notice-success' ), diff --git a/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php b/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php index c26628d0fe..d729a56baf 100644 --- a/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php +++ b/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php @@ -73,7 +73,7 @@ class Tests_Admin_wpPrivacyRequestsTable extends WP_UnitTestCase { * @param string|null $search Search term. * @param string $expected Expected in SQL query. - * @dataProvider data_test_columns_should_be_sortable + * @dataProvider data_columns_should_be_sortable * @covers WP_Privacy_Requests_Table::prepare_items * @ticket 43960 */ @@ -125,7 +125,7 @@ class Tests_Admin_wpPrivacyRequestsTable extends WP_UnitTestCase { * } * } */ - public function data_test_columns_should_be_sortable() { + public function data_columns_should_be_sortable() { return array( // Default order (ID) DESC. array( diff --git a/tests/phpunit/tests/compat/mbStrlen.php b/tests/phpunit/tests/compat/mbStrlen.php index 472d5a3bac..bb77e5f2d3 100644 --- a/tests/phpunit/tests/compat/mbStrlen.php +++ b/tests/phpunit/tests/compat/mbStrlen.php @@ -17,14 +17,14 @@ class Tests_Compat_mbStrlen extends WP_UnitTestCase { } /** - * @dataProvider utf8_string_lengths + * @dataProvider data_utf8_string_lengths */ public function test_mb_strlen( $input_string, $expected_character_length ) { $this->assertSame( $expected_character_length, _mb_strlen( $input_string, 'UTF-8' ) ); } /** - * @dataProvider utf8_string_lengths + * @dataProvider data_utf8_string_lengths */ public function test_mb_strlen_via_regex( $input_string, $expected_character_length ) { _wp_can_use_pcre_u( false ); @@ -33,7 +33,7 @@ class Tests_Compat_mbStrlen extends WP_UnitTestCase { } /** - * @dataProvider utf8_string_lengths + * @dataProvider data_utf8_string_lengths */ public function test_8bit_mb_strlen( $input_string, $expected_character_length, $expected_byte_length ) { $this->assertSame( $expected_byte_length, _mb_strlen( $input_string, '8bit' ) ); @@ -44,7 +44,7 @@ class Tests_Compat_mbStrlen extends WP_UnitTestCase { * * @return array */ - public function utf8_string_lengths() { + public function data_utf8_string_lengths() { return array( array( 'input_string' => 'баба', diff --git a/tests/phpunit/tests/compat/mbSubstr.php b/tests/phpunit/tests/compat/mbSubstr.php index 12325bee73..ddf7e662fb 100644 --- a/tests/phpunit/tests/compat/mbSubstr.php +++ b/tests/phpunit/tests/compat/mbSubstr.php @@ -17,14 +17,14 @@ class Tests_Compat_mbSubstr extends WP_UnitTestCase { } /** - * @dataProvider utf8_substrings + * @dataProvider data_utf8_substrings */ public function test_mb_substr( $input_string, $start, $length, $expected_character_substring ) { $this->assertSame( $expected_character_substring, _mb_substr( $input_string, $start, $length, 'UTF-8' ) ); } /** - * @dataProvider utf8_substrings + * @dataProvider data_utf8_substrings */ public function test_mb_substr_via_regex( $input_string, $start, $length, $expected_character_substring ) { _wp_can_use_pcre_u( false ); @@ -33,7 +33,7 @@ class Tests_Compat_mbSubstr extends WP_UnitTestCase { } /** - * @dataProvider utf8_substrings + * @dataProvider data_utf8_substrings */ public function test_8bit_mb_substr( $input_string, $start, $length, $expected_character_substring, $expected_byte_substring ) { $this->assertSame( $expected_byte_substring, _mb_substr( $input_string, $start, $length, '8bit' ) ); @@ -44,7 +44,7 @@ class Tests_Compat_mbSubstr extends WP_UnitTestCase { * * @return array */ - public function utf8_substrings() { + public function data_utf8_substrings() { return array( array( 'input_string' => 'баба', diff --git a/tests/phpunit/tests/date/dateI18n.php b/tests/phpunit/tests/date/dateI18n.php index dfc98dd369..1fe6f38a95 100644 --- a/tests/phpunit/tests/date/dateI18n.php +++ b/tests/phpunit/tests/date/dateI18n.php @@ -203,7 +203,7 @@ class Tests_Date_DateI18n extends WP_UnitTestCase { /** * @ticket 25768 * - * @dataProvider dst_times + * @dataProvider data_should_handle_dst * * @param string $time Time to test in Y-m-d H:i:s format. * @param string $timezone PHP timezone string to use. @@ -219,7 +219,7 @@ class Tests_Date_DateI18n extends WP_UnitTestCase { $this->assertSame( $datetime->format( $format ), date_i18n( $format, $wp_timestamp ) ); } - public function dst_times() { + public function data_should_handle_dst() { return array( 'Before DST start' => array( '2019-03-31 02:59:00', 'Europe/Helsinki' ), 'After DST start' => array( '2019-03-31 04:01:00', 'Europe/Helsinki' ), diff --git a/tests/phpunit/tests/date/query.php b/tests/phpunit/tests/date/query.php index 32ac0ed018..7fc21f3878 100644 --- a/tests/phpunit/tests/date/query.php +++ b/tests/phpunit/tests/date/query.php @@ -531,7 +531,7 @@ class Tests_Date_Query extends WP_UnitTestCase { /** * @ticket 41782 * - * @dataProvider mysql_datetime_input_provider + * @dataProvider data_build_mysql_datetime * * @param array|string $datetime Array or string date input. * @param string $expected Expected built result. @@ -546,7 +546,7 @@ class Tests_Date_Query extends WP_UnitTestCase { $this->assertEqualsWithDelta( strtotime( $expected ), strtotime( $found ), 10, $message ); } - public function mysql_datetime_input_provider() { + public function data_build_mysql_datetime() { return array( array( '2019-06-04T08:18:24+03:00', '2019-06-04 05:18:24' ), array( '2019-06-04T05:18:24+00:00', '2019-06-04 05:18:24' ), @@ -564,7 +564,7 @@ class Tests_Date_Query extends WP_UnitTestCase { /** * @ticket 41782 * - * @dataProvider mysql_datetime_input_provider_custom_timezone + * @dataProvider data_build_mysql_datetime_with_custom_timezone * * @param array|string $datetime Array or string date input. * @param string $expected Expected built result. @@ -582,7 +582,7 @@ class Tests_Date_Query extends WP_UnitTestCase { } - public function mysql_datetime_input_provider_custom_timezone() { + public function data_build_mysql_datetime_with_custom_timezone() { return array( array( '2019-06-04T08:18:24+03:00', '2019-06-04 08:18:24' ), array( '2019-06-04T05:18:24+00:00', '2019-06-04 08:18:24' ), diff --git a/tests/phpunit/tests/date/wpTimezone.php b/tests/phpunit/tests/date/wpTimezone.php index 3e8b6fef5f..f28ebbf658 100644 --- a/tests/phpunit/tests/date/wpTimezone.php +++ b/tests/phpunit/tests/date/wpTimezone.php @@ -22,7 +22,7 @@ class Tests_Date_wpTimezone extends WP_UnitTestCase { /** * @ticket 24730 * - * @dataProvider timezone_offset_provider + * @dataProvider data_should_convert_gmt_offset * * @param float $gmt_offset Numeric offset from UTC. * @param string $tz_name Expected timezone name. @@ -38,41 +38,12 @@ class Tests_Date_wpTimezone extends WP_UnitTestCase { $this->assertSame( $tz_name, $timezone->getName() ); } - /** - * @ticket 24730 - */ - public function test_should_return_timezone_string() { - update_option( 'timezone_string', 'Europe/Helsinki' ); - - $this->assertSame( 'Europe/Helsinki', wp_timezone_string() ); - - $timezone = wp_timezone(); - - $this->assertSame( 'Europe/Helsinki', $timezone->getName() ); - } - - /** - * Ensures that deprecated timezone strings are handled correctly. - * - * @ticket 56468 - */ - public function test_should_return_deprecated_timezone_string() { - $tz_string = 'America/Buenos_Aires'; // This timezone was deprecated pre-PHP 5.6. - update_option( 'timezone_string', $tz_string ); - - $this->assertSame( $tz_string, wp_timezone_string() ); - - $timezone = wp_timezone(); - - $this->assertSame( $tz_string, $timezone->getName() ); - } - /** * Data provider to test numeric offset conversion. * * @return array */ - public function timezone_offset_provider() { + public function data_should_convert_gmt_offset() { return array( array( -12, '-12:00' ), array( -11.5, '-11:30' ), @@ -134,4 +105,33 @@ class Tests_Date_wpTimezone extends WP_UnitTestCase { array( 14, '+14:00' ), ); } + + /** + * @ticket 24730 + */ + public function test_should_return_timezone_string() { + update_option( 'timezone_string', 'Europe/Helsinki' ); + + $this->assertSame( 'Europe/Helsinki', wp_timezone_string() ); + + $timezone = wp_timezone(); + + $this->assertSame( 'Europe/Helsinki', $timezone->getName() ); + } + + /** + * Ensures that deprecated timezone strings are handled correctly. + * + * @ticket 56468 + */ + public function test_should_return_deprecated_timezone_string() { + $tz_string = 'America/Buenos_Aires'; // This timezone was deprecated pre-PHP 5.6. + update_option( 'timezone_string', $tz_string ); + + $this->assertSame( $tz_string, wp_timezone_string() ); + + $timezone = wp_timezone(); + + $this->assertSame( $tz_string, $timezone->getName() ); + } } diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php index c30baf9394..11e35e4554 100644 --- a/tests/phpunit/tests/db.php +++ b/tests/phpunit/tests/db.php @@ -578,7 +578,7 @@ class Tests_DB extends WP_UnitTestCase { * @param arrray|string|null $last_result The value to assign to `$wpdb->last_result`. * @param int|string $column The column index to retrieve. * - * @dataProvider data_test_get_col + * @dataProvider data_get_col * * @ticket 45299 */ @@ -612,7 +612,7 @@ class Tests_DB extends WP_UnitTestCase { * @type arrray|string|null $last_result The value to assign to `$wpdb->last_result`. * @type int|string $column The column index to retrieve. */ - public function data_test_get_col() { + public function data_get_col() { global $wpdb; return array( @@ -2239,7 +2239,7 @@ class Tests_DB extends WP_UnitTestCase { } /** - * @dataProvider parse_db_host_data_provider + * @dataProvider data_parse_db_host * @ticket 41722 * @ticket 54877 */ @@ -2260,7 +2260,7 @@ class Tests_DB extends WP_UnitTestCase { } } - public function parse_db_host_data_provider() { + public function data_parse_db_host() { return array( array( '', // DB_HOST. diff --git a/tests/phpunit/tests/db/charset.php b/tests/phpunit/tests/db/charset.php index 627526bff2..1a79ab911f 100644 --- a/tests/phpunit/tests/db/charset.php +++ b/tests/phpunit/tests/db/charset.php @@ -773,7 +773,7 @@ class Tests_DB_Charset extends WP_UnitTestCase { /** * @ticket 21212 */ - public function data_test_get_table_charset() { + public function data_get_table_charset() { $table_name = 'test_get_table_charset'; $vars = array(); @@ -788,7 +788,7 @@ class Tests_DB_Charset extends WP_UnitTestCase { } /** - * @dataProvider data_test_get_table_charset + * @dataProvider data_get_table_charset * @ticket 21212 * * @covers wpdb::get_table_charset @@ -814,7 +814,7 @@ class Tests_DB_Charset extends WP_UnitTestCase { /** * @ticket 21212 */ - public function data_test_get_column_charset() { + public function data_get_column_charset() { $table_name = 'test_get_column_charset'; $vars = array(); @@ -829,7 +829,7 @@ class Tests_DB_Charset extends WP_UnitTestCase { } /** - * @dataProvider data_test_get_column_charset + * @dataProvider data_get_column_charset * @ticket 21212 * * @covers wpdb::get_col_charset @@ -856,7 +856,7 @@ class Tests_DB_Charset extends WP_UnitTestCase { } /** - * @dataProvider data_test_get_column_charset + * @dataProvider data_get_column_charset * @ticket 21212 * * @covers wpdb::get_col_charset @@ -883,7 +883,7 @@ class Tests_DB_Charset extends WP_UnitTestCase { } /** - * @dataProvider data_test_get_column_charset + * @dataProvider data_get_column_charset * @ticket 33501 * * @covers wpdb::get_col_charset diff --git a/tests/phpunit/tests/feed/rss2.php b/tests/phpunit/tests/feed/rss2.php index 356b402def..a3f45e0896 100644 --- a/tests/phpunit/tests/feed/rss2.php +++ b/tests/phpunit/tests/feed/rss2.php @@ -487,7 +487,7 @@ class Tests_Feed_RSS2 extends WP_UnitTestCase { * * @ticket 4575 * - * @dataProvider data_test_get_feed_build_date + * @dataProvider data_get_feed_build_date */ public function test_get_feed_build_date( $url, $element ) { $this->go_to( $url ); @@ -501,7 +501,7 @@ class Tests_Feed_RSS2 extends WP_UnitTestCase { } - public function data_test_get_feed_build_date() { + public function data_get_feed_build_date() { return array( array( '/?feed=rss2', 'rss' ), array( '/?feed=commentsrss2', 'rss' ), diff --git a/tests/phpunit/tests/formatting/balanceTags.php b/tests/phpunit/tests/formatting/balanceTags.php index e035275741..2631343ec6 100644 --- a/tests/phpunit/tests/formatting/balanceTags.php +++ b/tests/phpunit/tests/formatting/balanceTags.php @@ -7,46 +7,17 @@ */ class Tests_Formatting_BalanceTags extends WP_UnitTestCase { - public function nestable_tags() { - return array( - array( 'article' ), - array( 'aside' ), - array( 'blockquote' ), - array( 'details' ), - array( 'div' ), - array( 'figure' ), - array( 'object' ), - array( 'q' ), - array( 'section' ), - array( 'span' ), - ); + /** + * @ticket 47014 + * @dataProvider data_supported_traditional_tag_names + */ + public function test_detects_traditional_tag_names( $tag ) { + $normalized = strtolower( $tag ); + + $this->assertSame( "<$normalized>inside", balanceTags( "<$tag>inside", true ) ); } - // This is a complete(?) listing of valid single/self-closing tags. - public function single_tags() { - return array( - array( 'area' ), - array( 'base' ), - array( 'basefont' ), - array( 'br' ), - array( 'col' ), - array( 'command' ), - array( 'embed' ), - array( 'frame' ), - array( 'hr' ), - array( 'img' ), - array( 'input' ), - array( 'isindex' ), - array( 'link' ), - array( 'meta' ), - array( 'param' ), - array( 'source' ), - array( 'track' ), - array( 'wbr' ), - ); - } - - public function supported_traditional_tag_names() { + public function data_supported_traditional_tag_names() { return array( array( 'a' ), array( 'div' ), @@ -58,7 +29,15 @@ class Tests_Formatting_BalanceTags extends WP_UnitTestCase { ); } - public function supported_custom_element_tag_names() { + /** + * @ticket 47014 + * @dataProvider data_supported_custom_element_tag_names + */ + public function test_detects_supported_custom_element_tag_names( $tag ) { + $this->assertSame( "<$tag>inside", balanceTags( "<$tag>inside", true ) ); + } + + public function data_supported_custom_element_tag_names() { return array( array( 'custom-element' ), array( 'my-custom-element' ), @@ -70,19 +49,35 @@ class Tests_Formatting_BalanceTags extends WP_UnitTestCase { ); } - public function invalid_tag_names() { + /** + * @ticket 47014 + * @dataProvider data_invalid_tag_names + */ + public function test_ignores_invalid_tag_names( $input, $output ) { + $this->assertSame( $output, balanceTags( $input, true ) ); + } + + public function data_invalid_tag_names() { return array( array( '<0-day>inside', '<0-day>inside' ), // Can't start with a number - handled by the "<3" fix. array( 'inside', 'inside' ), // Custom elements cannot be uppercase. ); } + /** + * @ticket 47014 + * @dataProvider data_unsupported_valid_tag_names + */ + public function test_ignores_unsupported_custom_tag_names( $tag ) { + $this->assertSame( "<$tag>inside", balanceTags( "<$tag>inside", true ) ); + } + /** * These are valid custom elements but we don't support them yet. * * @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name */ - public function unsupported_valid_tag_names() { + public function data_unsupported_valid_tag_names() { return array( // We don't allow ending in a dash. array( 'inside' ), @@ -137,12 +132,20 @@ class Tests_Formatting_BalanceTags extends WP_UnitTestCase { ); } + /** + * @ticket 47014 + * @dataProvider data_supported_invalid_tag_names + */ + public function test_detects_supported_invalid_tag_names( $tag ) { + $this->assertSame( "<$tag>inside", balanceTags( "<$tag>inside", true ) ); + } + /** * These are invalid custom elements but we support them right now in order to keep the parser simpler. * * @see https://w3c.github.io/webcomponents/spec/custom/#valid-custom-element-name */ - public function supported_invalid_tag_names() { + public function data_supported_invalid_tag_names() { return array( // Reserved names for custom elements. array( 'annotation-xml' ), @@ -156,53 +159,11 @@ class Tests_Formatting_BalanceTags extends WP_UnitTestCase { ); } - /** - * @ticket 47014 - * @dataProvider supported_traditional_tag_names - */ - public function test_detects_traditional_tag_names( $tag ) { - $normalized = strtolower( $tag ); - - $this->assertSame( "<$normalized>inside", balanceTags( "<$tag>inside", true ) ); - } - - /** - * @ticket 47014 - * @dataProvider supported_custom_element_tag_names - */ - public function test_detects_supported_custom_element_tag_names( $tag ) { - $this->assertSame( "<$tag>inside", balanceTags( "<$tag>inside", true ) ); - } - - /** - * @ticket 47014 - * @dataProvider invalid_tag_names - */ - public function test_ignores_invalid_tag_names( $input, $output ) { - $this->assertSame( $output, balanceTags( $input, true ) ); - } - - /** - * @ticket 47014 - * @dataProvider unsupported_valid_tag_names - */ - public function test_ignores_unsupported_custom_tag_names( $tag ) { - $this->assertSame( "<$tag>inside", balanceTags( "<$tag>inside", true ) ); - } - - /** - * @ticket 47014 - * @dataProvider supported_invalid_tag_names - */ - public function test_detects_supported_invalid_tag_names( $tag ) { - $this->assertSame( "<$tag>inside", balanceTags( "<$tag>inside", true ) ); - } - /** * If a recognized valid single tag appears unclosed, it should get self-closed * * @ticket 1597 - * @dataProvider single_tags + * @dataProvider data_single_tags */ public function test_selfcloses_unclosed_known_single_tags( $tag ) { $this->assertSame( "<$tag />", balanceTags( "<$tag>", true ) ); @@ -213,12 +174,36 @@ class Tests_Formatting_BalanceTags extends WP_UnitTestCase { * should get removed and tag should be self-closed. * * @ticket 1597 - * @dataProvider single_tags + * @dataProvider data_single_tags */ public function test_selfcloses_known_single_tags_having_closing_tag( $tag ) { $this->assertSame( "<$tag />", balanceTags( "<$tag>", true ) ); } + // This is a complete(?) listing of valid single/self-closing tags. + public function data_single_tags() { + return array( + array( 'area' ), + array( 'base' ), + array( 'basefont' ), + array( 'br' ), + array( 'col' ), + array( 'command' ), + array( 'embed' ), + array( 'frame' ), + array( 'hr' ), + array( 'img' ), + array( 'input' ), + array( 'isindex' ), + array( 'link' ), + array( 'meta' ), + array( 'param' ), + array( 'source' ), + array( 'track' ), + array( 'wbr' ), + ); + } + /** * @ticket 1597 */ @@ -274,7 +259,7 @@ class Tests_Formatting_BalanceTags extends WP_UnitTestCase { } /** - * @dataProvider nestable_tags + * @dataProvider data_nestable_tags */ public function test_balances_nestable_tags( $tag ) { $inputs = array( @@ -293,6 +278,21 @@ class Tests_Formatting_BalanceTags extends WP_UnitTestCase { } } + public function data_nestable_tags() { + return array( + array( 'article' ), + array( 'aside' ), + array( 'blockquote' ), + array( 'details' ), + array( 'div' ), + array( 'figure' ), + array( 'object' ), + array( 'q' ), + array( 'section' ), + array( 'span' ), + ); + } + public function test_allows_adjacent_nestable_tags() { $inputs = array( '
Example quote
', diff --git a/tests/phpunit/tests/formatting/convertSmilies.php b/tests/phpunit/tests/formatting/convertSmilies.php index 5031b4b51c..509b2383a4 100644 --- a/tests/phpunit/tests/formatting/convertSmilies.php +++ b/tests/phpunit/tests/formatting/convertSmilies.php @@ -8,12 +8,32 @@ */ class Tests_Formatting_ConvertSmilies extends WP_UnitTestCase { + /** + * @dataProvider data_convert_standard_smilies + * + * Basic Validation Test to confirm that smilies are converted to image + * when use_smilies = 1 and not when use_smilies = 0 + */ + public function test_convert_standard_smilies( $in_txt, $converted_txt ) { + // Standard smilies, use_smilies: ON. + update_option( 'use_smilies', 1 ); + + smilies_init(); + + $this->assertSame( $converted_txt, convert_smilies( $in_txt ) ); + + // Standard smilies, use_smilies: OFF. + update_option( 'use_smilies', 0 ); + + $this->assertSame( $in_txt, convert_smilies( $in_txt ) ); + } + /** * Basic Test Content DataProvider * * array ( input_txt, converted_output_txt) */ - public function get_smilies_input_output() { + public function data_convert_standard_smilies() { $includes_path = includes_url( 'images/smilies/' ); return array( @@ -45,51 +65,7 @@ class Tests_Formatting_ConvertSmilies extends WP_UnitTestCase { } /** - * @dataProvider get_smilies_input_output - * - * Basic Validation Test to confirm that smilies are converted to image - * when use_smilies = 1 and not when use_smilies = 0 - */ - public function test_convert_standard_smilies( $in_txt, $converted_txt ) { - // Standard smilies, use_smilies: ON. - update_option( 'use_smilies', 1 ); - - smilies_init(); - - $this->assertSame( $converted_txt, convert_smilies( $in_txt ) ); - - // Standard smilies, use_smilies: OFF. - update_option( 'use_smilies', 0 ); - - $this->assertSame( $in_txt, convert_smilies( $in_txt ) ); - } - - /** - * Custom Smilies Test Content DataProvider - * - * array ( input_txt, converted_output_txt) - */ - public function get_custom_smilies_input_output() { - $includes_path = includes_url( 'images/smilies/' ); - - return array( - array( - 'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. :monkey:', - 'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. :monkey:', - ), - array( - 'Star Wars Jedi Knight :arrow: Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. :nervou:', - 'Star Wars Jedi Knight :arrow: Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. :nervou:', - ), - array( - ':arrow: monkey: Lorem ipsum dolor sit amet enim. Etiam ullam :PP
corper. Suspendisse a pellentesque dui, non felis. :arrow: :arrow', - ':arrow: monkey: Lorem ipsum dolor sit amet enim. Etiam ullam :PP
corper. Suspendisse a pellentesque dui, non felis. :arrow: :arrow', - ), - ); - } - - /** - * @dataProvider get_custom_smilies_input_output + * @dataProvider data_convert_custom_smilies * * Validate Custom Smilies are converted to images when use_smilies = 1 */ @@ -124,17 +100,27 @@ class Tests_Formatting_ConvertSmilies extends WP_UnitTestCase { $wpsmiliestrans = $trans_orig; // Reset original translations array. } - /** - * DataProvider of HTML elements/tags that smilie matches should be ignored in + * Custom Smilies Test Content DataProvider + * + * array ( input_txt, converted_output_txt) */ - public function get_smilies_ignore_tags() { + public function data_convert_custom_smilies() { + $includes_path = includes_url( 'images/smilies/' ); + return array( - array( 'pre' ), - array( 'code' ), - array( 'script' ), - array( 'style' ), - array( 'textarea' ), + array( + 'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. :monkey:', + 'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. :monkey:', + ), + array( + 'Star Wars Jedi Knight :arrow: Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. :nervou:', + 'Star Wars Jedi Knight :arrow: Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. :nervou:', + ), + array( + ':arrow: monkey: Lorem ipsum dolor sit amet enim. Etiam ullam :PP
corper. Suspendisse a pellentesque dui, non felis. :arrow: :arrow', + ':arrow: monkey: Lorem ipsum dolor sit amet enim. Etiam ullam :PP
corper. Suspendisse a pellentesque dui, non felis. :arrow: :arrow', + ), ); } @@ -143,7 +129,7 @@ class Tests_Formatting_ConvertSmilies extends WP_UnitTestCase { * pre, code, script, style * * @ticket 16448 - * @dataProvider get_smilies_ignore_tags + * @dataProvider data_ignore_smilies_in_tags */ public function test_ignore_smilies_in_tags( $element ) { $includes_path = includes_url( 'images/smilies/' ); @@ -161,10 +147,43 @@ class Tests_Formatting_ConvertSmilies extends WP_UnitTestCase { update_option( 'use_smilies', 0 ); } + /** + * DataProvider of HTML elements/tags that smilie matches should be ignored in + */ + public function data_ignore_smilies_in_tags() { + return array( + array( 'pre' ), + array( 'code' ), + array( 'script' ), + array( 'style' ), + array( 'textarea' ), + ); + } + + /** + * Validate Combinations of Smilies separated by single space + * are converted correctly + * + * @ticket 20124 + * @dataProvider data_smilies_combinations + */ + public function test_smilies_combinations( $in_txt, $converted_txt ) { + // Custom smilies, use_smilies: ON. + update_option( 'use_smilies', 1 ); + smilies_init(); + + $this->assertSame( $converted_txt, convert_smilies( $in_txt ) ); + + // Custom smilies, use_smilies: OFF. + update_option( 'use_smilies', 0 ); + + $this->assertSame( $in_txt, convert_smilies( $in_txt ) ); + } + /** * DataProvider of Smilie Combinations */ - public function get_smilies_combinations() { + public function data_smilies_combinations() { $includes_path = includes_url( 'images/smilies/' ); return array( @@ -195,54 +214,12 @@ class Tests_Formatting_ConvertSmilies extends WP_UnitTestCase { ); } - /** - * Validate Combinations of Smilies separated by single space - * are converted correctly - * - * @ticket 20124 - * @dataProvider get_smilies_combinations - */ - public function test_smilies_combinations( $in_txt, $converted_txt ) { - // Custom smilies, use_smilies: ON. - update_option( 'use_smilies', 1 ); - smilies_init(); - - $this->assertSame( $converted_txt, convert_smilies( $in_txt ) ); - - // Custom smilies, use_smilies: OFF. - update_option( 'use_smilies', 0 ); - - $this->assertSame( $in_txt, convert_smilies( $in_txt ) ); - } - - /** - * DataProvider of Single Smilies input and converted output - */ - public function get_single_smilies_input_output() { - $includes_path = includes_url( 'images/smilies/' ); - - return array( - array( - '8-O :-(', - '8-O :-(', - ), - array( - '8O :) additional text here :)', - '8O :) additional text here :)', - ), - array( - ':) :) :) :)', - ':) :) :) :)', - ), - ); - } - /** * Validate Smilies are converted for single smilie in * the $wpsmiliestrans global array * * @ticket 25303 - * @dataProvider get_single_smilies_input_output + * @dataProvider data_single_smilies_in_wpsmiliestrans */ public function test_single_smilies_in_wpsmiliestrans( $in_txt, $converted_txt ) { global $wpsmiliestrans; @@ -272,7 +249,51 @@ class Tests_Formatting_ConvertSmilies extends WP_UnitTestCase { $wpsmiliestrans = $orig_trans; // Reset original translations array. } - public function get_spaces_around_smilies() { + /** + * DataProvider of Single Smilies input and converted output + */ + public function data_single_smilies_in_wpsmiliestrans() { + $includes_path = includes_url( 'images/smilies/' ); + + return array( + array( + '8-O :-(', + '8-O :-(', + ), + array( + '8O :) additional text here :)', + '8O :) additional text here :)', + ), + array( + ':) :) :) :)', + ':) :) :) :)', + ), + ); + } + + /** + * Check that $wp_smiliessearch pattern will match smilies + * between spaces, but never capture those spaces. + * + * Further check that spaces aren't randomly deleted + * or added when replacing the text with an image. + * + * @ticket 22692 + * @dataProvider data_spaces_around_smilies + */ + public function test_spaces_around_smilies( $in_txt, $converted_txt ) { + // Standard smilies, use_smilies: ON. + update_option( 'use_smilies', 1 ); + + smilies_init(); + + $this->assertSame( $converted_txt, convert_smilies( $in_txt ) ); + + // Standard smilies, use_smilies: OFF. + update_option( 'use_smilies', 0 ); + } + + public function data_spaces_around_smilies() { $nbsp = "\xC2\xA0"; return array( @@ -291,28 +312,6 @@ class Tests_Formatting_ConvertSmilies extends WP_UnitTestCase { ); } - /** - * Check that $wp_smiliessearch pattern will match smilies - * between spaces, but never capture those spaces. - * - * Further check that spaces aren't randomly deleted - * or added when replacing the text with an image. - * - * @ticket 22692 - * @dataProvider get_spaces_around_smilies - */ - public function test_spaces_around_smilies( $in_txt, $converted_txt ) { - // Standard smilies, use_smilies: ON. - update_option( 'use_smilies', 1 ); - - smilies_init(); - - $this->assertSame( $converted_txt, convert_smilies( $in_txt ) ); - - // Standard smilies, use_smilies: OFF. - update_option( 'use_smilies', 0 ); - } - /** * Test to ensure smilies can be removed with a filter * diff --git a/tests/phpunit/tests/formatting/date.php b/tests/phpunit/tests/formatting/date.php index 684cf86d97..8e090dd9c1 100644 --- a/tests/phpunit/tests/formatting/date.php +++ b/tests/phpunit/tests/formatting/date.php @@ -130,11 +130,11 @@ class Tests_Formatting_Date extends WP_UnitTestCase { /** * @ticket 31809 * - * @dataProvider timezone_provider + * @dataProvider data_timezone_provider * * @covers ::get_gmt_from_date */ - public function test_gmt_from_date_correct_time( $timezone_string, $gmt_offset ) { + public function test_get_gmt_from_date_correct_time( $timezone_string, $gmt_offset ) { update_option( 'timezone_string', $timezone_string ); update_option( 'gmt_offset', $gmt_offset ); @@ -148,11 +148,11 @@ class Tests_Formatting_Date extends WP_UnitTestCase { /** * @ticket 31809 * - * @dataProvider timezone_provider + * @dataProvider data_timezone_provider * * @covers ::get_date_from_gmt */ - public function test_date_from_gmt_correct_time( $timezone_string, $gmt_offset ) { + public function test_get_date_from_gmt_correct_time( $timezone_string, $gmt_offset ) { update_option( 'timezone_string', $timezone_string ); update_option( 'gmt_offset', $gmt_offset ); @@ -166,7 +166,7 @@ class Tests_Formatting_Date extends WP_UnitTestCase { /** * @ticket 31809 * - * @dataProvider timezone_provider + * @dataProvider data_timezone_provider * * @covers ::iso8601_to_datetime */ @@ -230,7 +230,7 @@ class Tests_Formatting_Date extends WP_UnitTestCase { * * @return array */ - public function timezone_provider() { + public function data_timezone_provider() { return array( array( 'timezone_string' => 'Europe/Helsinki', diff --git a/tests/phpunit/tests/formatting/ent2ncr.php b/tests/phpunit/tests/formatting/ent2ncr.php index daf7f44b4d..ea5e2885bf 100644 --- a/tests/phpunit/tests/formatting/ent2ncr.php +++ b/tests/phpunit/tests/formatting/ent2ncr.php @@ -7,7 +7,7 @@ */ class Tests_Formatting_Ent2ncr extends WP_UnitTestCase { /** - * @dataProvider entities + * @dataProvider data_entities */ public function test_converts_named_entities_to_numeric_character_references( $entity, $ncr ) { $entity = '&' . $entity . ';'; @@ -19,7 +19,7 @@ class Tests_Formatting_Ent2ncr extends WP_UnitTestCase { * Get test data from files, one test per line. * Comments start with "###". */ - public function entities() { + public function data_entities() { $entities = file( DIR_TESTDATA . '/formatting/entities.txt' ); $data_provided = array(); foreach ( $entities as $line ) { diff --git a/tests/phpunit/tests/formatting/escXml.php b/tests/phpunit/tests/formatting/escXml.php index bce29da9df..6fdbd136a7 100644 --- a/tests/phpunit/tests/formatting/escXml.php +++ b/tests/phpunit/tests/formatting/escXml.php @@ -9,7 +9,7 @@ class Tests_Formatting_EscXml extends WP_UnitTestCase { /** * Test basic escaping * - * @dataProvider _test_esc_xml_basics_dataprovider + * @dataProvider data_esc_xml_basics * * @param string $source The source string to be escaped. * @param string $expected The expected escaped value of `$source`. @@ -27,7 +27,7 @@ class Tests_Formatting_EscXml extends WP_UnitTestCase { * @type string $expected The expected escaped value of `$source`. * } */ - public function _test_esc_xml_basics_dataprovider() { + public function data_esc_xml_basics() { return array( // Simple string. array( @@ -84,7 +84,7 @@ class Tests_Formatting_EscXml extends WP_UnitTestCase { /** * Test that CDATA Sections are not escaped. * - * @dataProvider _test_ignores_cdata_sections_dataprovider + * @dataProvider data_ignores_cdata_sections * * @param string $source The source string to be escaped. * @param string $expected The expected escaped value of `$source`. @@ -102,7 +102,7 @@ class Tests_Formatting_EscXml extends WP_UnitTestCase { * @type string $expected The expected escaped value of `$source`. * } */ - public function _test_ignores_cdata_sections_dataprovider() { + public function data_ignores_cdata_sections() { return array( // basic CDATA Section containing chars that would otherwise be escaped if not in a CDATA Section // not to mention the CDATA Section markup itself :-) diff --git a/tests/phpunit/tests/formatting/getBloginfo.php b/tests/phpunit/tests/formatting/getBloginfo.php index 0b6ab77358..37f449bac6 100644 --- a/tests/phpunit/tests/formatting/getBloginfo.php +++ b/tests/phpunit/tests/formatting/getBloginfo.php @@ -8,7 +8,7 @@ class Tests_Formatting_GetBloginfo extends WP_UnitTestCase { /** - * @dataProvider locales + * @dataProvider data_get_bloginfo_language * @ticket 28303 */ public function test_get_bloginfo_language( $test_locale, $expected ) { @@ -22,7 +22,7 @@ class Tests_Formatting_GetBloginfo extends WP_UnitTestCase { $locale = $old_locale; } - public function locales() { + public function data_get_bloginfo_language() { return array( // Locale, language code. array( 'en_US', 'en-US' ), diff --git a/tests/phpunit/tests/formatting/getUrlInContent.php b/tests/phpunit/tests/formatting/getUrlInContent.php index dd79769998..3406a064af 100644 --- a/tests/phpunit/tests/formatting/getUrlInContent.php +++ b/tests/phpunit/tests/formatting/getUrlInContent.php @@ -7,12 +7,21 @@ */ class Tests_Formatting_GetUrlInContent extends WP_UnitTestCase { + /** + * Validate the get_url_in_content function + * + * @dataProvider data_get_url_in_content + */ + public function test_get_url_in_content( $in_str, $exp_str ) { + $this->assertSame( $exp_str, get_url_in_content( $in_str ) ); + } + /** * URL Content Data Provider * * array ( input_txt, converted_output_txt ) */ - public function get_input_output() { + public function data_get_url_in_content() { return array( array( // Empty content. '', @@ -40,13 +49,4 @@ class Tests_Formatting_GetUrlInContent extends WP_UnitTestCase { ), ); } - - /** - * Validate the get_url_in_content function - * - * @dataProvider get_input_output - */ - public function test_get_url_in_content( $in_str, $exp_str ) { - $this->assertSame( $exp_str, get_url_in_content( $in_str ) ); - } } diff --git a/tests/phpunit/tests/formatting/humanTimeDiff.php b/tests/phpunit/tests/formatting/humanTimeDiff.php index 829487c370..0a2bffb367 100644 --- a/tests/phpunit/tests/formatting/humanTimeDiff.php +++ b/tests/phpunit/tests/formatting/humanTimeDiff.php @@ -11,7 +11,7 @@ class Tests_Formatting_HumanTimeDiff extends WP_UnitTestCase { /** * @group formatting * @ticket 38773 - * @dataProvider data_test_human_time_diff + * @dataProvider data_human_time_diff */ public function test_human_time_diff( $expected, $stopdate, $message ) { $startdate = new DateTime( '2016-01-01 12:00:00' ); @@ -19,7 +19,7 @@ class Tests_Formatting_HumanTimeDiff extends WP_UnitTestCase { } // Data for test_human_time_diff. - public function data_test_human_time_diff() { + public function data_human_time_diff() { return array( array( '37 seconds', diff --git a/tests/phpunit/tests/formatting/linksAddTarget.php b/tests/phpunit/tests/formatting/linksAddTarget.php index 2bf582824f..adf7c5a412 100644 --- a/tests/phpunit/tests/formatting/linksAddTarget.php +++ b/tests/phpunit/tests/formatting/linksAddTarget.php @@ -5,12 +5,28 @@ * @covers ::links_add_target */ class Tests_Formatting_LinksAddTarget extends WP_UnitTestCase { + + /** + * Validate the normalize_whitespace function + * + * @dataProvider data_links_add_target + */ + public function test_links_add_target( $content, $target, $tags, $exp_str ) { + if ( true === is_null( $target ) ) { + $this->assertSame( $exp_str, links_add_target( $content ) ); + } elseif ( true === is_null( $tags ) ) { + $this->assertSame( $exp_str, links_add_target( $content, $target ) ); + } else { + $this->assertSame( $exp_str, links_add_target( $content, $target, $tags ) ); + } + } + /** * Test Content DataProvider * * array ( input_txt, converted_output_txt) */ - public function get_input_output() { + public function data_links_add_target() { return array( array( 'MY CONTENT
SOME ADDITIONAL TEXT LINK HERE
END TEXT', @@ -92,19 +108,4 @@ class Tests_Formatting_LinksAddTarget extends WP_UnitTestCase { ), ); } - - /** - * Validate the normalize_whitespace function - * - * @dataProvider get_input_output - */ - public function test_normalize_whitespace( $content, $target, $tags, $exp_str ) { - if ( true === is_null( $target ) ) { - $this->assertSame( $exp_str, links_add_target( $content ) ); - } elseif ( true === is_null( $tags ) ) { - $this->assertSame( $exp_str, links_add_target( $content, $target ) ); - } else { - $this->assertSame( $exp_str, links_add_target( $content, $target, $tags ) ); - } - } } diff --git a/tests/phpunit/tests/formatting/normalizeWhitespace.php b/tests/phpunit/tests/formatting/normalizeWhitespace.php index cdb9a0062d..8f6fdb23d7 100644 --- a/tests/phpunit/tests/formatting/normalizeWhitespace.php +++ b/tests/phpunit/tests/formatting/normalizeWhitespace.php @@ -5,12 +5,22 @@ * @covers ::normalize_whitespace */ class Tests_Formatting_NormalizeWhitespace extends WP_UnitTestCase { + + /** + * Validate the normalize_whitespace function + * + * @dataProvider data_normalize_whitespace + */ + public function test_normalize_whitespace( $in_str, $exp_str ) { + $this->assertSame( $exp_str, normalize_whitespace( $in_str ) ); + } + /** * WhitespaceTest Content DataProvider * * array( input_txt, converted_output_txt) */ - public function get_input_output() { + public function data_normalize_whitespace() { return array( array( ' ', @@ -42,13 +52,4 @@ class Tests_Formatting_NormalizeWhitespace extends WP_UnitTestCase { ), ); } - - /** - * Validate the normalize_whitespace function - * - * @dataProvider get_input_output - */ - public function test_normalize_whitespace( $in_str, $exp_str ) { - $this->assertSame( $exp_str, normalize_whitespace( $in_str ) ); - } } diff --git a/tests/phpunit/tests/formatting/redirect.php b/tests/phpunit/tests/formatting/redirect.php index 213ba36bf5..99e4c8a882 100644 --- a/tests/phpunit/tests/formatting/redirect.php +++ b/tests/phpunit/tests/formatting/redirect.php @@ -18,7 +18,7 @@ class Tests_Formatting_Redirect extends WP_UnitTestCase { /** * @ticket 44317 * - * @dataProvider get_bad_status_codes + * @dataProvider data_wp_redirect_bad_status_code * * @covers ::wp_redirect * @@ -31,7 +31,7 @@ class Tests_Formatting_Redirect extends WP_UnitTestCase { wp_redirect( $location, $status ); } - public function get_bad_status_codes() { + public function data_wp_redirect_bad_status_code() { return array( // Tests for bad arguments. array( '/wp-admin', 404 ), @@ -73,7 +73,7 @@ class Tests_Formatting_Redirect extends WP_UnitTestCase { } /** - * @dataProvider valid_url_provider + * @dataProvider data_wp_validate_redirect_valid_url * * @covers ::wp_validate_redirect */ @@ -81,16 +81,7 @@ class Tests_Formatting_Redirect extends WP_UnitTestCase { $this->assertSame( $expected, wp_validate_redirect( $url ) ); } - /** - * @dataProvider invalid_url_provider - * - * @covers ::wp_validate_redirect - */ - public function test_wp_validate_redirect_invalid_url( $url ) { - $this->assertEquals( false, wp_validate_redirect( $url, false ) ); - } - - public function valid_url_provider() { + public function data_wp_validate_redirect_valid_url() { return array( array( 'http://example.com', 'http://example.com' ), array( 'http://example.com/', 'http://example.com/' ), @@ -106,7 +97,16 @@ class Tests_Formatting_Redirect extends WP_UnitTestCase { ); } - public function invalid_url_provider() { + /** + * @dataProvider data_wp_validate_redirect_invalid_url + * + * @covers ::wp_validate_redirect + */ + public function test_wp_validate_redirect_invalid_url( $url ) { + $this->assertEquals( false, wp_validate_redirect( $url, false ) ); + } + + public function data_wp_validate_redirect_invalid_url() { return array( // parse_url() fails. array( '' ), @@ -176,7 +176,7 @@ class Tests_Formatting_Redirect extends WP_UnitTestCase { /** * @ticket 47980 - * @dataProvider relative_url_provider + * @dataProvider data_wp_validate_redirect_relative_url * * @covers ::wp_validate_redirect */ @@ -211,7 +211,7 @@ class Tests_Formatting_Redirect extends WP_UnitTestCase { * string Expected destination. * } */ - public function relative_url_provider() { + public function data_wp_validate_redirect_relative_url() { return array( array( '/', diff --git a/tests/phpunit/tests/formatting/sanitizeOrderby.php b/tests/phpunit/tests/formatting/sanitizeOrderby.php index 8384f8a4b2..fec1d41713 100644 --- a/tests/phpunit/tests/formatting/sanitizeOrderby.php +++ b/tests/phpunit/tests/formatting/sanitizeOrderby.php @@ -8,12 +8,12 @@ class Tests_Formatting_SanitizeOrderby extends WP_UnitTestCase { /** - * @dataProvider valid_orderbys + * @dataProvider data_sanitize_sql_orderby_valid */ - public function test_valid( $orderby ) { + public function test_sanitize_sql_orderby_valid( $orderby ) { $this->assertSame( $orderby, sanitize_sql_orderby( $orderby ) ); } - public function valid_orderbys() { + public function data_sanitize_sql_orderby_valid() { return array( array( '1' ), array( '1 ASC' ), @@ -34,12 +34,12 @@ class Tests_Formatting_SanitizeOrderby extends WP_UnitTestCase { } /** - * @dataProvider invalid_orderbys + * @dataProvider data_sanitize_sql_orderby_invalid */ - public function test_invalid( $orderby ) { + public function test_sanitize_sql_orderby_invalid( $orderby ) { $this->assertFalse( sanitize_sql_orderby( $orderby ) ); } - public function invalid_orderbys() { + public function data_sanitize_sql_orderby_invalid() { return array( array( '' ), array( '1 2' ), diff --git a/tests/phpunit/tests/formatting/sanitizeTextField.php b/tests/phpunit/tests/formatting/sanitizeTextField.php index ffee225354..2d184ebb13 100644 --- a/tests/phpunit/tests/formatting/sanitizeTextField.php +++ b/tests/phpunit/tests/formatting/sanitizeTextField.php @@ -7,6 +7,24 @@ * @covers ::sanitize_textarea_field */ class Tests_Formatting_SanitizeTextField extends WP_UnitTestCase { + + /** + * @ticket 32257 + * @dataProvider data_sanitize_text_field + */ + public function test_sanitize_text_field( $str, $expected ) { + if ( is_array( $expected ) ) { + $expected_oneline = $expected['oneline']; + $expected_multiline = $expected['multiline']; + } else { + $expected_oneline = $expected; + $expected_multiline = $expected; + } + $this->assertSame( $expected_oneline, sanitize_text_field( $str ) ); + $this->assertSameIgnoreEOL( $expected_multiline, sanitize_textarea_field( $str ) ); + + } + public function data_sanitize_text_field() { return array( array( @@ -126,21 +144,4 @@ class Tests_Formatting_SanitizeTextField extends WP_UnitTestCase { ), ); } - - /** - * @ticket 32257 - * @dataProvider data_sanitize_text_field - */ - public function test_sanitize_text_field( $str, $expected ) { - if ( is_array( $expected ) ) { - $expected_oneline = $expected['oneline']; - $expected_multiline = $expected['multiline']; - } else { - $expected_oneline = $expected; - $expected_multiline = $expected; - } - $this->assertSame( $expected_oneline, sanitize_text_field( $str ) ); - $this->assertSameIgnoreEOL( $expected_multiline, sanitize_textarea_field( $str ) ); - - } } diff --git a/tests/phpunit/tests/formatting/sanitizeTrackbackUrls.php b/tests/phpunit/tests/formatting/sanitizeTrackbackUrls.php index f5a5404e93..b560ad5c75 100644 --- a/tests/phpunit/tests/formatting/sanitizeTrackbackUrls.php +++ b/tests/phpunit/tests/formatting/sanitizeTrackbackUrls.php @@ -8,7 +8,7 @@ class Tests_Formatting_SanitizeTrackbackUrls extends WP_UnitTestCase { /** * @ticket 21624 - * @dataProvider separators + * @dataProvider data_sanitize_trackback_urls_with_multiple_urls */ public function test_sanitize_trackback_urls_with_multiple_urls( $separator ) { $this->assertSame( @@ -17,7 +17,7 @@ class Tests_Formatting_SanitizeTrackbackUrls extends WP_UnitTestCase { ); } - public function separators() { + public function data_sanitize_trackback_urls_with_multiple_urls() { return array( array( "\r\n\t " ), array( "\r" ), diff --git a/tests/phpunit/tests/formatting/seemsUtf8.php b/tests/phpunit/tests/formatting/seemsUtf8.php index 5e9bb8e8a1..b6a67950e9 100644 --- a/tests/phpunit/tests/formatting/seemsUtf8.php +++ b/tests/phpunit/tests/formatting/seemsUtf8.php @@ -10,14 +10,14 @@ class Tests_Formatting_SeemsUtf8 extends WP_UnitTestCase { /** * `seems_utf8` returns true for utf-8 strings, false otherwise. * - * @dataProvider utf8_strings + * @dataProvider data_seems_utf8_returns_true_for_utf8_strings */ - public function test_returns_true_for_utf8_strings( $utf8_string ) { + public function test_seems_utf8_returns_true_for_utf8_strings( $utf8_string ) { // From http://www.i18nguy.com/unicode-example.html $this->assertTrue( seems_utf8( $utf8_string ) ); } - public function utf8_strings() { + public function data_seems_utf8_returns_true_for_utf8_strings() { $utf8_strings = file( DIR_TESTDATA . '/formatting/utf-8/utf-8.txt' ); foreach ( $utf8_strings as &$string ) { $string = (array) trim( $string ); @@ -27,13 +27,13 @@ class Tests_Formatting_SeemsUtf8 extends WP_UnitTestCase { } /** - * @dataProvider big5_strings + * @dataProvider data_seems_utf8_returns_false_for_non_utf8_strings */ - public function test_returns_false_for_non_utf8_strings( $big5_string ) { + public function test_seems_utf8_returns_false_for_non_utf8_strings( $big5_string ) { $this->assertFalse( seems_utf8( $big5_string ) ); } - public function big5_strings() { + public function data_seems_utf8_returns_false_for_non_utf8_strings() { // Get data from formatting/big5.txt. $big5_strings = file( DIR_TESTDATA . '/formatting/big5.txt' ); foreach ( $big5_strings as &$string ) { diff --git a/tests/phpunit/tests/formatting/urlencodeDeep.php b/tests/phpunit/tests/formatting/urlencodeDeep.php index a3b461a6ae..55b2a4b76d 100644 --- a/tests/phpunit/tests/formatting/urlencodeDeep.php +++ b/tests/phpunit/tests/formatting/urlencodeDeep.php @@ -11,7 +11,7 @@ class Tests_Formatting_UrlencodeDeep extends WP_UnitTestCase { /** * Data Provider */ - public function data_test_values() { + public function data_urlencode_deep() { return array( array( 'qwerty123456', 'qwerty123456' ), array( '|!"£$%&/()=?', '%7C%21%22%C2%A3%24%25%26%2F%28%29%3D%3F' ), @@ -24,7 +24,7 @@ class Tests_Formatting_UrlencodeDeep extends WP_UnitTestCase { /** * Validate the urlencode_deep function pair by pair * - * @dataProvider data_test_values + * @dataProvider data_urlencode_deep * * @param string $actual * @param string $expected @@ -37,7 +37,7 @@ class Tests_Formatting_UrlencodeDeep extends WP_UnitTestCase { * Test the whole array as input */ public function test_urlencode_deep_should_encode_all_values_in_array() { - $data = $this->data_test_values(); + $data = $this->data_urlencode_deep(); $actual = wp_list_pluck( $data, 0 ); $expected = wp_list_pluck( $data, 1 ); diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 152c42b69b..aa12b106e1 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -1767,7 +1767,7 @@ class Tests_Functions extends WP_UnitTestCase { * Test file path validation * * @ticket 42016 - * @dataProvider data_test_validate_file + * @dataProvider data_validate_file * * @param string $file File path. * @param array $allowed_files List of allowed files. @@ -1788,7 +1788,7 @@ class Tests_Functions extends WP_UnitTestCase { * } * } */ - public function data_test_validate_file() { + public function data_validate_file() { return array( // Allowed files: @@ -1910,7 +1910,7 @@ class Tests_Functions extends WP_UnitTestCase { /** * Test stream URL validation. * - * @dataProvider data_test_wp_is_stream + * @dataProvider data_wp_is_stream * * @param string $path The resource path or URL. * @param bool $expected Expected result. @@ -1933,7 +1933,7 @@ class Tests_Functions extends WP_UnitTestCase { * } * } */ - public function data_test_wp_is_stream() { + public function data_wp_is_stream() { return array( // Legitimate stream examples. array( 'http://example.com', true ), @@ -1954,7 +1954,7 @@ class Tests_Functions extends WP_UnitTestCase { * Test human_readable_duration(). * * @ticket 39667 - * @dataProvider data_test_human_readable_duration + * @dataProvider data_human_readable_duration * * @param string $input Duration. * @param string $expected Expected human readable duration. @@ -1973,7 +1973,7 @@ class Tests_Functions extends WP_UnitTestCase { * } * } */ - public function data_test_human_readable_duration() { + public function data_human_readable_duration() { return array( // Valid ii:ss cases. array( '0:0', '0 minutes, 0 seconds' ), @@ -2030,14 +2030,14 @@ class Tests_Functions extends WP_UnitTestCase { /** * @ticket 49404 - * @dataProvider data_test_wp_is_json_media_type + * @dataProvider data_wp_is_json_media_type */ public function test_wp_is_json_media_type( $input, $expected ) { $this->assertSame( $expected, wp_is_json_media_type( $input ) ); } - public function data_test_wp_is_json_media_type() { + public function data_wp_is_json_media_type() { return array( array( 'application/ld+json', true ), array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', true ), diff --git a/tests/phpunit/tests/functions/doEnclose.php b/tests/phpunit/tests/functions/doEnclose.php index 41ad26a338..5611878bd2 100644 --- a/tests/phpunit/tests/functions/doEnclose.php +++ b/tests/phpunit/tests/functions/doEnclose.php @@ -28,7 +28,7 @@ class Tests_Functions_DoEnclose extends WP_UnitTestCase { * * @since 5.3.0 * - * @dataProvider data_test_do_enclose + * @dataProvider data_do_enclose */ public function test_function_with_explicit_content_input( $content, $expected ) { $post_id = self::factory()->post->create(); @@ -44,7 +44,7 @@ class Tests_Functions_DoEnclose extends WP_UnitTestCase { * * @since 5.3.0 * - * @dataProvider data_test_do_enclose + * @dataProvider data_do_enclose */ public function test_function_with_implicit_content_input( $content, $expected ) { $post_id = self::factory()->post->create( @@ -72,7 +72,7 @@ class Tests_Functions_DoEnclose extends WP_UnitTestCase { * } * } */ - public function data_test_do_enclose() { + public function data_do_enclose() { return array( 'null' => array( 'content' => null, @@ -144,7 +144,7 @@ class Tests_Functions_DoEnclose extends WP_UnitTestCase { * @since 5.3.0 */ public function test_function_should_delete_enclosed_link_when_no_longer_in_post_content() { - $data = $this->data_test_do_enclose(); + $data = $this->data_do_enclose(); // Create a post with a single movie link. $post_id = self::factory()->post->create( @@ -178,7 +178,7 @@ class Tests_Functions_DoEnclose extends WP_UnitTestCase { * @since 5.3.0 */ public function test_function_should_support_post_object_input() { - $data = $this->data_test_do_enclose(); + $data = $this->data_do_enclose(); $post_object = self::factory()->post->create_and_get( array( @@ -198,7 +198,7 @@ class Tests_Functions_DoEnclose extends WP_UnitTestCase { * @since 5.3.0 */ public function test_function_enclosure_links_should_be_filterable() { - $data = $this->data_test_do_enclose(); + $data = $this->data_do_enclose(); $post_id = self::factory()->post->create( array( diff --git a/tests/phpunit/tests/functions/getStatusHeaderDesc.php b/tests/phpunit/tests/functions/getStatusHeaderDesc.php index a7b253fcdd..c3826c5dc8 100644 --- a/tests/phpunit/tests/functions/getStatusHeaderDesc.php +++ b/tests/phpunit/tests/functions/getStatusHeaderDesc.php @@ -11,7 +11,7 @@ class Tests_Functions_GetStatusHeaderDesc extends WP_UnitTestCase { /** - * @dataProvider _status_strings + * @dataProvider data_get_status_header_desc * * @param int $code HTTP status code. * @param string $expected Status description. @@ -25,7 +25,7 @@ class Tests_Functions_GetStatusHeaderDesc extends WP_UnitTestCase { * * @return array */ - public function _status_strings() { + public function data_get_status_header_desc() { return array( array( 200, 'OK' ), array( 301, 'Moved Permanently' ), diff --git a/tests/phpunit/tests/functions/isNewDay.php b/tests/phpunit/tests/functions/isNewDay.php index 3201717fe0..f852c8908f 100644 --- a/tests/phpunit/tests/functions/isNewDay.php +++ b/tests/phpunit/tests/functions/isNewDay.php @@ -11,7 +11,7 @@ class Tests_Functions_IsNewDate extends WP_UnitTestCase { /** * @ticket 46627 - * @dataProvider _data_is_new_date + * @dataProvider data_is_new_date * * @param string $currentday_string The day of the current post in the loop. * @param string $previousday_string The day of the previous post in the loop. @@ -26,7 +26,7 @@ class Tests_Functions_IsNewDate extends WP_UnitTestCase { $this->assertSame( $expected, is_new_day() ); } - public function _data_is_new_date() { + public function data_is_new_date() { return array( array( '21.05.19', '21.05.19', 0 ), array( '21.05.19', '20.05.19', 1 ), diff --git a/tests/phpunit/tests/functions/removeQueryArg.php b/tests/phpunit/tests/functions/removeQueryArg.php index b8130abe8d..8d05a6c230 100644 --- a/tests/phpunit/tests/functions/removeQueryArg.php +++ b/tests/phpunit/tests/functions/removeQueryArg.php @@ -7,7 +7,7 @@ class Tests_Functions_RemoveQueryArg extends WP_UnitTestCase { /** - * @dataProvider remove_query_arg_provider + * @dataProvider data_remove_query_arg */ public function test_remove_query_arg( $keys_to_remove, $url, $expected ) { $actual = remove_query_arg( $keys_to_remove, $url ); @@ -16,7 +16,7 @@ class Tests_Functions_RemoveQueryArg extends WP_UnitTestCase { $this->assertSame( $expected, $actual ); } - public function remove_query_arg_provider() { + public function data_remove_query_arg() { return array( array( 'foo', 'edit.php?foo=test1&baz=test1', 'edit.php?baz=test1' ), array( array( 'foo' ), 'edit.php?foo=test2&baz=test2', 'edit.php?baz=test2' ), diff --git a/tests/phpunit/tests/functions/sizeFormat.php b/tests/phpunit/tests/functions/sizeFormat.php index 72c383ff95..bed09d15aa 100644 --- a/tests/phpunit/tests/functions/sizeFormat.php +++ b/tests/phpunit/tests/functions/sizeFormat.php @@ -12,7 +12,7 @@ */ class Tests_Functions_SizeFormat extends WP_UnitTestCase { - public function _data_size_format() { + public function data_size_format() { return array( // Invalid values. array( array(), 0, false ), @@ -72,7 +72,7 @@ class Tests_Functions_SizeFormat extends WP_UnitTestCase { } /** - * @dataProvider _data_size_format + * @dataProvider data_size_format * * @param $bytes * @param $decimals diff --git a/tests/phpunit/tests/functions/wpListFilter.php b/tests/phpunit/tests/functions/wpListFilter.php index 7b7f54d2d9..bc8acdc63a 100644 --- a/tests/phpunit/tests/functions/wpListFilter.php +++ b/tests/phpunit/tests/functions/wpListFilter.php @@ -9,7 +9,7 @@ class Tests_Functions_wpListFilter extends WP_UnitTestCase { /** - * @dataProvider data_test_wp_list_filter + * @dataProvider data_wp_list_filter * * @param array $input_list An array of objects to filter. * @param array $args An array of key => value arguments to match @@ -21,7 +21,7 @@ class Tests_Functions_wpListFilter extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, wp_list_filter( $input_list, $args, $operator ) ); } - public function data_test_wp_list_filter() { + public function data_wp_list_filter() { return array( 'string instead of array' => array( 'foo', diff --git a/tests/phpunit/tests/functions/wpListPluck.php b/tests/phpunit/tests/functions/wpListPluck.php index fa10b01595..cb3c4bfe27 100644 --- a/tests/phpunit/tests/functions/wpListPluck.php +++ b/tests/phpunit/tests/functions/wpListPluck.php @@ -204,7 +204,7 @@ class Tests_Functions_wpListPluck extends WP_UnitTestCase { } /** - * @dataProvider data_test_wp_list_pluck + * @dataProvider data_wp_list_pluck * * @param array $input_list List of objects or arrays. * @param int|string $field Field from the object to place instead of the entire object @@ -215,7 +215,7 @@ class Tests_Functions_wpListPluck extends WP_UnitTestCase { $this->assertSameSetsWithIndex( $expected, wp_list_pluck( $input_list, $field, $index_key ) ); } - public function data_test_wp_list_pluck() { + public function data_wp_list_pluck() { return array( 'arrays' => array( array( diff --git a/tests/phpunit/tests/functions/wpListSort.php b/tests/phpunit/tests/functions/wpListSort.php index a77354d70e..63c495dd84 100644 --- a/tests/phpunit/tests/functions/wpListSort.php +++ b/tests/phpunit/tests/functions/wpListSort.php @@ -9,7 +9,7 @@ class Tests_Functions_wpListSort extends WP_UnitTestCase { /** - * @dataProvider data_test_wp_list_sort + * @dataProvider data_wp_list_sort * * @param string|array $orderby Either the field name to order by or an array * of multiple orderby fields as `$orderby => $order`. @@ -19,7 +19,7 @@ class Tests_Functions_wpListSort extends WP_UnitTestCase { $this->assertSame( $expected, wp_list_sort( $input_list, $orderby, $order ) ); } - public function data_test_wp_list_sort() { + public function data_wp_list_sort() { return array( 'single orderby ascending' => array( array( @@ -334,7 +334,7 @@ class Tests_Functions_wpListSort extends WP_UnitTestCase { } /** - * @dataProvider data_test_wp_list_sort_preserve_keys + * @dataProvider data_wp_list_sort_preserve_keys * * @param string|array $orderby Either the field name to order by or an array * of multiple orderby fields as `$orderby => $order`. @@ -344,7 +344,7 @@ class Tests_Functions_wpListSort extends WP_UnitTestCase { $this->assertSame( $expected, wp_list_sort( $input_list, $orderby, $order, true ) ); } - public function data_test_wp_list_sort_preserve_keys() { + public function data_wp_list_sort_preserve_keys() { return array( 'single orderby ascending' => array( array( diff --git a/tests/phpunit/tests/http/http.php b/tests/phpunit/tests/http/http.php index dfc9fd6518..de9dd73320 100644 --- a/tests/phpunit/tests/http/http.php +++ b/tests/phpunit/tests/http/http.php @@ -12,7 +12,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { * @ticket 20434 * @ticket 56231 * - * @dataProvider make_absolute_url_testcases + * @dataProvider data_make_absolute_url * * @covers WP_Http::make_absolute_url */ @@ -21,7 +21,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { $this->assertSame( $expected, $actual ); } - public function make_absolute_url_testcases() { + public function data_make_absolute_url() { // 0: The Location header, 1: The current URL, 3: The expected URL. return array( // Absolute URL provided. @@ -80,7 +80,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { } /** - * @dataProvider parse_url_testcases + * @dataProvider data_wp_parse_url * * @covers ::wp_parse_url */ @@ -89,7 +89,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { $this->assertSame( $expected, $actual ); } - public function parse_url_testcases() { + public function data_wp_parse_url() { // 0: The URL, 1: The expected resulting structure. return array( array( @@ -217,7 +217,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { /** * @ticket 36356 * - * @dataProvider parse_url_component_testcases + * @dataProvider data_wp_parse_url_with_component * * @covers ::wp_parse_url */ @@ -226,7 +226,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { $this->assertSame( $expected, $actual ); } - public function parse_url_component_testcases() { + public function data_wp_parse_url_with_component() { // 0: The URL, 1: The requested component, 2: The expected resulting structure. return array( array( self::FULL_TEST_URL, PHP_URL_SCHEME, 'http' ), @@ -333,7 +333,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { /** * @ticket 36356 * - * @dataProvider get_component_from_parsed_url_array_testcases + * @dataProvider data_get_component_from_parsed_url_array * * @covers ::wp_parse_url * @covers ::_get_component_from_parsed_url_array @@ -344,7 +344,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { $this->assertSame( $expected, $actual ); } - public function get_component_from_parsed_url_array_testcases() { + public function data_get_component_from_parsed_url_array() { // 0: A URL, 1: PHP URL constant, 2: The expected result. return array( array( @@ -375,7 +375,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { /** * @ticket 36356 * - * @dataProvider wp_translate_php_url_constant_to_key_testcases + * @dataProvider data_wp_translate_php_url_constant_to_key * * @covers ::_wp_translate_php_url_constant_to_key */ @@ -384,7 +384,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { $this->assertSame( $expected, $actual ); } - public function wp_translate_php_url_constant_to_key_testcases() { + public function data_wp_translate_php_url_constant_to_key() { // 0: PHP URL constant, 1: The expected result. return array( array( PHP_URL_SCHEME, 'scheme' ), diff --git a/tests/phpunit/tests/image/editor.php b/tests/phpunit/tests/image/editor.php index be4591451d..6e800deb7a 100644 --- a/tests/phpunit/tests/image/editor.php +++ b/tests/phpunit/tests/image/editor.php @@ -288,7 +288,7 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { * Test wp_get_webp_info. * * @ticket 35725 - * @dataProvider _test_wp_get_webp_info + * @dataProvider data_wp_get_webp_info * */ public function test_wp_get_webp_info( $file, $expected ) { @@ -305,7 +305,7 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { /** * Data provider for test_wp_get_webp_info(). */ - public function _test_wp_get_webp_info() { + public function data_wp_get_webp_info() { return array( // Standard JPEG. array( diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index 27424276a3..3c7cb86827 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -937,7 +937,7 @@ EOF; * @ticket 48376 * @ticket 55966 * @ticket 56122 - * @dataProvider data_test_safecss_filter_attr + * @dataProvider data_safecss_filter_attr * * @param string $css A string of CSS rules. * @param string $expected Expected string of CSS rules. @@ -956,7 +956,7 @@ EOF; * } * } */ - public function data_test_safecss_filter_attr() { + public function data_safecss_filter_attr() { return array( // Empty input, empty output. array( @@ -1568,7 +1568,7 @@ EOF; * * @ticket 37134 * - * @dataProvider data_test_safecss_filter_attr_filtered + * @dataProvider data_safecss_filter_attr_filtered * * @param string $css A string of CSS rules. * @param string $expected Expected string of CSS rules. @@ -1589,7 +1589,7 @@ EOF; * } * } */ - public function data_test_safecss_filter_attr_filtered() { + public function data_safecss_filter_attr_filtered() { return array( // A single attribute name, with a single value. diff --git a/tests/phpunit/tests/l10n/loadScriptTextdomain.php b/tests/phpunit/tests/l10n/loadScriptTextdomain.php index fab8aa8b5a..80313f5f37 100644 --- a/tests/phpunit/tests/l10n/loadScriptTextdomain.php +++ b/tests/phpunit/tests/l10n/loadScriptTextdomain.php @@ -14,7 +14,7 @@ class Tests_L10n_LoadScriptTextdomain extends WP_UnitTestCase { * @ticket 46387 * @ticket 49145 * - * @dataProvider data_test_resolve_relative_path + * @dataProvider data_resolve_relative_path */ public function test_resolve_relative_path( $translation_path, $handle, $src, $textdomain, $filter = array() ) { if ( ! empty( $filter ) ) { @@ -26,7 +26,7 @@ class Tests_L10n_LoadScriptTextdomain extends WP_UnitTestCase { $this->assertSame( $expected, load_script_textdomain( $handle, $textdomain, DIR_TESTDATA . '/languages' ) ); } - public function data_test_resolve_relative_path() { + public function data_resolve_relative_path() { return array( // @ticket 45528 array( diff --git a/tests/phpunit/tests/meta/isProtectedMeta.php b/tests/phpunit/tests/meta/isProtectedMeta.php index 46f20e72fa..ba3eeed9a2 100644 --- a/tests/phpunit/tests/meta/isProtectedMeta.php +++ b/tests/phpunit/tests/meta/isProtectedMeta.php @@ -7,13 +7,13 @@ class Tests_Meta_isProtectedMeta extends WP_UnitTestCase { /** - * @dataProvider protected_data + * @dataProvider data_is_protected_meta_true */ - public function test_protected( $key ) { + public function test_is_protected_meta_true( $key ) { $this->assertTrue( is_protected_meta( $key ) ); } - public function protected_data() { + public function data_is_protected_meta_true() { $protected_keys = array( array( '_wp_attachment' ), ); @@ -29,13 +29,13 @@ class Tests_Meta_isProtectedMeta extends WP_UnitTestCase { } /** - * @dataProvider unprotected_data + * @dataProvider data_is_protected_meta_false */ - public function test_unprotected( $key ) { + public function test_is_protected_meta_false( $key ) { $this->assertFalse( is_protected_meta( $key ) ); } - public function unprotected_data() { + public function data_is_protected_meta_false() { $unprotected_keys = array( array( 'singleword' ), array( 'two_words' ), diff --git a/tests/phpunit/tests/oembed/filterResult.php b/tests/phpunit/tests/oembed/filterResult.php index 0267bded34..543d336cb9 100644 --- a/tests/phpunit/tests/oembed/filterResult.php +++ b/tests/phpunit/tests/oembed/filterResult.php @@ -93,7 +93,7 @@ EOD; $this->assertSame( '
', $actual ); } - public function _data_oembed_test_strings() { + public function data_wp_filter_pre_oembed_custom_result() { return array( array( '
', @@ -115,7 +115,7 @@ EOD; } /** - * @dataProvider _data_oembed_test_strings + * @dataProvider data_wp_filter_pre_oembed_custom_result */ public function test_wp_filter_pre_oembed_custom_result( $html, $expected ) { $data = (object) array( diff --git a/tests/phpunit/tests/option/sanitizeOption.php b/tests/phpunit/tests/option/sanitizeOption.php index dec3cf7ced..e50cec0c62 100644 --- a/tests/phpunit/tests/option/sanitizeOption.php +++ b/tests/phpunit/tests/option/sanitizeOption.php @@ -5,6 +5,14 @@ */ class Tests_Option_SanitizeOption extends WP_UnitTestCase { + /** + * @dataProvider data_sanitize_option + * + * @covers ::sanitize_option + */ + public function test_sanitize_option( $option_name, $sanitized, $original ) { + $this->assertSame( $sanitized, sanitize_option( $option_name, $original ) ); + } /** * Data provider to test all of the sanitize_option() case * @@ -12,7 +20,7 @@ class Tests_Option_SanitizeOption extends WP_UnitTestCase { * * @return array */ - public function sanitize_option_provider() { + public function data_sanitize_option() { return array( array( 'admin_email', 'mail@example.com', 'mail@example.com' ), array( 'admin_email', get_option( 'admin_email' ), 'invalid' ), @@ -86,15 +94,15 @@ class Tests_Option_SanitizeOption extends WP_UnitTestCase { } /** - * @dataProvider sanitize_option_provider + * @dataProvider data_sanitize_option_upload_path * * @covers ::sanitize_option */ - public function test_sanitize_option( $option_name, $sanitized, $original ) { - $this->assertSame( $sanitized, sanitize_option( $option_name, $original ) ); + public function test_sanitize_option_upload_path( $provided, $expected ) { + $this->assertSame( $expected, sanitize_option( 'upload_path', $provided ) ); } - public function upload_path_provider() { + public function data_sanitize_option_upload_path() { return array( array( 'Link', 'Link' ), array( 'url', 'url' ), @@ -103,15 +111,6 @@ class Tests_Option_SanitizeOption extends WP_UnitTestCase { ); } - /** - * @dataProvider upload_path_provider - * - * @covers ::sanitize_option - */ - public function test_sanitize_option_upload_path( $provided, $expected ) { - $this->assertSame( $expected, sanitize_option( 'upload_path', $provided ) ); - } - /** * @ticket 36122 * @@ -133,12 +132,12 @@ class Tests_Option_SanitizeOption extends WP_UnitTestCase { } /** - * @dataProvider permalink_structure_provider + * @dataProvider data_sanitize_option_permalink_structure * * @covers ::sanitize_option * @covers ::get_settings_errors */ - public function test_sanitize_permalink_structure( $provided, $expected, $valid ) { + public function test_sanitize_option_permalink_structure( $provided, $expected, $valid ) { global $wp_settings_errors; $old_wp_settings_errors = (array) $wp_settings_errors; @@ -159,7 +158,7 @@ class Tests_Option_SanitizeOption extends WP_UnitTestCase { $this->assertEquals( $expected, $actual ); } - public function permalink_structure_provider() { + public function data_sanitize_option_permalink_structure() { return array( array( '', '', true ), array( '%postname', false, false ), diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 0d5cc192a5..0343302c68 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -39,15 +39,38 @@ class PluralFormsTest extends WP_UnitTestCase { /** * @ticket 41562 + * @dataProvider data_locales * @group external-http */ - public function test_locales_provider() { - $locales = self::locales_provider(); + public function test_regression( $lang, $nplurals, $expression ) { + require_once dirname( dirname( __DIR__ ) ) . '/includes/plural-form-function.php'; + + $parenthesized = self::parenthesize_plural_expression( $expression ); + $old_style = tests_make_plural_form_function( $nplurals, $parenthesized ); + $plural_forms = new Plural_Forms( $expression ); + + $generated_old = array(); + $generated_new = array(); + + foreach ( range( 0, 200 ) as $i ) { + $generated_old[] = $old_style( $i ); + $generated_new[] = $plural_forms->get( $i ); + } + + $this->assertSame( $generated_old, $generated_new ); + } + + /** + * @ticket 41562 + * @group external-http + */ + public function test_locales_file_not_empty() { + $locales = self::data_locales(); $this->assertNotEmpty( $locales, 'Unable to retrieve GP_Locales file' ); } - public static function locales_provider() { + public static function data_locales() { if ( ! class_exists( 'GP_Locales' ) ) { $filename = download_url( 'https://raw.githubusercontent.com/GlotPress/GlotPress-WP/develop/locales/locales.php' ); if ( is_wp_error( $filename ) ) { @@ -70,28 +93,19 @@ class PluralFormsTest extends WP_UnitTestCase { /** * @ticket 41562 - * @dataProvider locales_provider - * @group external-http + * @dataProvider data_simple */ - public function test_regression( $lang, $nplurals, $expression ) { - require_once dirname( dirname( __DIR__ ) ) . '/includes/plural-form-function.php'; - - $parenthesized = self::parenthesize_plural_expression( $expression ); - $old_style = tests_make_plural_form_function( $nplurals, $parenthesized ); - $plural_forms = new Plural_Forms( $expression ); - - $generated_old = array(); - $generated_new = array(); - - foreach ( range( 0, 200 ) as $i ) { - $generated_old[] = $old_style( $i ); - $generated_new[] = $plural_forms->get( $i ); + public function test_simple( $expression, $expected ) { + $plural_forms = new Plural_Forms( $expression ); + $actual = array(); + foreach ( array_keys( $expected ) as $num ) { + $actual[ $num ] = $plural_forms->get( $num ); } - $this->assertSame( $generated_old, $generated_new ); + $this->assertSame( $expected, $actual ); } - public static function simple_provider() { + public static function data_simple() { return array( array( // Simple equivalence. @@ -143,17 +157,19 @@ class PluralFormsTest extends WP_UnitTestCase { } /** + * Ensures that an exception is thrown when an invalid plural form is encountered. + * * @ticket 41562 - * @dataProvider simple_provider + * @dataProvider data_exceptions */ - public function test_simple( $expression, $expected ) { - $plural_forms = new Plural_Forms( $expression ); - $actual = array(); - foreach ( array_keys( $expected ) as $num ) { - $actual[ $num ] = $plural_forms->get( $num ); - } + public function test_exceptions( $expression, $expected_message, $call_get ) { + $this->expectException( 'Exception' ); + $this->expectExceptionMessage( $expected_message ); - $this->assertSame( $expected, $actual ); + $plural_forms = new Plural_Forms( $expression ); + if ( $call_get ) { + $plural_forms->get( 1 ); + } } public function data_exceptions() { @@ -196,22 +212,6 @@ class PluralFormsTest extends WP_UnitTestCase { ); } - /** - * Ensures that an exception is thrown when an invalid plural form is encountered. - * - * @ticket 41562 - * @dataProvider data_exceptions - */ - public function test_exceptions( $expression, $expected_message, $call_get ) { - $this->expectException( 'Exception' ); - $this->expectExceptionMessage( $expected_message ); - - $plural_forms = new Plural_Forms( $expression ); - if ( $call_get ) { - $plural_forms->get( 1 ); - } - } - /** * @ticket 41562 */ diff --git a/tests/phpunit/tests/post/nav-menu.php b/tests/phpunit/tests/post/nav-menu.php index dc7cc74e2d..d02a9b1767 100644 --- a/tests/phpunit/tests/post/nav-menu.php +++ b/tests/phpunit/tests/post/nav-menu.php @@ -965,23 +965,9 @@ class Tests_Post_Nav_Menu extends WP_UnitTestCase { $this->assertNotContains( 'current-menu-ancestor', $post_archive_menu_item->classes ); } - /** - * Provides IRI matching data for _wp_menu_item_classes_by_context() test. - */ - public function get_iri_current_menu_items() { - return array( - array( site_url( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/' ) ), - array( site_url( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82' ) ), - array( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/' ), - array( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82' ), - array( '/привет/' ), - array( '/привет' ), - ); - } - /** * @ticket 43401 - * @dataProvider get_iri_current_menu_items + * @dataProvider data_iri_current_menu_item */ public function test_iri_current_menu_item( $custom_link, $current = true ) { wp_update_nav_menu_item( @@ -1008,6 +994,20 @@ class Tests_Post_Nav_Menu extends WP_UnitTestCase { } } + /** + * Provides IRI matching data for _wp_menu_item_classes_by_context() test. + */ + public function data_iri_current_menu_item() { + return array( + array( site_url( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/' ) ), + array( site_url( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82' ) ), + array( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/' ), + array( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82' ), + array( '/привет/' ), + array( '/привет' ), + ); + } + /** * @ticket 44005 * @group privacy diff --git a/tests/phpunit/tests/post/query.php b/tests/phpunit/tests/post/query.php index 66bcdc2691..f67078117c 100644 --- a/tests/phpunit/tests/post/query.php +++ b/tests/phpunit/tests/post/query.php @@ -712,20 +712,10 @@ class Tests_Post_Query extends WP_UnitTestCase { $this->assertEquals( 2, $q->max_num_pages ); } - public function set_found_posts_provider() { - // Count return 0 for null, but 1 for other data you may not expect. - return array( - array( null, 0 ), - array( '', 1 ), - array( "To life, to life, l'chaim", 1 ), - array( false, 1 ), - ); - } - /** * @ticket 42860 * - * @dataProvider set_found_posts_provider + * @dataProvider data_set_found_posts_not_posts_as_an_array */ public function test_set_found_posts_not_posts_as_an_array( $posts, $expected ) { $q = new WP_Query( @@ -744,6 +734,16 @@ class Tests_Post_Query extends WP_UnitTestCase { $this->assertSame( $expected, $q->found_posts ); } + public function data_set_found_posts_not_posts_as_an_array() { + // Count return 0 for null, but 1 for other data you may not expect. + return array( + array( null, 0 ), + array( '', 1 ), + array( "To life, to life, l'chaim", 1 ), + array( false, 1 ), + ); + } + /** * @ticket 42469 */ diff --git a/tests/phpunit/tests/post/wpUniquePostSlug.php b/tests/phpunit/tests/post/wpUniquePostSlug.php index 6d279bbbd5..f242159987 100644 --- a/tests/phpunit/tests/post/wpUniquePostSlug.php +++ b/tests/phpunit/tests/post/wpUniquePostSlug.php @@ -128,7 +128,7 @@ class Tests_Post_wpUniquePostSlug extends WP_UnitTestCase { } /** - * @dataProvider allowed_post_statuses + * @dataProvider data_allowed_post_statuses_should_not_be_forced_to_be_unique */ public function test_allowed_post_statuses_should_not_be_forced_to_be_unique( $status ) { $p1 = self::factory()->post->create( @@ -149,7 +149,7 @@ class Tests_Post_wpUniquePostSlug extends WP_UnitTestCase { $this->assertSame( 'foo', $actual ); } - public function allowed_post_statuses() { + public function data_allowed_post_statuses_should_not_be_forced_to_be_unique() { return array( array( 'draft' ), array( 'pending' ), diff --git a/tests/phpunit/tests/rest-api.php b/tests/phpunit/tests/rest-api.php index 19e2758aed..20b23fc0fb 100644 --- a/tests/phpunit/tests/rest-api.php +++ b/tests/phpunit/tests/rest-api.php @@ -27,6 +27,10 @@ class Tests_REST_API extends WP_UnitTestCase { parent::tear_down(); } + public function filter_wp_rest_server_class( $class_name ) { + return 'Spy_REST_Server'; + } + /** * Checks that the main classes are loaded. */ @@ -822,7 +826,14 @@ class Tests_REST_API extends WP_UnitTestCase { unset( $filter ); } - public function jsonp_callback_provider() { + /** + * @dataProvider data_jsonp_callback_check + */ + public function test_jsonp_callback_check( $callback, $expected ) { + $this->assertSame( $expected, wp_check_jsonp_callback( $callback ) ); + } + + public function data_jsonp_callback_check() { return array( // Standard names. array( 'Springfield', true ), @@ -841,13 +852,13 @@ class Tests_REST_API extends WP_UnitTestCase { } /** - * @dataProvider jsonp_callback_provider + * @dataProvider data_rest_parse_date */ - public function test_jsonp_callback_check( $callback, $expected ) { - $this->assertSame( $expected, wp_check_jsonp_callback( $callback ) ); + public function test_rest_parse_date( $date, $expected ) { + $this->assertEquals( $expected, rest_parse_date( $date ) ); } - public function rest_date_provider() { + public function data_rest_parse_date() { return array( // Valid dates with timezones. array( '2017-01-16T11:30:00-05:00', gmmktime( 11, 30, 0, 1, 16, 2017 ) + 5 * HOUR_IN_SECONDS ), @@ -873,13 +884,13 @@ class Tests_REST_API extends WP_UnitTestCase { } /** - * @dataProvider rest_date_provider + * @dataProvider data_rest_parse_date_force_utc */ - public function test_rest_parse_date( $date, $expected ) { - $this->assertEquals( $expected, rest_parse_date( $date ) ); + public function test_rest_parse_date_force_utc( $date, $expected ) { + $this->assertSame( $expected, rest_parse_date( $date, true ) ); } - public function rest_date_force_utc_provider() { + public function data_rest_parse_date_force_utc() { return array( // Valid dates with timezones. array( '2017-01-16T11:30:00-05:00', gmmktime( 11, 30, 0, 1, 16, 2017 ) ), @@ -904,17 +915,6 @@ class Tests_REST_API extends WP_UnitTestCase { ); } - /** - * @dataProvider rest_date_force_utc_provider - */ - public function test_rest_parse_date_force_utc( $date, $expected ) { - $this->assertSame( $expected, rest_parse_date( $date, true ) ); - } - - public function filter_wp_rest_server_class( $class_name ) { - return 'Spy_REST_Server'; - } - public function test_register_rest_route_without_server() { $GLOBALS['wp_rest_server'] = null; add_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) ); @@ -1783,7 +1783,7 @@ class Tests_REST_API extends WP_UnitTestCase { } /** - * @dataProvider rest_ensure_response_data_provider + * @dataProvider data_rest_ensure_response_returns_instance_of_wp_rest_response * * @param mixed $response The response passed to rest_ensure_response(). * @param mixed $expected_data The expected data a response should include. @@ -1799,7 +1799,7 @@ class Tests_REST_API extends WP_UnitTestCase { * * @return array */ - public function rest_ensure_response_data_provider() { + public function data_rest_ensure_response_returns_instance_of_wp_rest_response() { return array( array( null, null ), array( array( 'chocolate' => 'cookies' ), array( 'chocolate' => 'cookies' ) ), diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 158f4d1546..55cf74f3d7 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -135,7 +135,16 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $this->assertCount( 3, $routes['/wp/v2/media/(?P[\d]+)'] ); } - public static function disposition_provider() { + /** + * @dataProvider data_parse_disposition + */ + public function test_parse_disposition( $header, $expected ) { + $header_list = array( $header ); + $parsed = WP_REST_Attachments_Controller::get_filename_from_disposition( $header_list ); + $this->assertSame( $expected, $parsed ); + } + + public static function data_parse_disposition() { return array( // Types. array( 'attachment; filename="foo.jpg"', 'foo.jpg' ), @@ -167,15 +176,6 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control ); } - /** - * @dataProvider disposition_provider - */ - public function test_parse_disposition( $header, $expected ) { - $header_list = array( $header ); - $parsed = WP_REST_Attachments_Controller::get_filename_from_disposition( $header_list ); - $this->assertSame( $expected, $parsed ); - } - public function test_context_param() { // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' ); @@ -1257,7 +1257,17 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $this->assertSame( $expected_output['caption']['raw'], $post->post_excerpt ); } - public static function attachment_roundtrip_provider() { + /** + * @dataProvider data_attachment_roundtrip_as_author + * @requires function imagejpeg + */ + public function test_attachment_roundtrip_as_author( $raw, $expected ) { + wp_set_current_user( self::$author_id ); + $this->assertFalse( current_user_can( 'unfiltered_html' ) ); + $this->verify_attachment_roundtrip( $raw, $expected ); + } + + public static function data_attachment_roundtrip_as_author() { return array( array( // Raw values. @@ -1354,16 +1364,6 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control ); } - /** - * @dataProvider attachment_roundtrip_provider - * @requires function imagejpeg - */ - public function test_post_roundtrip_as_author( $raw, $expected ) { - wp_set_current_user( self::$author_id ); - $this->assertFalse( current_user_can( 'unfiltered_html' ) ); - $this->verify_attachment_roundtrip( $raw, $expected ); - } - /** * @requires function imagejpeg */ diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index dbfca51fbb..9b4444f559 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -1144,7 +1144,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertSame( self::$post_id, $data['post'] ); } - public function comment_dates_provider() { + public function data_comment_dates() { return array( 'set date without timezone' => array( 'params' => array( @@ -1190,7 +1190,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase } /** - * @dataProvider comment_dates_provider + * @dataProvider data_comment_dates */ public function test_create_comment_date( $params, $results ) { wp_set_current_user( self::$admin_id ); @@ -2338,7 +2338,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase } /** - * @dataProvider comment_dates_provider + * @dataProvider data_comment_dates */ public function test_update_comment_date( $params, $results ) { wp_set_current_user( self::$editor_id ); diff --git a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php index 1927b3f824..3c627dfd59 100644 --- a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php +++ b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php @@ -2053,7 +2053,7 @@ class WP_Test_REST_Post_Meta_Fields extends WP_Test_REST_TestCase { /** * @ticket 43392 * @ticket 48363 - * @dataProvider _dp_meta_values_are_not_set_to_null_in_response_if_type_safely_serializable + * @dataProvider data_meta_values_are_not_set_to_null_in_response_if_type_safely_serializable */ public function test_meta_values_are_not_set_to_null_in_response_if_type_safely_serializable( $type, $stored, $expected ) { register_post_meta( @@ -2074,7 +2074,7 @@ class WP_Test_REST_Post_Meta_Fields extends WP_Test_REST_TestCase { $this->assertSame( $expected, $response->get_data()['meta']['safe'] ); } - public function _dp_meta_values_are_not_set_to_null_in_response_if_type_safely_serializable() { + public function data_meta_values_are_not_set_to_null_in_response_if_type_safely_serializable() { return array( array( 'boolean', 'true', true ), array( 'boolean', 'false', false ), diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 57f41971b5..353325fc81 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -2357,7 +2357,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->check_create_post_response( $response ); } - public function post_dates_provider() { + public function data_post_dates() { $all_statuses = array( 'draft', 'publish', @@ -2428,7 +2428,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te } /** - * @dataProvider post_dates_provider + * @dataProvider data_post_dates */ public function test_create_post_date( $status, $params, $results ) { wp_set_current_user( self::$editor_id ); @@ -3477,7 +3477,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te } /** - * @dataProvider post_dates_provider + * @dataProvider data_post_dates */ public function test_update_post_date( $status, $params, $results ) { wp_set_current_user( self::$editor_id ); @@ -4032,7 +4032,17 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertSame( $expected_output['excerpt']['raw'], $post->post_excerpt ); } - public static function post_roundtrip_provider() { + /** + * @dataProvider data_post_roundtrip_as_author + */ + public function test_post_roundtrip_as_author( $raw, $expected ) { + wp_set_current_user( self::$author_id ); + + $this->assertFalse( current_user_can( 'unfiltered_html' ) ); + $this->verify_post_roundtrip( $raw, $expected ); + } + + public static function data_post_roundtrip_as_author() { return array( array( // Raw values. @@ -4129,16 +4139,6 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te ); } - /** - * @dataProvider post_roundtrip_provider - */ - public function test_post_roundtrip_as_author( $raw, $expected ) { - wp_set_current_user( self::$author_id ); - - $this->assertFalse( current_user_can( 'unfiltered_html' ) ); - $this->verify_post_roundtrip( $raw, $expected ); - } - public function test_post_roundtrip_as_editor_unfiltered_html() { wp_set_current_user( self::$editor_id ); diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php index 22acb99060..aac7145287 100644 --- a/tests/phpunit/tests/rest-api/rest-request.php +++ b/tests/phpunit/tests/rest-api/rest-request.php @@ -57,7 +57,16 @@ class Tests_REST_Request extends WP_UnitTestCase { $this->assertSame( array( $value1, $value2 ), $this->request->get_header_as_array( 'Accept' ) ); } - public static function header_provider() { + /** + * @dataProvider data_header_canonicalization + * @param string $original Original header key. + * @param string $expected Expected canonicalized version. + */ + public function test_header_canonicalization( $original, $expected ) { + $this->assertSame( $expected, $this->request->canonicalize_header_name( $original ) ); + } + + public static function data_header_canonicalization() { return array( array( 'Test', 'test' ), array( 'TEST', 'test' ), @@ -69,27 +78,7 @@ class Tests_REST_Request extends WP_UnitTestCase { } /** - * @dataProvider header_provider - * @param string $original Original header key. - * @param string $expected Expected canonicalized version. - */ - public function test_header_canonicalization( $original, $expected ) { - $this->assertSame( $expected, $this->request->canonicalize_header_name( $original ) ); - } - - public static function content_type_provider() { - return array( - // Check basic parsing. - array( 'application/x-wp-example', 'application/x-wp-example', 'application', 'x-wp-example', '' ), - array( 'application/x-wp-example; charset=utf-8', 'application/x-wp-example', 'application', 'x-wp-example', 'charset=utf-8' ), - - // Check case insensitivity. - array( 'APPLICATION/x-WP-Example', 'application/x-wp-example', 'application', 'x-wp-example', '' ), - ); - } - - /** - * @dataProvider content_type_provider + * @dataProvider data_content_type_parsing * * @param string $header Header value. * @param string $value Full type value. @@ -110,6 +99,17 @@ class Tests_REST_Request extends WP_UnitTestCase { $this->assertSame( $parameters, $parsed['parameters'] ); } + public static function data_content_type_parsing() { + return array( + // Check basic parsing. + array( 'application/x-wp-example', 'application/x-wp-example', 'application', 'x-wp-example', '' ), + array( 'application/x-wp-example; charset=utf-8', 'application/x-wp-example', 'application', 'x-wp-example', 'charset=utf-8' ), + + // Check case insensitivity. + array( 'APPLICATION/x-WP-Example', 'application/x-wp-example', 'application', 'x-wp-example', '' ), + ); + } + protected function request_with_parameters() { $this->request->set_url_params( array( @@ -186,20 +186,9 @@ class Tests_REST_Request extends WP_UnitTestCase { $this->assertEmpty( $this->request->get_param( 'has_json_params' ) ); } - public static function alternate_json_content_type_provider() { - return array( - array( 'application/ld+json', 'json', true ), - array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', 'json', true ), - array( 'application/activity+json', 'json', true ), - array( 'application/json+oembed', 'json', true ), - array( 'application/nojson', 'body', false ), - array( 'application/no.json', 'body', false ), - ); - } - /** * @ticket 49404 - * @dataProvider alternate_json_content_type_provider + * @dataProvider data_alternate_json_content_type * * @param string $content_type The Content-Type header. * @param string $source The source value. @@ -217,20 +206,20 @@ class Tests_REST_Request extends WP_UnitTestCase { $this->assertEquals( $accept_json, $this->request->get_param( 'has_json_params' ) ); } - public static function is_json_content_type_provider() { + public static function data_alternate_json_content_type() { return array( - array( 'application/ld+json', true ), - array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', true ), - array( 'application/activity+json', true ), - array( 'application/json+oembed', true ), - array( 'application/nojson', false ), - array( 'application/no.json', false ), + array( 'application/ld+json', 'json', true ), + array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', 'json', true ), + array( 'application/activity+json', 'json', true ), + array( 'application/json+oembed', 'json', true ), + array( 'application/nojson', 'body', false ), + array( 'application/no.json', 'body', false ), ); } /** * @ticket 49404 - * @dataProvider is_json_content_type_provider + * @dataProvider data_is_json_content_type * * @param string $content_type The Content-Type header. * @param bool $is_json The is_json value. @@ -244,6 +233,17 @@ class Tests_REST_Request extends WP_UnitTestCase { $this->assertSame( $is_json, $this->request->is_json_content_type() ); } + public static function data_is_json_content_type() { + return array( + array( 'application/ld+json', true ), + array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', true ), + array( 'application/activity+json', true ), + array( 'application/json+oembed', true ), + array( 'application/nojson', false ), + array( 'application/no.json', false ), + ); + } + /** * @ticket 49404 */ @@ -310,20 +310,12 @@ class Tests_REST_Request extends WP_UnitTestCase { $this->assertEmpty( $this->request->get_param( 'has_json_params' ) ); } - public function non_post_http_methods_with_request_body_provider() { - return array( - array( 'PUT' ), - array( 'PATCH' ), - array( 'DELETE' ), - ); - } - /** * Tests that methods supporting request bodies have access to the * request's body. For POST this is straightforward via `$_POST`; for * other methods `WP_REST_Request` needs to parse the body for us. * - * @dataProvider non_post_http_methods_with_request_body_provider + * @dataProvider data_non_post_body_parameters */ public function test_non_post_body_parameters( $request_method ) { $data = array( @@ -345,6 +337,14 @@ class Tests_REST_Request extends WP_UnitTestCase { } } + public function data_non_post_body_parameters() { + return array( + array( 'PUT' ), + array( 'PATCH' ), + array( 'DELETE' ), + ); + } + public function test_parameters_for_json_put() { $data = array( 'foo' => 'bar', diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index b06a46ca2f..3a7bf78353 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -49,6 +49,10 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { parent::tear_down(); } + public function filter_wp_rest_server_class() { + return 'Spy_REST_Server'; + } + public function test_envelope() { $data = array( 'amount of arbitrary data' => 'alot', @@ -1004,7 +1008,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { } /** - * @dataProvider _dp_response_to_data_embedding + * @dataProvider data_response_to_data_embedding */ public function test_response_to_data_embedding( $expected, $embed ) { $response = new WP_REST_Response(); @@ -1022,7 +1026,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { } } - public function _dp_response_to_data_embedding() { + public function data_response_to_data_embedding() { return array( array( array( 'author', 'wp:term', 'https://wordpress.org' ), @@ -1461,10 +1465,6 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $this->assertSame( 'data\\with\\slashes', rest_get_server()->last_request->get_header( 'x_my_header' ) ); } - public function filter_wp_rest_server_class() { - return 'Spy_REST_Server'; - } - /** * Refreshed nonce should not be present in header when an invalid nonce is passed for logged in user. * diff --git a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php index aa1f74b05c..811767444d 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php @@ -169,7 +169,7 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc /** * @ticket 54507 - * @dataProvider get_template_endpoint_urls + * @dataProvider data_get_item_works_with_a_single_slash */ public function test_get_item_works_with_a_single_slash( $endpoint_url ) { wp_set_current_user( self::$admin_id ); @@ -203,7 +203,7 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc ); } - public function get_template_endpoint_urls() { + public function data_get_item_works_with_a_single_slash() { return array( array( '/wp/v2/templates/default/my_template' ), array( '/wp/v2/templates/default//my_template' ), @@ -375,7 +375,7 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc /** * @ticket 54507 - * @dataProvider get_template_ids_to_sanitize + * @dataProvider data_sanitize_template_id */ public function test_sanitize_template_id( $input_id, $sanitized_id ) { $endpoint = new WP_REST_Templates_Controller( 'wp_template' ); @@ -385,7 +385,7 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc ); } - public function get_template_ids_to_sanitize() { + public function data_sanitize_template_id() { return array( array( 'tt1-blocks/index', 'tt1-blocks//index' ), array( 'tt1-blocks//index', 'tt1-blocks//index' ), diff --git a/tests/phpunit/tests/rewrite/rewriteTags.php b/tests/phpunit/tests/rewrite/rewriteTags.php index 8eeef7f7d9..31c28df15e 100644 --- a/tests/phpunit/tests/rewrite/rewriteTags.php +++ b/tests/phpunit/tests/rewrite/rewriteTags.php @@ -20,19 +20,8 @@ class Tests_Rewrite_Tags extends WP_UnitTestCase { $this->queryreplace = $wp_rewrite->queryreplace; } - public function _invalid_rewrite_tags() { - return array( - array( 'foo', 'bar' ), - array( '%', 'bar' ), - array( '%a', 'bar' ), - array( 'a%', 'bar' ), - array( '%%', 'bar' ), - array( '', 'bar' ), - ); - } - /** - * @dataProvider _invalid_rewrite_tags + * @dataProvider data_add_rewrite_tag_invalid * * @param string $tag Rewrite tag. * @param string $regex Regex. @@ -46,6 +35,17 @@ class Tests_Rewrite_Tags extends WP_UnitTestCase { $this->assertSameSets( $this->queryreplace, $wp_rewrite->queryreplace ); } + public function data_add_rewrite_tag_invalid() { + return array( + array( 'foo', 'bar' ), + array( '%', 'bar' ), + array( '%a', 'bar' ), + array( 'a%', 'bar' ), + array( '%%', 'bar' ), + array( '', 'bar' ), + ); + } + public function test_add_rewrite_tag_empty_query() { global $wp_rewrite; diff --git a/tests/phpunit/tests/shortcode.php b/tests/phpunit/tests/shortcode.php index 33549b73e8..1c19cfb42d 100644 --- a/tests/phpunit/tests/shortcode.php +++ b/tests/phpunit/tests/shortcode.php @@ -404,7 +404,19 @@ EOF; $this->assertSame( $test_string, shortcode_unautop( wpautop( $test_string ) ) ); } - public function data_test_strip_shortcodes() { + /** + * @ticket 10326 + * + * @dataProvider data_strip_shortcodes + * + * @param string $expected Expected output. + * @param string $content Content to run strip_shortcodes() on. + */ + public function test_strip_shortcodes( $expected, $content ) { + $this->assertSame( $expected, strip_shortcodes( $content ) ); + } + + public function data_strip_shortcodes() { return array( array( 'before', 'before[gallery]' ), array( 'after', '[gallery]after' ), @@ -419,18 +431,6 @@ EOF; ); } - /** - * @ticket 10326 - * - * @dataProvider data_test_strip_shortcodes - * - * @param string $expected Expected output. - * @param string $content Content to run strip_shortcodes() on. - */ - public function test_strip_shortcodes( $expected, $content ) { - $this->assertSame( $expected, strip_shortcodes( $content ) ); - } - /** * @ticket 37767 */ diff --git a/tests/phpunit/tests/sitemaps/functions.php b/tests/phpunit/tests/sitemaps/functions.php index f67335733b..0620d465d4 100644 --- a/tests/phpunit/tests/sitemaps/functions.php +++ b/tests/phpunit/tests/sitemaps/functions.php @@ -63,7 +63,7 @@ class Tests_Sitemaps_Functions extends WP_UnitTestCase { /** * Test get_sitemap_url() with plain permalinks. * - * @dataProvider plain_permalinks_provider + * @dataProvider data_get_sitemap_url_plain_permalinks */ public function test_get_sitemap_url_plain_permalinks( $name, $subtype_name, $page, $expected ) { $actual = get_sitemap_url( $name, $subtype_name, $page ); @@ -74,7 +74,7 @@ class Tests_Sitemaps_Functions extends WP_UnitTestCase { /** * Test get_sitemap_url() with pretty permalinks. * - * @dataProvider pretty_permalinks_provider + * @dataProvider data_get_sitemap_url_pretty_permalinks */ public function test_get_sitemap_url_pretty_permalinks( $name, $subtype_name, $page, $expected ) { $this->set_permalink_structure( '/%postname%/' ); @@ -96,7 +96,7 @@ class Tests_Sitemaps_Functions extends WP_UnitTestCase { * @type string|false $4 Sitemap URL. * } */ - public function plain_permalinks_provider() { + public function data_get_sitemap_url_plain_permalinks() { return array( array( 'posts', 'post', 1, home_url( '/?sitemap=posts&sitemap-subtype=post&paged=1' ) ), array( 'posts', 'post', 0, home_url( '/?sitemap=posts&sitemap-subtype=post&paged=1' ) ), @@ -128,7 +128,7 @@ class Tests_Sitemaps_Functions extends WP_UnitTestCase { * @type string|false $4 Sitemap URL. * } */ - public function pretty_permalinks_provider() { + public function data_get_sitemap_url_pretty_permalinks() { return array( array( 'posts', 'post', 1, home_url( '/wp-sitemap-posts-post-1.xml' ) ), array( 'posts', 'post', 0, home_url( '/wp-sitemap-posts-post-1.xml' ) ), diff --git a/tests/phpunit/tests/term/wpGenerateTagCloud.php b/tests/phpunit/tests/term/wpGenerateTagCloud.php index d1b02bb04d..62de4a0c26 100644 --- a/tests/phpunit/tests/term/wpGenerateTagCloud.php +++ b/tests/phpunit/tests/term/wpGenerateTagCloud.php @@ -8,7 +8,7 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { /** * Testing when passed $tags array is empty * - * @dataProvider empty_tags_data_provider + * @dataProvider data_empty_tags * * @param $expected Expected output from `wp_generate_tag_cloud()`. * @param $args Options for `wp_generate_tag_cloud()`. @@ -21,7 +21,7 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { /** * Testing when no tags are found * - * @dataProvider empty_tags_data_provider + * @dataProvider data_empty_tags * * @param $expected Expected output from `wp_generate_tag_cloud()`. * @param $args Options for `wp_generate_tag_cloud()`. @@ -41,7 +41,7 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { * * @return array */ - public function empty_tags_data_provider() { + public function data_empty_tags() { return array( // When 'format' => 'array', we should be getting an empty array back. array( diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index 4583e0155b..beecfd3b85 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -1314,13 +1314,9 @@ class Tests_User_Capabilities extends WP_UnitTestCase { } } - public function authorless_post_statuses() { - return array( array( 'draft' ), array( 'private' ), array( 'publish' ) ); - } - /** * @ticket 27020 - * @dataProvider authorless_post_statuses + * @dataProvider data_authorless_post */ public function test_authorless_post( $status ) { // Make a post without an author. @@ -1349,6 +1345,10 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertSame( 'publish' === $status, $contributor->has_cap( 'read_post', $post ) ); } + public function data_authorless_post() { + return array( array( 'draft' ), array( 'private' ), array( 'publish' ) ); + } + /** * @ticket 16714 */ diff --git a/tests/phpunit/tests/user/query.php b/tests/phpunit/tests/user/query.php index 722a3fbeaf..85170997d3 100644 --- a/tests/phpunit/tests/user/query.php +++ b/tests/phpunit/tests/user/query.php @@ -186,7 +186,7 @@ class Tests_User_Query extends WP_UnitTestCase { } /** - * @dataProvider orderby_should_convert_non_prefixed_keys_data + * @dataProvider data_orderby_should_convert_non_prefixed_keys */ public function test_orderby_should_convert_non_prefixed_keys( $short_key, $full_key ) { $q = new WP_User_Query( @@ -198,7 +198,7 @@ class Tests_User_Query extends WP_UnitTestCase { $this->assertStringContainsString( "ORDER BY $full_key", $q->query_orderby ); } - public function orderby_should_convert_non_prefixed_keys_data() { + public function data_orderby_should_convert_non_prefixed_keys() { return array( array( 'nicename', 'user_nicename' ), array( 'email', 'user_email' ),