wordpress-develop/tests/phpunit/tests
Tonya Mork 90a7ecc474 Editor: Rename new theme_json_{$context} filters.
The newly introduced filters are renamed to use the `wp_theme_json_data{$context}` structure:

* `theme_json_default` renamed to `wp_theme_json_data_default`
* `theme_json_theme` renamed to `wp_theme_json_data_theme`
* `theme_json_blocks` renamed to `wp_theme_json_data_blocks`
* `theme_json_user` renamed to `wp_theme_json_data_user`

The following new filter gets the `wp_` prefix added:
* `theme_json_get_style_nodes` renamed to `wp_theme_json_get_style_nodes`

Follow-up to [56467], [54183], [54118].

Props kebbet, desrosj, mukesh27, ocean90, sergeybiryukov, davidbaumwald, hellofromTonya.
Fixes #56796.

git-svn-id: https://develop.svn.wordpress.org/trunk@54501 602fd350-edb4-49c9-b593-d223f7449a82
2022-10-11 20:06:16 +00:00
..
admin Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
ajax Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
attachment Build/Test Tools: Add and fix @covers tags to the attachments and block-supports test groups. 2022-07-07 21:06:03 +00:00
block-supports Editor: Merge latest fluid typography bugfixes for 6.1 Release Candidate 1. 2022-10-11 18:42:20 +00:00
block-templates Editor: Adds template types, is_wp_suggestion, and fallback template content. 2022-09-20 21:19:10 +00:00
blocks Build/Test Tools: Add unit test for non-existing block-styles registration. 2022-10-11 09:58:27 +00:00
bookmark General: Fix 'rel' argument in Tests_Functions_wpListBookmarks test datasets. 2021-12-21 00:10:26 +00:00
canonical Code Modernization: Explicitly declare all properties created in set_up() methods of various test classes. 2022-08-27 12:30:08 +00:00
category Tests: Use the factory method instead of the property. 2022-09-06 22:09:49 +00:00
comment Comments: Return early from comment_form() if an invalid post ID is passed. 2022-10-11 15:43:04 +00:00
compat Tests: Restore @covers tags for PHP polyfill tests in phpunit/tests/compat/. 2022-09-03 14:45:20 +00:00
cron Cron API: Modify _get_cron_array() to always return an array. 2022-07-29 03:32:58 +00:00
customize Coding Standards: Correct alignment in test_import_theme_starter_content(). 2022-10-09 16:37:01 +00:00
date Code Modernization: Fix null to non-nullable deprecations in wp_xmlrpc_server::_insert_post(). 2022-09-27 02:16:28 +00:00
db Database: Correct MariaDB version check in wpdb::has_cap(). 2022-10-04 15:39:28 +00:00
dependencies Code Modernization: Use correct default value for JavaScript translations path. 2022-09-28 17:31:53 +00:00
editor Editor: Add PHPUnit tests for 5.9.0 new functions. 2022-10-04 14:20:18 +00:00
error-protection Tests: Rename classes in phpunit/tests/error-protection/ per the naming conventions. 2021-08-21 15:32:53 +00:00
feed Tests: Correctly use the factory method. 2022-09-06 22:03:10 +00:00
filesystem Coding Standards: Add visibility to methods in tests/phpunit/tests/. 2021-11-04 15:22:47 +00:00
formatting Formatting: Strip object replacement characters from slugs. 2022-10-11 10:27:00 +00:00
functions General: Remove instances of _wp_http_referer from GET forms in the admin. 2022-10-10 18:57:44 +00:00
general Feeds: Add a set of fine-grained filters to disable the different types of feed links separately. 2022-09-14 17:12:20 +00:00
hooks Code Modernization: Explicitly declare all properties in various tests. 2022-08-25 15:34:24 +00:00
http Tests: Use a consistent URL in HTTP response cookie tests. 2022-06-12 15:16:09 +00:00
image Media: ensure the wp_editor_set_quality filter consistently passes the correct output mime type. 2022-10-07 19:15:59 +00:00
import Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
includes Code Modernization: Explicitly declare all properties created in set_up() methods of various test classes. 2022-08-27 12:30:08 +00:00
kses Editor: Add PHPUnit tests for 5.9.0 new functions. 2022-10-04 14:20:18 +00:00
l10n Code Modernization: Use correct default value for JavaScript translations path. 2022-09-28 17:31:53 +00:00
link Tests: Use the factory method instead of the property. 2022-09-06 22:09:49 +00:00
load Login and Registration: Rename is_login_screen() function to is_login(). 2022-10-10 17:57:52 +00:00
media Tests: Use the factory method instead of the property. 2022-09-06 22:09:49 +00:00
menu Menus: Remove .menu-item-has-children on wp_nav_menu last level menu items when $depth arg is used. 2022-10-11 14:02:55 +00:00
meta Code Modernization: Remove dynamic properties in Tests_*_Slashes. 2022-06-23 14:24:08 +00:00
multisite Networks and Sites: Ensure fileupload_maxk is an int to avoid potential fatal errors. 2022-10-11 15:05:29 +00:00
oembed Tests: Correctly use the factory method. 2022-09-06 22:03:10 +00:00
option Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
pluggable Users: Revert use of shared objects for current user. 2022-10-06 04:36:46 +00:00
pomo i18n: Ensure empty strings are consistently translated to ''. 2022-09-26 20:54:44 +00:00
post Query: Move call to update_menu_item_cache in WP_Query 2022-10-07 09:58:32 +00:00
privacy Tests: Use the factory method instead of the property. 2022-09-06 22:09:49 +00:00
query Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
rest-api Tests: Minimize file copying in WP_REST_Attachments_Controller tests. 2022-10-09 17:45:54 +00:00
rewrite Tests: Consistently create a post fixture in old date or slug redirect tests. 2022-09-06 01:25:45 +00:00
sitemaps Sitemaps: Prevent invalid provider names throwing errors. 2022-08-05 05:47:56 +00:00
style-engine Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
taxonomy Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
term Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
theme Editor: Rename new theme_json_{$context} filters. 2022-10-11 20:06:16 +00:00
url Tests: Remove @uses tags from the test suite. 2022-07-08 00:11:15 +00:00
user Users: Fetch user by login in retrieve_password() if not found by email. 2022-10-11 13:43:20 +00:00
webfonts Tests: Ignore EOL differences in Webfonts API tests. 2022-04-30 11:33:30 +00:00
widgets Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
wp Bootstrap/Load: Send HTTP headers after querying posts in WP::main(). 2022-09-20 13:10:24 +00:00
xmlrpc Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
actions.php Code Modernization: Explicitly declare all properties in various tests. 2022-08-25 15:34:24 +00:00
adminbar.php Tests: Correctly use the factory method. 2022-09-06 22:03:10 +00:00
auth.php Tests: Use the factory method instead of the property. 2022-09-06 22:09:49 +00:00
avatar.php Media: Add decoding="async" to image attributes. 2022-06-09 05:29:57 +00:00
basic.php Tests: Separate the tests in basic.php for clarity. 2022-07-07 23:55:13 +00:00
block-template-utils.php Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
block-template.php Site Editor: Resolve homepage template on server-side 2022-04-07 13:33:03 +00:00
cache.php Tests: Use named data provider for WP_Object_Cache::is_valid_key() test. 2022-08-04 17:47:41 +00:00
canonical.php Canonical: Include all public status in 404 redirects. 2022-04-01 03:23:07 +00:00
category.php Build/Test Tools: Add @covers tags to the taxonomy and category test groups. 2022-07-07 23:00:07 +00:00
comment-submission.php Comments: Consistently normalize user_ID to user_id in wp_new_comment(). 2022-10-11 16:30:40 +00:00
comment.php Comments: Consistently normalize user_ID to user_id in wp_new_comment(). 2022-10-11 16:30:40 +00:00
cron.php Cron API: Modify _get_cron_array() to always return an array. 2022-07-29 03:32:58 +00:00
db.php Database: Ensure MySQL port numbers are numeric in wpdb. 2022-07-06 05:31:47 +00:00
dbdelta.php Database: Ignore display width for integer data types in dbDelta() on MySQL 8.0.17 or later. 2022-08-15 13:16:22 +00:00
dependencies.php Script Loader: Allow for wp_register_script() to be called after wp_enqueue_script(). 2021-12-07 17:44:46 +00:00
file.php Code Modernization: Remove dynamic properties in Tests_File. 2022-08-07 14:48:42 +00:00
filters.php Tests: Update the terminology used for action or filter names in MockAction class. 2022-07-31 16:25:27 +00:00
functions.php Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
https-detection.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
https-migration.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
kses.php Tests: Simplify the data provider for testing whether KSES globals are defined. 2022-09-19 14:15:10 +00:00
l10n.php Tests: Ensure prerequisites are met for draft length tests in Tests_L10n. 2022-10-01 15:47:13 +00:00
link.php Coding Standards: Add visibility to methods in tests/phpunit/tests/. 2021-11-04 15:22:47 +00:00
locale.php Build/Test Tools: Add @covers tags to the l10n and i18n tests. 2022-08-08 23:39:06 +00:00
mail.php Mail: Prevent the last character of names in “From” headers from being trimmed. 2022-08-16 18:16:43 +00:00
media.php Media: ensure the wp_editor_set_quality filter consistently passes the correct output mime type. 2022-10-07 19:15:59 +00:00
meta.php Code Modernization: Explicitly declare all properties created in set_up() methods of various test classes. 2022-08-27 12:30:08 +00:00
multisite.php Coding Standards: Add visibility to methods in tests/phpunit/tests/. 2021-11-04 15:22:47 +00:00
pluggable.php Cache API: Introduce wp_cache_supports() function. 2022-10-10 18:20:28 +00:00
post.php Tests: Use the factory method instead of the property. 2022-09-06 22:09:49 +00:00
query.php Query: Avoid PHP notices when get_queried_object() returns null. 2022-10-11 18:13:34 +00:00
readme.php Tests: Relocate the tests for recommended PHP, MySQL, and MariaDB versions. 2022-10-11 14:25:47 +00:00
rest-api.php REST API: Ensure args is an array of arrays in register_rest_route(). 2022-09-27 20:12:00 +00:00
rewrite.php Code Modernization: Check the return type of parse_url() in url_to_postid(). 2022-10-01 03:23:41 +00:00
robots.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
shortcode.php Code Modernization: Explicitly declare all properties created in set_up() methods of various test classes. 2022-08-27 12:30:08 +00:00
taxonomy.php Tests: Use the factory method instead of the property. 2022-09-06 22:09:49 +00:00
template.php Administration: Allow to wrap Settings sections with custom HTML content. 2022-09-20 09:57:43 +00:00
term.php Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
theme.php Themes: Import Twenty Twenty-Three is now the default theme. 2022-09-20 01:34:49 +00:00
upload.php Coding Standards: Add visibility to methods in tests/phpunit/tests/. 2021-11-04 15:22:47 +00:00
url.php Tests: Remove @uses tags from the test suite. 2022-07-08 00:11:15 +00:00
user.php Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
utils.php Tests: Correct the @covers tag in a test for strip_ws() utility function. 2022-09-01 19:06:19 +00:00
walker.php Code Modernization: Explicitly declare all properties created in set_up() methods of various test classes. 2022-08-27 12:30:08 +00:00
widgets.php Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
wp.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00

