Skip to content

Commit 0d97691

Browse files
committed
Improve strings in site health test
1 parent 726e112 commit 0d97691

File tree

2 files changed

+66
-26
lines changed

2 files changed

+66
-26
lines changed

src/Admin/SiteHealth.php

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,16 @@ static function ( $available_service ) {
338338
public function page_cache() {
339339
$page_cache_detail = $this->get_page_cache_detail();
340340

341-
$badge_color = 'red';
342-
$status = is_wp_error( $page_cache_detail ) ? 'critical' : $page_cache_detail['status'];
343-
$label = __( 'Page caching is not detected and response time is slow.', 'amp' );
344-
345341
$description = '<p>' . esc_html__( 'The AMP plugin performs at its best when page caching is enabled. This is because the additional optimizations performed require additional server processing time, and page caching ensures that responses are served quickly.', 'amp' ) . '</p>';
346342

347343
/* translators: List of page cache headers. */
348-
$description .= '<p>' . sprintf( __( 'Page caching is detected by looking for an active page caching plugin, making three requests to the homepage and looking for HTTP response headers like: %s.', 'amp' ), '<code>' . implode( '</code>, <code>', array_keys( self::get_page_cache_headers() ) ) . '</code>' );
344+
$description .= '<p>' . sprintf( __( 'Page caching is detected by looking for an active page caching plugin as well as making three requests to the homepage and looking for one or more of the following HTTP client caching response headers: %s.', 'amp' ), '<code>' . implode( '</code>, <code>', array_keys( self::get_page_cache_headers() ) ) . '</code>' );
349345

350346
if ( is_wp_error( $page_cache_detail ) ) {
347+
$badge_color = 'red';
348+
$status = 'critical';
349+
$label = __( 'Unable to detect the presence of page caching', 'amp' );
350+
351351
$error_info = sprintf(
352352
/* translators: 1 is error message, 2 is error code */
353353
__( 'Unable to detect page caching due to possible loopback request problem. Please verify that the loopback request test is passing. Error: %1$s (Code: %2$s)', 'amp' ),
@@ -356,41 +356,65 @@ public function page_cache() {
356356
);
357357

358358
$description = "<p>$error_info</p>" . $description;
359-
} elseif ( 'recommended' === $status ) {
359+
} elseif ( 'recommended' === $page_cache_detail['status'] ) {
360360
$badge_color = 'orange';
361+
$status = $page_cache_detail['status'];
361362
$label = __( 'Page caching is not detected, but your response time is OK', 'amp' );
362-
} elseif ( 'good' === $status ) {
363+
} elseif ( 'good' === $page_cache_detail['status'] ) {
363364
$badge_color = 'green';
365+
$status = $page_cache_detail['status'];
364366
$label = __( 'Page caching is detected', 'amp' );
367+
} else {
368+
$badge_color = 'red';
369+
$status = $page_cache_detail['status'];
370+
$label = __( 'Page caching is not detected and response time is slow', 'amp' );
365371
}
366372

367373
if ( ! is_wp_error( $page_cache_detail ) ) {
368374
$page_cache_test_summary = [];
369375

376+
// @todo This should only be shown if no client page caching headers are found.
370377
if ( $page_cache_detail['advanced_cache_present'] ) {
371-
$page_cache_test_summary[] = '<span class="dashicons dashicons-yes-alt text-success"></span>' . __( 'Page caching plugin is available.', 'amp' );
378+
$page_cache_test_summary[] = '<span class="dashicons dashicons-yes-alt text-success"></span> ' . __( 'A page caching plugin was detected.', 'amp' );
372379
} else {
373-
$page_cache_test_summary[] = '<span class="dashicons dashicons-warning text-warning"></span>' . __( 'Page caching plugin is not available.', 'amp' );
380+
$page_cache_test_summary[] = '<span class="dashicons dashicons-warning text-warning"></span> ' . __( 'A page caching plugin was not detected.', 'amp' );
374381
}
375382

376383
if ( empty( $page_cache_detail['response_time'] ) ) {
377-
$page_cache_test_summary[] = '<span class="dashicons dashicons-dismiss text-error"></span>' . __( 'We couldn\'t able to find a response time. Please make sure loopback requests are allowed.', 'amp' );
384+
$page_cache_test_summary[] = '<span class="dashicons dashicons-dismiss text-error"></span> ' . __( 'Server response time could not be determined. Verify that loopback requests are working.', 'amp' );
378385
} else {
379386

387+
// @todo The 600 millisecond threshold should be filterable.
380388
if ( $page_cache_detail['response_time'] < 600 ) {
381-
$page_cache_test_summary[] = '<span class="dashicons dashicons-yes-alt text-success"></span>' . __( 'Site response time is less than 600 microseconds.', 'amp' );
389+
$page_cache_test_summary[] = '<span class="dashicons dashicons-yes-alt text-success"></span> ' . sprintf(
390+
/* translators: %d is the response time in milliseconds */
391+
__( 'Median server response time was %d milliseconds. This is less than the 600 millisecond threshold.', 'amp' ),
392+
$page_cache_detail['response_time']
393+
);
382394
} else {
383-
$page_cache_test_summary[] = '<span class="dashicons dashicons-warning text-warning"></span>' . __( 'Site response time is more than 600 microseconds, which is not ideal.', 'amp' );
395+
$page_cache_test_summary[] = '<span class="dashicons dashicons-warning text-warning"></span> ' . sprintf(
396+
/* translators: %d is the response time in milliseconds */
397+
__( 'Median server response time was %d milliseconds. It should be less than 600 milliseconds.', 'amp' ),
398+
$page_cache_detail['response_time'],
399+
$page_cache_detail['response_time']
400+
);
384401
}
385402

386403
if ( empty( $page_cache_detail['headers'] ) ) {
387-
$page_cache_test_summary[] = '<span class="dashicons dashicons-warning text-warning"></span>' . __( 'We could not find any page cache headers in a response.', 'amp' );
404+
$page_cache_test_summary[] = '<span class="dashicons dashicons-warning text-warning"></span> ' . __( 'No client caching response headers were detected in response.', 'amp' );
388405
} else {
389-
$page_cache_test_summary[] = '<span class="dashicons dashicons-yes-alt text-success"></span>' . sprintf(
390-
/* translators: List of detected page cache headers. */
391-
__( 'These are headers we found in a response. %s', 'amp' ),
392-
'<code>' . implode( '</code>, <code>', $page_cache_detail['headers'] ) . '</code>'
393-
);
406+
$page_cache_test_summary[] = '<span class="dashicons dashicons-yes-alt text-success"></span> ' .
407+
sprintf(
408+
/* translators: List of detected page cache headers. */
409+
_n(
410+
'There was %d client caching response header detected:',
411+
'There were %d client caching response headers detected:',
412+
count( $page_cache_detail['headers'] ),
413+
'amp'
414+
),
415+
count( $page_cache_detail['headers'] )
416+
) .
417+
'<code>' . implode( '</code>, <code>', $page_cache_detail['headers'] ) . '</code>';
394418
}
395419
}
396420

tests/php/src/Admin/SiteHealthTest.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,28 +697,36 @@ public function test_add_extensions() {
697697
* @return array[]
698698
*/
699699
public function get_page_cache_data() {
700+
$recommended_label = 'Page caching is not detected, but your response time is OK';
701+
$good_label = 'Page caching is detected';
702+
$critical_label = 'Page caching is not detected and response time is slow';
703+
$error_label = 'Unable to detect the presence of page caching';
700704

701705
return [
702706
'basic-auth-fail' => [
703707
'responses' => [
704708
'unauthorized',
705709
],
706710
'expected_status' => 'critical',
711+
'expected_label' => $error_label,
707712
'good_basic_auth' => false,
708713
],
709714
'no-cache-control' => [
710715
'responses' => array_fill( 0, 3, [] ),
711716
'expected_status' => 'critical',
717+
'expected_label' => $critical_label,
712718
'good_basic_auth' => null,
713719
'delay_the_response' => true,
714720
],
715721
'no-cache' => [
716722
'responses' => array_fill( 0, 3, [ 'cache-control' => 'no-cache' ] ),
717723
'expected_status' => 'recommended',
724+
'expected_label' => $recommended_label,
718725
],
719726
'no-cache-with-delayed-response' => [
720727
'responses' => array_fill( 0, 3, [ 'cache-control' => 'no-cache' ] ),
721728
'expected_status' => 'critical',
729+
'expected_label' => $critical_label,
722730
'good_basic_auth' => null,
723731
'delay_the_response' => true,
724732
],
@@ -729,6 +737,7 @@ public function get_page_cache_data() {
729737
[ 'age' => '1345' ]
730738
),
731739
'expected_status' => 'good',
740+
'expected_label' => $good_label,
732741
],
733742
'cache-control-max-age' => [
734743
'responses' => array_fill(
@@ -737,6 +746,7 @@ public function get_page_cache_data() {
737746
[ 'cache-control' => 'public; max-age=600' ]
738747
),
739748
'expected_status' => 'good',
749+
'expected_label' => $good_label,
740750
],
741751
'cache-control-max-age-after-2-requests' => [
742752
'responses' => [
@@ -745,6 +755,7 @@ public function get_page_cache_data() {
745755
[ 'cache-control' => 'public; max-age=600' ],
746756
],
747757
'expected_status' => 'good',
758+
'expected_label' => $good_label,
748759
],
749760
'cache-control-with-future-expires' => [
750761
'responses' => array_fill(
@@ -753,6 +764,7 @@ public function get_page_cache_data() {
753764
[ 'expires' => gmdate( 'r', time() + MINUTE_IN_SECONDS * 10 ) ]
754765
),
755766
'expected_status' => 'good',
767+
'expected_label' => $good_label,
756768
],
757769
'cache-control-with-past-expires' => [
758770
'responses' => array_fill(
@@ -761,6 +773,7 @@ public function get_page_cache_data() {
761773
[ 'expires' => gmdate( 'r', time() - MINUTE_IN_SECONDS * 10 ) ]
762774
),
763775
'expected_status' => 'critical',
776+
'expected_label' => $critical_label,
764777
'good_basic_auth' => null,
765778
'delay_the_response' => true,
766779
],
@@ -771,6 +784,7 @@ public function get_page_cache_data() {
771784
[ 'cache-control' => 'public; max-age=600' ]
772785
),
773786
'expected_status' => 'good',
787+
'expected_label' => $good_label,
774788
'good_basic_auth' => true,
775789
],
776790
'cf-cache-status' => [
@@ -780,6 +794,7 @@ public function get_page_cache_data() {
780794
[ 'cf-cache-status' => 'HIT: 1' ]
781795
),
782796
'expected_status' => 'good',
797+
'expected_label' => $good_label,
783798
],
784799
'cf-cache-status-without-header-and-delay' => [
785800
'responses' => array_fill(
@@ -788,6 +803,7 @@ public function get_page_cache_data() {
788803
[ 'cf-cache-status' => 'MISS' ]
789804
),
790805
'expected_status' => 'recommended',
806+
'expected_label' => $recommended_label,
791807
'good_basic_auth' => null,
792808
'delay_the_response' => false,
793809
],
@@ -798,6 +814,7 @@ public function get_page_cache_data() {
798814
[ 'cf-cache-status' => 'MISS' ]
799815
),
800816
'expected_status' => 'critical',
817+
'expected_label' => $critical_label,
801818
'good_basic_auth' => null,
802819
'delay_the_response' => true,
803820
],
@@ -808,6 +825,7 @@ public function get_page_cache_data() {
808825
[ 'x-cache-enabled' => 'true' ]
809826
),
810827
'expected_status' => 'good',
828+
'expected_label' => $good_label,
811829
],
812830
'x-cache-enabled-with-delay' => [
813831
'responses' => array_fill(
@@ -816,6 +834,7 @@ public function get_page_cache_data() {
816834
[ 'x-cache-enabled' => 'false' ]
817835
),
818836
'expected_status' => 'critical',
837+
'expected_label' => $critical_label,
819838
'good_basic_auth' => null,
820839
'delay_the_response' => true,
821840
],
@@ -826,6 +845,7 @@ public function get_page_cache_data() {
826845
[ 'x-cache-disabled' => 'off' ]
827846
),
828847
'expected_status' => 'good',
848+
'expected_label' => $good_label,
829849
],
830850
'cf-apo-via' => [
831851
'responses' => array_fill(
@@ -834,6 +854,7 @@ public function get_page_cache_data() {
834854
[ 'cf-apo-via' => 'tcache' ]
835855
),
836856
'expected_status' => 'good',
857+
'expected_label' => $good_label,
837858
],
838859
'cf-edge-cache' => [
839860
'responses' => array_fill(
@@ -842,6 +863,7 @@ public function get_page_cache_data() {
842863
[ 'cf-edge-cache' => 'cache' ]
843864
),
844865
'expected_status' => 'good',
866+
'expected_label' => $good_label,
845867
],
846868
];
847869
}
@@ -852,28 +874,22 @@ public function get_page_cache_data() {
852874
* @covers ::get_page_cache_headers()
853875
* @covers ::check_for_page_caching()
854876
*/
855-
public function test_page_cache( $responses, $expected_status, $good_basic_auth = null, $delay_the_response = false ) {
877+
public function test_page_cache( $responses, $expected_status, $expected_label, $good_basic_auth = null, $delay_the_response = false ) {
856878

857879
$badge_color = [
858880
'critical' => 'red',
859881
'recommended' => 'orange',
860882
'good' => 'green',
861883
];
862884

863-
$labels = [
864-
'critical' => 'Page caching is not detected and response time is slow.',
865-
'recommended' => 'Page caching is not detected, but your response time is OK',
866-
'good' => 'Page caching is detected',
867-
];
868-
869885
$expected_props = [
870886
'badge' => [
871887
'label' => 'AMP',
872888
'color' => $badge_color[ $expected_status ],
873889
],
874890
'test' => 'amp_page_cache',
875891
'status' => $expected_status,
876-
'label' => $labels[ $expected_status ],
892+
'label' => $expected_label,
877893
];
878894

879895
if ( null !== $good_basic_auth ) {

0 commit comments

Comments
 (0)