From c1b78cc2dd4128d79c7f17e4b790c0826d171477 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 30 Dec 2021 16:27:48 +0000 Subject: [PATCH] Tests: Add a unit test for the recommended MariaDB version in `readme.html`. Per the [https://mariadb.org/about/#maintenance-policy MariaDB maintenance policy], MariaDB releases are supported for 5 years from the first stable (GA) release. The test ensures that the recommended MariaDB version in `readme.html` is not older than 5 years. Follow-up to [31291], [35759], [52319], [52358], [52418], [meta11407], [52420], [52421]. Fixes #41490. git-svn-id: https://develop.svn.wordpress.org/trunk@52424 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/external-http/basic.php | 33 ++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/tests/external-http/basic.php b/tests/phpunit/tests/external-http/basic.php index f02e8fbcaf..b160e2b56f 100644 --- a/tests/phpunit/tests/external-http/basic.php +++ b/tests/phpunit/tests/external-http/basic.php @@ -19,10 +19,10 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { $response_body = $this->get_response_body( 'https://www.php.net/supported-versions.php' ); - preg_match_all( '#\s*\s*]*>\s*([0-9.]*)#s', $response_body, $phpmatches ); + preg_match_all( '#\s*\s*]*>\s*([0-9.]*)#s', $response_body, $php_matches ); // TODO: Enable this check once PHP 8.0 compatibility is achieved. - // $this->assertContains( $matches[1], $phpmatches[1], "readme.html's Recommended PHP version is too old. Remember to update the WordPress.org Requirements page, too." ); + // $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." ); } /** @@ -41,7 +41,7 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { $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, $mysqlmatches ); + 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. @@ -52,11 +52,36 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { * * TODO: Reduce this back to 5 years once MySQL 8.0 compatibility is achieved. */ - $mysql_eol = strtotime( $mysqlmatches[1] . ' +8 years' ); + $mysql_eol = strtotime( $mysql_matches[1] . ' +8 years' ); $this->assertLessThan( $mysql_eol, time(), "readme.html's Recommended MySQL version is too old. Remember to update the WordPress.org Requirements page, too." ); } + /** + * @covers ::wp_remote_get + * @covers ::wp_remote_retrieve_response_code + * @covers ::wp_remote_retrieve_body + */ + public function test_readme_mariadb_version() { + // This test is designed to only run on trunk/master. + $this->skipOnAutomatedBranches(); + + $readme = file_get_contents( ABSPATH . 'readme.html' ); + + preg_match( '#Recommendations.*MariaDB version ([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 = strtotime( $mariadb_matches[1] . ' +5 years' ); + + $this->assertLessThan( $mariadb_eol, time(), "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. *