<?php
/**
 * Validate recommended versions for dependencies referenced in `readme.html`,
 * based on external site support pages.
 *
 * @group external-http
 */
class Tests_Readme extends WP_UnitTestCase {

	/**
	 * @coversNothing
	 */
	public function test_readme_php_version() {
		$this->markTestSkipped(
			'Temporarily disabled. Test should be re-enabled once WordPress is fully compatible with PHP 8.0+.'
		);

		// This test is designed to only run on trunk.
		$this->skipOnAutomatedBranches();

		$readme = file_get_contents( ABSPATH . 'readme.html' );

		preg_match( '#Recommendations.*PHP</a> version <strong>([0-9.]*)#s', $readme, $matches );

		$response_body = $this->get_response_body( 'https://www.php.net/supported-versions.php' );

		preg_match_all( '#<tr class="stable">\s*<td>\s*<a [^>]*>\s*([0-9.]*)#s', $response_body, $php_matches );

		$this->assertContains( $matches[1], $php_matches[1], "readme.html's Recommended PHP version is too old. Remember to update the WordPress.org Requirements page, too." );
	}

	/**
	 * @coversNothing
	 */
	public function test_readme_mysql_version() {
		// This test is designed to only run on trunk.
		$this->skipOnAutomatedBranches();

		$readme = file_get_contents( ABSPATH . 'readme.html' );

		preg_match( '#Recommendations.*MySQL</a> version <strong>([0-9.]*)#s', $readme, $matches );

		$response_body = $this->get_response_body( "https://dev.mysql.com/doc/relnotes/mysql/{$matches[1]}/en/" );

		// Retrieve the date of the first GA release for the recommended branch.
		preg_match( '#.*(\d{4}-\d{2}-\d{2}), General Availability#s', $response_body, $mysql_matches );

		/*
		 * Per https://www.mysql.com/support/, Oracle actively supports MySQL releases for 5 years from GA release.
		 *
		 * The currently recommended MySQL 5.7 branch moved from active support to extended support on 2020-10-21.
		 * As WordPress core is not fully compatible with MySQL 8.0 at this time, the "supported" period here
		 * is increased to 8 years to include extended support.
		 *
		 * TODO: Reduce this back to 5 years once MySQL 8.0 compatibility is achieved.
		 */
		$mysql_eol    = gmdate( 'Y-m-d', strtotime( $mysql_matches[1] . ' +8 years' ) );
		$current_date = gmdate( 'Y-m-d' );

		$this->assertLessThan( $mysql_eol, $current_date, "readme.html's Recommended MySQL version is too old. Remember to update the WordPress.org Requirements page, too." );
	}

