wordpress-develop/tests/phpunit/tests
Bernie Reiter 973b4565ee HTML API: Stop processing HTML when encountering unsupported markup.
It was a design goal of the HTML Processor to abort processing its input document when encountering unsupported markup. Unfortunately there was no test for this and so-far, the HTML Processor has paused, but continued processing in these situations.

In this patch a new test ensures that the HTML Processor stops and refuses to move forward after encountering any unsupported markup. It also ensures that it doesn't report any current tag names since unsupported markup could imply that the read tag name is different than the parsed tag name.

Props dmsnell.
Fixes #59167.

git-svn-id: https://develop.svn.wordpress.org/trunk@56493 602fd350-edb4-49c9-b593-d223f7449a82
2023-08-30 15:37:33 +00:00
..
admin Fix coding standards for Tests_Admin_wpUserSearch 2023-08-25 03:42:48 +00:00
ajax Build/Test Tools: Update PHPUnit Polyfills to version 1.1.0. 2023-08-21 15:53:04 +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: Replace some accidental double setting up of tests with proper tearing down. 2023-08-27 20:32:16 +00:00
block-templates Editor: Remove need for template prefix in get_template_hierarchy. 2023-02-02 19:36:29 +00:00
blocks Build/Test Tools: Update PHPUnit Polyfills to version 1.1.0. 2023-08-21 15:53:04 +00:00
bookmark Tests: Use the function get_num_queries across all unit tests. 2023-05-11 10:05:51 +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: Always lazily load comment meta. 2023-05-11 12:25:51 +00:00
compat Tests: Use the data_ prefix for various data provider methods. 2023-03-19 12:03:30 +00:00
cron Cron API: Modify _get_cron_array() to always return an array. 2022-07-29 03:32:58 +00:00
customize Build/Test Tools: Update PHPUnit Polyfills to version 1.1.0. 2023-08-21 15:53:04 +00:00
date General: Increase the minimum supported version of PHP to 7.0.0. 2023-07-05 17:39:55 +00:00
db Tests: Use the data_ prefix for various data provider methods. 2023-03-19 12:03:30 +00:00
dependencies Script Loader: Improve test coverage for wp_print_scripts(). 2023-07-17 14:04:00 +00:00
diff Code Modernization: Deprecate dynamic properties in WP_Text_Diff_Renderer_Table magic methods. 2023-08-03 18:11:36 +00:00
editor Editor: Fix error handling of converting classic to block menus. 2023-08-21 17:49:09 +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: Use the data_ prefix for various data provider methods. 2023-03-19 12:03:30 +00:00
filesystem Filesystem API: Attempt to create directory in copy_dir(). 2023-06-19 01:58:25 +00:00
formatting Build/Tests: Tests_Formatting_MakeClickable should use data providors 2023-08-24 14:33:28 +00:00
functions Coding Standards: Always use parentheses for class instantiation. 2023-07-22 12:35:15 +00:00
general General: Replace some instances of "blog" with "site" in documentation, translator comments, and user-facing text strings. 2023-06-19 18:26:01 +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: Stop processing HTML when encountering unsupported markup. 2023-08-30 15:37:33 +00:00
http Coding Standards: Use correct case for class name in WP_Http tests. 2023-07-27 14:45:09 +00:00
image Media: Adjust PDF upload handling to remove non-opaque alpha channels from previews. 2023-07-19 22:33:47 +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: Ensure determine_locale() does not potentially return an empty string. 2023-06-23 16:01:08 +00:00
link Editor: fix post edit navigation link. 2023-06-27 06:00:59 +00:00
load General: Rename wp_in_development_mode() to wp_is_development_mode(). 2023-07-17 14:48:48 +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: Allow themes and plugins to pass HTML attributes to various Nav Walker outputs. 2023-06-27 15:25:00 +00:00
meta Tests: Use the data_ prefix for various data provider methods. 2023-03-19 12:03:30 +00:00
multisite Networks and Sites: Lazy load site meta. 2023-05-11 11:13:10 +00:00
oembed Embeds: Modernize wp-embed script with removal of obsolete IE10/IE11 code and support for WP<4.4. 2023-08-10 19:47:08 +00:00
option Options, Meta APIs: Introduce prime_options() to load multiple options with a single database request. 2023-08-24 14:40:01 +00:00
pluggable General: Use static on closures whenever $this is not used to avoid memory leaks. 2023-05-17 22:44:21 +00:00
pomo Tests: Use the data_ prefix for various data provider methods. 2023-03-19 12:03:30 +00:00
post Posts, Post Types: Reinstate missing sort_column options in get_pages(). 2023-08-29 22:03:25 +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 Build/Test Tools: Reset main query object after each test. 2023-07-11 13:31:03 +00:00
rest-api Tests: Correct uses of ReflectionProperty::setValue() for static properties. 2023-08-30 10:49:27 +00:00
rewrite Tests: Use the data_ prefix for various data provider methods. 2023-03-19 12:03:30 +00:00
sitemaps Tests: Use the data_ prefix for various data provider methods. 2023-03-19 12:03:30 +00:00
style-engine Editor: add box shadow support to blocks. 2023-06-26 23:42:16 +00:00
taxonomy Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
term Build/Test Tools: Update PHPUnit Polyfills to version 1.1.0. 2023-08-21 15:53:04 +00:00
theme Tests: Correct uses of ReflectionProperty::setValue() for static properties. 2023-08-30 10:49:27 +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 Build/Test Tools: Update PHPUnit Polyfills to version 1.1.0. 2023-08-21 15:53:04 +00:00
webfonts Tests: Fix tests introduced in [55612]. 2023-03-30 12:15:36 +00:00
widgets Media: Ensure that the image widget supports loading optimization attributes. 2023-07-06 16:31:02 +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 Coding Standards: Use instanceof keyword instead of the is_a() function. 2023-08-03 12:08:30 +00:00
adminbar.php Tests: Add tests to ensure the contribute Toolbar node is added when appropriate. 2023-07-13 12:39:42 +00:00
auth.php Login and Registration: Improve test coverage for sign on related functions 2023-08-24 19:12:33 +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: update template titles in browse mode. 2023-07-06 03:02:57 +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 Tools: Update PHPUnit Polyfills to version 1.1.0. 2023-08-21 15:53:04 +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: Remove support for the mysql extension. 2023-08-26 13:01:05 +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 Filesystem API: Ensure wp_tempnam() does not produce file names longer than 255 characters as this is the limit on most filesystems. 2023-07-10 20:31:35 +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 Docs: Corrections and improvements to docblocks for global styles, global settings, theme.json parsing, and shortcodes. 2023-05-03 18:46:44 +00:00
https-detection.php General: Remove Windows Live Writer manifest file. 2023-04-04 14:54:31 +00:00
https-migration.php Coding Standards: Use static closures when not using $this. 2021-08-26 12:57:08 +00:00
kses.php KSES: Add support for CSS repeat() function. 2023-06-20 02:29:18 +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 Media: Simplify logic in wp_get_loading_optimization_attributes(). 2023-08-02 17:56:16 +00:00
meta.php Coding Standards: Always use parentheses when instantiating an object. 2022-11-29 15:49:49 +00:00
post.php Build/Test Tools: Update PHPUnit Polyfills to version 1.1.0. 2023-08-21 15:53:04 +00:00
query.php Media: Conditionally skip lazy-loading on images before the loop to improve LCP performance. 2023-05-22 19:11:36 +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 Tests: Use the data_ prefix for various data provider methods. 2023-03-19 12:03:30 +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 Tests: Use the data_ prefix for various data provider methods. 2023-03-19 12:03:30 +00:00
taxonomy.php Build/Test Tools: Update PHPUnit Polyfills to version 1.1.0. 2023-08-21 15:53:04 +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 Login and Registration: Revert [55358] and [55360]. 2023-03-23 13:52:25 +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;
	}
}