Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit page caching and object caching tests for Site Health if on WP>=6.1 #7645

Merged
merged 7 commits into from
Oct 25, 2023
64 changes: 44 additions & 20 deletions src/Admin/SiteHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public function register() {
add_filter( 'site_status_test_result', [ $this, 'modify_test_result' ] );
add_filter( 'site_status_test_php_modules', [ $this, 'add_extensions' ] );

if ( version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) && has_filter( 'amp_page_cache_good_response_time_threshold' ) ) {
add_filter( 'site_status_good_response_time_threshold', 'get_good_response_time_threshold' );
thelovekesh marked this conversation as resolved.
Show resolved Hide resolved
}

add_action( 'admin_print_styles-tools_page_health-check', [ $this, 'add_styles' ] );
add_action( 'admin_print_styles-site-health.php', [ $this, 'add_styles' ] );
}
Expand Down Expand Up @@ -180,17 +184,13 @@ public function register_async_test_endpoints() {
* @return array $tests The filtered tests, with tests for AMP.
*/
public function add_tests( $tests ) {
$tests['direct']['amp_persistent_object_cache'] = [
'label' => esc_html__( 'Persistent object cache', 'amp' ),
'test' => [ $this, 'persistent_object_cache' ],
];

if ( ! amp_is_canonical() && QueryVar::AMP !== amp_get_slug() ) {
$tests['direct']['amp_slug_definition_timing'] = [
'label' => esc_html__( 'AMP slug (query var) definition timing', 'amp' ),
'test' => [ $this, 'slug_definition_timing' ],
];
}

$tests['direct']['amp_curl_multi_functions'] = [
'label' => esc_html__( 'cURL multi functions', 'amp' ),
'test' => [ $this, 'curl_multi_functions' ],
Expand All @@ -207,7 +207,8 @@ public function add_tests( $tests ) {
'label' => esc_html__( 'Transient caching of stylesheets', 'amp' ),
'test' => [ $this, 'css_transient_caching' ],
];
$tests['direct']['amp_xdebug_extension'] = [

$tests['direct']['amp_xdebug_extension'] = [
'label' => esc_html__( 'Xdebug extension', 'amp' ),
'test' => [ $this, 'xdebug_extension' ],
];
Expand All @@ -217,13 +218,21 @@ public function add_tests( $tests ) {
'test' => [ $this, 'publisher_logo' ],
];

if ( $this->supports_async_rest_tests( $tests ) ) {
$tests['async'][ self::TEST_PAGE_CACHING ] = [
'label' => esc_html__( 'Page caching', 'amp' ),
'test' => rest_url( self::REST_API_NAMESPACE . self::REST_API_PAGE_CACHE_ENDPOINT ),
'has_rest' => true,
'async_direct_test' => [ $this, 'page_cache' ],
// Only run page and object cache tests for WP < 6.1, since it has been a part of core now.
if ( version_compare( get_bloginfo( 'version' ), '6.1', '<' ) ) {
$tests['direct']['amp_persistent_object_cache'] = [
'label' => esc_html__( 'Persistent object cache', 'amp' ),
'test' => [ $this, 'persistent_object_cache' ],
];

if ( $this->supports_async_rest_tests( $tests ) ) {
$tests['async'][ self::TEST_PAGE_CACHING ] = [
'label' => esc_html__( 'Page caching', 'amp' ),
'test' => rest_url( self::REST_API_NAMESPACE . self::REST_API_PAGE_CACHE_ENDPOINT ),
'has_rest' => true,
'async_direct_test' => [ $this, 'page_cache' ],
];
}
}

return $tests;
Expand Down Expand Up @@ -340,16 +349,31 @@ static function ( $available_service ) {
*
* @since 2.2.1
*
* @param int $threshold Threshold in milliseconds.
*
* @return int Threshold.
*/
public function get_good_response_time_threshold() {
/**
* Filters the threshold below which a response time is considered good.
*
* @since 2.2.1
* @param int $threshold Threshold in milliseconds.
*/
return (int) apply_filters( 'amp_page_cache_good_response_time_threshold', 600 );
public function get_good_response_time_threshold( $threshold = 600 ) {
if ( version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) ) {
/** This filter is documented in src/Admin/SiteHealth.php */
return (int) apply_filters_deprecated(
'amp_page_cache_good_response_time_threshold',
[ $threshold ],
'AMP 2.4.3',
'site_status_good_response_time_threshold'
);
} else {
/**
* Filters the threshold below which a response time is considered good.
*
* @since 2.2.1
*
* @deprecated 2.4.3 Use `site_status_good_response_time_threshold` instead.
*
* @param int $threshold Threshold in milliseconds.
*/
return (int) apply_filters( 'amp_page_cache_good_response_time_threshold', 600 );
}
}

/**
Expand Down
21 changes: 16 additions & 5 deletions tests/php/src/Admin/SiteHealthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,17 @@ public function test_register_async_test_endpoints() {
*/
public function test_add_tests() {
$tests = $this->instance->add_tests( [] );

$this->assertArrayHasKey( 'direct', $tests );
$this->assertArrayHasKey( 'amp_persistent_object_cache', $tests['direct'] );

if ( version_compare( get_bloginfo( 'version' ), '5.6', '>=' ) ) {
$this->assertArrayHasKey( 'amp_page_cache', $tests['async'] );
} elseif ( array_key_exists( 'async', $tests ) ) {
$this->assertArrayNotHasKey( 'amp_page_cache', $tests['async'] );
if ( ! version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) ) {
$this->assertArrayHasKey( 'amp_persistent_object_cache', $tests['direct'] );

if ( version_compare( get_bloginfo( 'version' ), '5.6', '>=' ) ) {
$this->assertArrayHasKey( 'amp_page_cache', $tests['async'] );
} elseif ( array_key_exists( 'async', $tests ) ) {
$this->assertArrayNotHasKey( 'amp_page_cache', $tests['async'] );
}
}

$this->assertArrayHasKey( 'amp_curl_multi_functions', $tests['direct'] );
Expand Down Expand Up @@ -698,6 +702,10 @@ public function test_add_extensions() {
* @covers ::get_good_response_time_threshold()
*/
public function test_get_good_response_time_threshold() {
if ( version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) ) {
$this->markTestSkipped( '`amp_page_cache_good_response_time_threshold` is deprecated in WordPress 6.1 and above.' );
}

$this->assertSame( 600, $this->instance->get_good_response_time_threshold() );

add_filter(
Expand Down Expand Up @@ -918,6 +926,9 @@ public function get_page_cache_data() {
* @covers ::check_for_page_caching()
*/
public function test_page_cache( $responses, $expected_status, $expected_label, $good_basic_auth = null, $delay_the_response = false ) {
if ( version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) ) {
$this->markTestSkipped( 'AMP plugin omits page and object caching tests for Site Health if on WP>=6.1 ' );
}

$badge_color = [
'critical' => 'red',
Expand Down
Loading