	/**
	 * @coversNothing
	 */
	public function test_readme_mariadb_version() {
		// This test is designed to only run on trunk.
		$this->skipOnAutomatedBranches();

		$readme = file_get_contents( ABSPATH . 'readme.html' );

		preg_match( '#Recommendations.*MariaDB</a> version <strong>([0-9.]*)#s', $readme, $matches );
		$matches[1] = str_replace( '.', '', $matches[1] );

		$response_body = $this->get_response_body( "https://mariadb.com/kb/en/release-notes-mariadb-{$matches[1]}-series/" );

		// Retrieve the date of the first stable release for the recommended branch.
		preg_match( '#.*Stable.*?(\d{2} [A-Za-z]{3} \d{4})#s', $response_body, $mariadb_matches );

		// Per https://mariadb.org/about/#maintenance-policy, MariaDB releases are supported for 5 years.
		$mariadb_eol  = gmdate( 'Y-m-d', strtotime( $mariadb_matches[1] . ' +5 years' ) );
		$current_date = gmdate( 'Y-m-d' );

		$this->assertLessThan( $mariadb_eol, $current_date, "readme.html's Recommended MariaDB version is too old. Remember to update the WordPress.org Requirements page, too." );
	}

	/**
	 * Helper function to retrieve the response body or skip the test on HTTP timeout.
	 *
	 * @param string $url The URL to retrieve the response from.
	 * @return string The response body.
	 */
	public function get_response_body( $url ) {
		$response = wp_remote_get( $url );

		$this->skipTestOnTimeout( $response );

		$response_code = wp_remote_retrieve_response_code( $response );
		$response_body = wp_remote_retrieve_body( $response );

		if ( 200 !== $response_code ) {
			$parsed_url = parse_url( $url );

			$error_message = sprintf(
				'Could not contact %1$s to check versions. Response code: %2$s. Response body: %3$s',
				$parsed_url['host'],
				$response_code,
				$response_body
			);

			if ( 503 === $response_code ) {
				$this->markTestSkipped( $error_message );
			}

			$this->fail( $error_message );
		}

		return $response_body;
	}
}