wordpress-develop/tests/phpunit/tests
Jonny Harris 2724a495af Cache API: Add a warning when calling _get_non_cached_ids with invalid ids.
Sanitize the array of ids passed to the `_get_non_cached_ids` function and add a `_doing_it_wrong` call, if an invalid type is passed. 

Props tillkruess, spacedmonkey, peterwilsoncc, flixos90, SergeyBiryukov.
Fixes #57593.

git-svn-id: https://develop.svn.wordpress.org/trunk@55543 602fd350-edb4-49c9-b593-d223f7449a82
2023-03-14 15:51:28 +00:00
..
admin Upgrade/Install: Introduce WP_Automatic_Updater::is_allowed_dir() method. 2023-02-26 15:17:45 +00:00
ajax Tests: Merge file-level and class-level DocBlocks in various unit test files. 2023-02-14 16:10:13 +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 Tests: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +00:00
block-templates Editor: Remove need for template prefix in get_template_hierarchy. 2023-02-02 19:36:29 +00:00
blocks Tests: Add a unit test for register_block_style_handle() with an RTL locale. 2023-03-08 15:00:12 +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: Split the tests from category.php into individual test classes. 2022-10-29 14:38:18 +00:00
comment Comments: Prevent replying to unapproved comments. 2023-02-21 01:43:33 +00:00
compat Code Modernization: Rename parameters that use reserved keywords in phpunit/tests/compat/mbSubstr.php. 2023-01-08 01:13:59 +00:00
cron Cron API: Modify _get_cron_array() to always return an array. 2022-07-29 03:32:58 +00:00
customize Tests: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +00:00
date Build/Test Tooling: Use assertSame() in WP_Date_Query tests. 2023-03-06 14:44:35 +00:00
db Tests: Correct references to set_up() and tear_down() in various DocBlocks. 2022-11-22 21:25:27 +00:00
dependencies Editor: Fix 'wp-block-library-theme' style enqueue conditions. 2023-02-20 21:11:57 +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: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +00:00
filesystem Filesystem API: Add test for uncovered WP_Error in move_dir(). 2023-02-07 03:15:49 +00:00
formatting Formatting: Restore consistent quotes in _make_web_ftp_clickable_cb(). 2023-03-09 00:18:29 +00:00
functions Cache API: Add a warning when calling _get_non_cached_ids with invalid ids. 2023-03-14 15:51:28 +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: Rename parameters that use reserved keywords in phpunit/tests/hooks/addFilter.php. 2023-01-17 14:05:38 +00:00
html-api HTML API: Fix finding RCData and Script tag closers. 2023-03-06 18:53:38 +00:00
http HTTP API: Add fragment support to WP_Http::make_absolute_url(). 2023-02-21 01:47:57 +00:00
image Tests: Use more specific assertions in image saving tests. 2023-01-15 13:36:10 +00:00
import Coding Standards: Always use parentheses when instantiating an object. 2022-11-29 15:49:49 +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 I18N: Check that $wp_locale global is set before calling its methods. 2023-02-15 23:35:33 +00:00
link Tests: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +00:00
load Tests: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +00:00
media Media: Revert the addition of a $size parameter to get_attached_file(). 2023-03-01 00:34:18 +00:00
menu Menus: Test creating parent after a child doesn't throw an error. 2023-02-14 03:30:58 +00:00
meta Users: Clear the user_meta cache when clean_user_cache function is called. 2022-12-06 13:52:02 +00:00
multisite Posts, Post Types: Pass the post object to _update_posts_count_on_delete(). 2023-02-24 01:21:54 +00:00
oembed Tests: Bring some consistency to mocking HTTP requests in unit tests. 2023-01-05 10:21:19 +00:00
option Options, Meta APIs: Add a filter to allow the shortcut return to wp_load_alloptions function. 2023-02-07 12:47:30 +00:00
pluggable Code Modernization: Rename parameters that use reserved keywords in phpunit/tests/pluggable/signatures.php. 2023-01-22 00:15:14 +00:00
pomo Coding Standards: Always use parentheses when instantiating an object. 2022-11-29 15:49:49 +00:00
post Revisions: Remove an unnecessary call to _doing_it_wrong() and corresponding new text string from the implementation of the new wp_save_post_revision_revisions_before_deletion filter. 2023-02-22 20:47:38 +00:00
privacy Tests: Merge file-level and class-level DocBlocks in various unit test files. 2023-02-14 16:10:13 +00:00
query Tests: Make sure the correct query is tested for term limits in taxonomy queries. 2023-03-04 11:50:26 +00:00
rest-api Tests: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +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 Editor: Introduce minimum height dimensions block support. 2023-02-01 16:13:49 +00:00
taxonomy Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
term Coding Standards: Rename $post_ID variable to $post_id in various files. 2023-02-19 15:03:50 +00:00
theme Tests: Use assertSame() in Tests_Theme_wpThemeJson. 2023-03-06 17:44:15 +00:00
url Tests: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +00:00
user Tests: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +00:00
webfonts Themes: Remove local() from @font-face styles in _wp_theme_json_webfonts_handler(). 2023-02-13 14:31:06 +00:00
widgets HTTP API: Fix request header inconsistencies. 2023-02-03 13:33:18 +00:00
wp Tests: Move the tests for WP class methods to the wp directory. 2022-10-28 14:08:20 +00:00
xmlrpc Code Modernization: Use correct property in IXR_Message::tag_open(). 2023-01-20 01:34:41 +00:00
actions.php Code Modernization: Explicitly declare all properties in various tests. 2022-08-25 15:34:24 +00:00
adminbar.php Coding Standards: Always use parentheses when instantiating an object. 2022-11-29 15:49:49 +00:00
auth.php Login and Registration: Set correct default values in wp_signon(). 2023-02-09 01:29:42 +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 Editor: Add more details to template descriptions. 2023-03-09 16:29:13 +00:00
block-template.php Tests: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +00:00
cache.php Coding Standards: Always use parentheses when instantiating an object. 2022-11-29 15:49:49 +00:00
canonical.php Canonical: Protect against error for term not exists queries. 2022-11-10 02:59:56 +00:00
comment.php Build/Test Tooling: Use assertSame() in Tests_Comment::test_update_comment_from_privileged_user_by_privileged_user(). 2023-03-06 15:01:33 +00:00
cron.php Code Modernization: Rename parameters that use reserved keywords in phpunit/tests/cron.php. 2023-01-09 00:40:55 +00:00
db.php Database: Add %i placeholder support to $wpdb->prepare to escape table and column names, take 2. 2023-01-27 18:47:53 +00:00
dependencies.php Coding Standards: Add visibility to Tests_Dependencies::test_enqueue_before_register(). 2022-12-30 03:29:11 +00:00
file.php Code Modernization: Rename parameters that use reserved keywords in phpunit/tests/file.php. 2023-01-13 00:59:29 +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: Move some data providers in Tests_Functions next to the tests they are used in. 2023-03-06 13:08:03 +00:00
https-detection.php Tests: Bring some consistency to mocking HTTP requests in unit tests. 2023-01-05 10:21:19 +00:00
https-migration.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
kses.php Formatting: Add aspect-ratio tests for safecss_filter_attr(). 2023-02-28 02:50:28 +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 I18N: Introduce word_count_type property to WP_Locale. 2023-02-07 17:26:14 +00:00
media.php Tests: Improve Tests_Media::test_wp_generate_attachment_metadata_doesnt_generate_sizes_for_150_square_image(). 2023-03-06 16:27:23 +00:00
meta.php Coding Standards: Always use parentheses when instantiating an object. 2022-11-29 15:49:49 +00:00
post.php Coding Standards: Rename $post_ID variable to $post_id in various files. 2023-02-19 15:03:50 +00:00
query.php Coding Standards: Always use parentheses when instantiating an object. 2022-11-29 15:49:49 +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 Code Modernization: Rename parameters that use reserved keywords in phpunit/tests/rest-api.php. 2023-01-23 12:10:28 +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 Tests: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +00:00
shortcode.php Code Modernization: Rename parameters that use reserved keywords in phpunit/tests/shortcode.php. 2023-01-23 16:33:57 +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 Docs: Align spelling with American English. 2022-10-21 21:10:29 +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 Users: Correct the error code in wp_insert_user() when login matches an existing email. 2023-02-17 10:13:36 +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 Coding Standards: Add visibility to methods in tests/phpunit/tests/. 2022-11-29 12:32:37 +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;
	}
}