mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
The Template and Template Part REST API controllers have unique characteristics compared to other post type REST API controllers. They do not rely on integer IDs to reference objects; instead, they use a combination of the theme name and slug of the template, like 'twentytwentyfour//home.' Consequently, when the post types template and template part were introduced in [52062], it led to the registration of REST API endpoints for autosaves and revisions with invalid URL structures. In this commit, we introduce new functionality to enable custom autosave and revisions endpoints to be registered at the post type level. Similar to the 'rest_controller_class' parameter, developers can now define 'revisions_rest_controller' and 'autosave_rest_controller.' This empowers developers to create custom controllers for these functionalities. Additionally, we introduce a 'late_route_registration' parameter, which proves helpful when dealing with custom URL patterns and regex pattern matching issues. This commit registers new classes for template and template part autosave and revisions controllers, differentiating them from standard controllers in the following ways: * The response shape now matches that of the template controller. * Permission checks align with the template controller. * A custom URL pattern is introduced to support slug-based identification of templates. Furthermore, we've updated the utility function '_build_block_template_result_from_post' to support passing revision post objects. This enhancement ensures compatibility with the custom revisions controller. Props spacedmonkey, revgeorge, andraganescu, hellofromTonya, antonvlasenko, kadamwhite, ironprogrammer, costdev, mukesh27, timothyblynjacobs, adamsilverstein. Fixes 56922. git-svn-id: https://develop.svn.wordpress.org/trunk@56819 602fd350-edb4-49c9-b593-d223f7449a82 |
||
|---|---|---|
| .. | ||
| admin | ||
| ajax | ||
| attachment | ||
| block-supports | ||
| block-templates | ||
| blocks | ||
| bookmark | ||
| canonical | ||
| category | ||
| comment | ||
| compat | ||
| cron | ||
| customize | ||
| date | ||
| db | ||
| dependencies | ||
| diff | ||
| editor | ||
| error-protection | ||
| feed | ||
| filesystem | ||
| fonts/font-face | ||
| formatting | ||
| functions | ||
| general | ||
| hooks | ||
| html-api | ||
| http | ||
| image | ||
| import | ||
| includes | ||
| kses | ||
| l10n | ||
| link | ||
| load | ||
| media | ||
| menu | ||
| meta | ||
| multisite | ||
| oembed | ||
| option | ||
| pluggable | ||
| pomo | ||
| post | ||
| privacy | ||
| query | ||
| rest-api | ||
| rewrite | ||
| sitemaps | ||
| style-engine | ||
| taxonomy | ||
| term | ||
| theme | ||
| url | ||
| user | ||
| widgets | ||
| wp | ||
| xmlrpc | ||
| actions.php | ||
| adminbar.php | ||
| auth.php | ||
| avatar.php | ||
| basic.php | ||
| block-template-utils.php | ||
| block-template.php | ||
| cache.php | ||
| canonical.php | ||
| comment.php | ||
| cron.php | ||
| db.php | ||
| dependencies.php | ||
| file.php | ||
| filters.php | ||
| functions.php | ||
| https-detection.php | ||
| https-migration.php | ||
| kses.php | ||
| l10n.php | ||
| link.php | ||
| locale.php | ||
| media.php | ||
| meta.php | ||
| post.php | ||
| query.php | ||
| readme.php | ||
| rest-api.php | ||
| rewrite.php | ||
| robots.php | ||
| shortcode.php | ||
| taxonomy.php | ||
| template.php | ||
| term.php | ||
| theme-previews.php | ||
| theme.php | ||
| upload.php | ||
| url.php | ||
| user.php | ||
| utils.php | ||
| vars.php | ||
| walker.php | ||
| widgets.php | ||
<?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;
}
}