<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[54075] trunk/tests/phpunit/tests: Tests: Move Site Health unit test class to `phpunit/tests/admin/`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/54075">54075</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/54075","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-09-05 22:25:54 +0000 (Mon, 05 Sep 2022)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Tests: Move Site Health unit test class to `phpunit/tests/admin/`.

Includes:
* Renaming the test class per the [https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization naming conventions].
* Creating a `WP_Site_Health` instance in the `set_up()` method, instead of leaving that to each individual test.

This brings some consistency with the tests for other admin classes, e.g. `WP_Community_Events`.

Follow-up to <a href="https://core.trac.wordpress.org/changeset/45802">[45802]</a>, <a href="https://core.trac.wordpress.org/changeset/51639">[51639]</a>.

See <a href="https://core.trac.wordpress.org/ticket/55652">#55652</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsadminwpCommunityEventsphp">trunk/tests/phpunit/tests/admin/wpCommunityEvents.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsadminwpSiteHealthphp">trunk/tests/phpunit/tests/admin/wpSiteHealth.php</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestssitehealthphp">trunk/tests/phpunit/tests/site-health.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestsadminwpCommunityEventsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/admin/wpCommunityEvents.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/wpCommunityEvents.php     2022-09-05 21:14:38 UTC (rev 54074)
+++ trunk/tests/phpunit/tests/admin/wpCommunityEvents.php       2022-09-05 22:25:54 UTC (rev 54075)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -16,10 +16,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 4.8.0
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> class Tests_Admin_wpCommunityEvents extends WP_UnitTestCase {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">         /**
</span><span class="cx" style="display: block; padding: 0 10px">         * An instance of the class to test.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @access private
</del><span class="cx" style="display: block; padding: 0 10px">          * @since 4.8.0
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @var WP_Community_Events
</span></span></pre></div>
<a id="trunktestsphpunittestsadminwpSiteHealthphpfromrev54074trunktestsphpunittestssitehealthphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/admin/wpSiteHealth.php (from rev 54074, trunk/tests/phpunit/tests/site-health.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/wpSiteHealth.php                          (rev 0)
+++ trunk/tests/phpunit/tests/admin/wpSiteHealth.php    2022-09-05 22:25:54 UTC (rev 54075)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,507 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group site-health
+ *
+ * @coversDefaultClass WP_Site_Health
+ */
+class Tests_Admin_wpSiteHealth extends WP_UnitTestCase {
+
+       /**
+        * An instance of the class to test.
+        *
+        * @since 6.1.0
+        *
+        * @var WP_Site_Health
+        */
+       private $instance;
+
+       public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+               // Include the `WP_Site_Health` file.
+               require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
+       }
+
+       /**
+        * Performs setup tasks for every test.
+        *
+        * @since 6.1.0
+        */
+       public function set_up() {
+               parent::set_up();
+
+               $this->instance = new WP_Site_Health();
+       }
+
+       /**
+        * @ticket 55791
+        * @covers ::prepare_sql_data()
+        * @covers ::get_test_sql_server()
+        */
+       public function test_mysql_recommended_version_matches_readme_html() {
+               // This test is designed to only run on trunk.
+               $this->skipOnAutomatedBranches();
+
+               $this->instance->get_test_sql_server();
+
+               $reflection          = new ReflectionClass( $this->instance );
+               $reflection_property = $reflection->getProperty( 'mysql_recommended_version' );
+               $reflection_property->setAccessible( true );
+
+               $readme = file_get_contents( ABSPATH . 'readme.html' );
+
+               preg_match( '#Recommendations.*MySQL</a> version <strong>([0-9.]*)#s', $readme, $matches );
+
+               $this->assertSame( $matches[1], $reflection_property->getValue( $this->instance ) );
+       }
+
+       /**
+        * @ticket 55791
+        * @covers ::prepare_sql_data()
+        * @covers ::get_test_sql_server()
+        */
+       public function test_mariadb_recommended_version_matches_readme_html() {
+               // This test is designed to only run on trunk.
+               $this->skipOnAutomatedBranches();
+
+               $this->instance->get_test_sql_server();
+
+               $reflection          = new ReflectionClass( $this->instance );
+               $reflection_property = $reflection->getProperty( 'mariadb_recommended_version' );
+               $reflection_property->setAccessible( true );
+
+               $readme = file_get_contents( ABSPATH . 'readme.html' );
+
+               preg_match( '#Recommendations.*MariaDB</a> version <strong>([0-9.]*)#s', $readme, $matches );
+
+               $this->assertSame( $matches[1], $reflection_property->getValue( $this->instance ) );
+       }
+
+       /**
+        * Ensure Site Health reports correctly cron job reports.
+        *
+        * @ticket 47223
+        */
+       public function test_cron_health_checks_critical() {
+               // Clear the cron array.
+               _set_cron_array( array() );
+
+               $cron_health = $this->instance->get_test_scheduled_events();
+
+               $this->assertSame( 'critical', $cron_health['status'] );
+               $this->assertSame( __( 'It was not possible to check your scheduled events' ), $cron_health['label'] );
+               $this->assertWPError( $this->instance->has_late_cron() );
+               $this->assertWPError( $this->instance->has_missed_cron() );
+       }
+
+       /**
+        * Ensure Site Health reports correctly cron job reports.
+        *
+        * @dataProvider data_cron_health_checks
+        * @ticket 47223
+        */
+       public function test_cron_health_checks( $times, $expected_status, $expected_label, $expected_late, $expected_missed ) {
+               /*
+                * Clear the cron array.
+                *
+                * The core jobs may register as late/missed in the test suite as they
+                * are not run. Clearing the array ensures the site health tests are only
+                * reported based on the jobs set in the test.
+                */
+               _set_cron_array( array() );
+
+               $times = (array) $times;
+               foreach ( $times as $job => $time ) {
+                       $timestamp = strtotime( $time );
+                       wp_schedule_event( $timestamp, 'daily', __FUNCTION__ . "_{$job}" );
+               }
+
+               $cron_health = $this->instance->get_test_scheduled_events();
+
+               $this->assertSame( $expected_status, $cron_health['status'] );
+               $this->assertSame( $expected_label, $cron_health['label'] );
+               $this->assertSame( $expected_late, $this->instance->has_late_cron() );
+               $this->assertSame( $expected_missed, $this->instance->has_missed_cron() );
+       }
+
+       /**
+        * Data provider for Site Health cron reports.
+        *
+        * The test suite runs with `DISABLE_WP_CRON === true` so the
+        * missed and late tests need to account for the extended periods
+        * allowed for with this flag enabled.
+        *
+        * 1. string|array Times to schedule (run through strtotime())
+        * 2. string       Expected status
+        * 3. string       Expected label
+        * 4. bool         Expected outcome has_late_cron()
+        * 5. bool         Expected outcome has_missed_cron()
+        */
+       public function data_cron_health_checks() {
+               return array(
+                       array(
+                               '+5 minutes',
+                               'good',
+                               __( 'Scheduled events are running' ),
+                               false,
+                               false,
+                       ),
+                       array(
+                               '-50 minutes',
+                               'recommended',
+                               __( 'A scheduled event is late' ),
+                               true,
+                               false,
+                       ),
+                       array(
+                               '-500 minutes',
+                               'recommended',
+                               __( 'A scheduled event has failed' ),
+                               false,
+                               true,
+                       ),
+                       array(
+                               array(
+                                       '-50 minutes',
+                                       '-500 minutes',
+                               ),
+                               'recommended',
+                               __( 'A scheduled event has failed' ),
+                               true,
+                               true,
+                       ),
+               );
+       }
+
+       /**
+        * @ticket 56041
+        * @dataProvider data_get_page_cache
+        * @covers ::get_test_page_cache()
+        * @covers ::get_page_cache_detail()
+        * @covers ::get_page_cache_headers()
+        * @covers ::check_for_page_caching()
+        */
+       public function test_get_page_cache( $responses, $expected_status, $expected_label, $good_basic_auth = null, $delay_the_response = false ) {
+               $expected_props = array(
+                       'badge'  => array(
+                               'label' => __( 'Performance' ),
+                               'color' => 'blue',
+                       ),
+                       'test'   => 'page_cache',
+                       'status' => $expected_status,
+                       'label'  => $expected_label,
+               );
+
+               if ( null !== $good_basic_auth ) {
+                       $_SERVER['PHP_AUTH_USER'] = 'admin';
+                       $_SERVER['PHP_AUTH_PW']   = 'password';
+               }
+
+               $threshold = 10;
+               if ( $delay_the_response ) {
+                       add_filter(
+                               'site_status_good_response_time_threshold',
+                               static function () use ( $threshold ) {
+                                       return $threshold;
+                               }
+                       );
+               }
+
+               add_filter(
+                       'pre_http_request',
+                       function ( $r, $parsed_args ) use ( &$responses, &$is_unauthorized, $good_basic_auth, $delay_the_response, $threshold ) {
+
+                               $expected_response = array_shift( $responses );
+
+                               if ( $delay_the_response ) {
+                                       usleep( $threshold * 1000 + 1 );
+                               }
+
+                               if ( 'unauthorized' === $expected_response ) {
+                                       $is_unauthorized = true;
+
+                                       return array(
+                                               'response' => array(
+                                                       'code'    => 401,
+                                                       'message' => 'Unauthorized',
+                                               ),
+                                       );
+                               }
+
+                               if ( null !== $good_basic_auth ) {
+                                       $this->assertArrayHasKey(
+                                               'Authorization',
+                                               $parsed_args['headers']
+                                       );
+                               }
+
+                               $this->assertIsArray( $expected_response );
+
+                               return array(
+                                       'headers'  => $expected_response,
+                                       'response' => array(
+                                               'code'    => 200,
+                                               'message' => 'OK',
+                                       ),
+                               );
+                       },
+                       20,
+                       2
+               );
+
+               $actual = $this->instance->get_test_page_cache();
+               $this->assertArrayHasKey( 'description', $actual );
+               $this->assertArrayHasKey( 'actions', $actual );
+
+               if ( $is_unauthorized ) {
+                       $this->assertStringContainsString( 'Unauthorized', $actual['description'] );
+               } else {
+                       $this->assertStringNotContainsString( 'Unauthorized', $actual['description'] );
+               }
+
+               $this->assertSame(
+                       $expected_props,
+                       wp_array_slice_assoc( $actual, array_keys( $expected_props ) )
+               );
+       }
+
+       /**
+        * Data provider for test_get_page_cache().
+        *
+        * Gets response data for WP_Site_Health::get_test_page_cache().
+        *
+        * @ticket 56041
+        *
+        * @return array[]
+        */
+       public function data_get_page_cache() {
+               $recommended_label = 'Page cache is not detected but the server response time is OK';
+               $good_label        = 'Page cache is detected and the server response time is good';
+               $critical_label    = 'Page cache is not detected and the server response time is slow';
+               $error_label       = 'Unable to detect the presence of page cache';
+
+               return array(
+                       'basic-auth-fail'                        => array(
+                               'responses'       => array(
+                                       'unauthorized',
+                               ),
+                               'expected_status' => 'recommended',
+                               'expected_label'  => $error_label,
+                               'good_basic_auth' => false,
+                       ),
+                       'no-cache-control'                       => array(
+                               'responses'          => array_fill( 0, 3, array() ),
+                               'expected_status'    => 'critical',
+                               'expected_label'     => $critical_label,
+                               'good_basic_auth'    => null,
+                               'delay_the_response' => true,
+                       ),
+                       'no-cache'                               => array(
+                               'responses'       => array_fill( 0, 3, array( 'cache-control' => 'no-cache' ) ),
+                               'expected_status' => 'recommended',
+                               'expected_label'  => $recommended_label,
+                       ),
+                       'no-cache-arrays'                        => array(
+                               'responses'       => array_fill(
+                                       0,
+                                       3,
+                                       array(
+                                               'cache-control' => array(
+                                                       'no-cache',
+                                                       'no-store',
+                                               ),
+                                       )
+                               ),
+                               'expected_status' => 'recommended',
+                               'expected_label'  => $recommended_label,
+                       ),
+                       'no-cache-with-delayed-response'         => array(
+                               'responses'          => array_fill( 0, 3, array( 'cache-control' => 'no-cache' ) ),
+                               'expected_status'    => 'critical',
+                               'expected_label'     => $critical_label,
+                               'good_basic_auth'    => null,
+                               'delay_the_response' => true,
+                       ),
+                       'age'                                    => array(
+                               'responses'       => array_fill(
+                                       0,
+                                       3,
+                                       array( 'age' => '1345' )
+                               ),
+                               'expected_status' => 'good',
+                               'expected_label'  => $good_label,
+                       ),
+                       'cache-control-max-age'                  => array(
+                               'responses'       => array_fill(
+                                       0,
+                                       3,
+                                       array( 'cache-control' => 'public; max-age=600' )
+                               ),
+                               'expected_status' => 'good',
+                               'expected_label'  => $good_label,
+                       ),
+                       'etag'                                   => array(
+                               'responses'       => array_fill(
+                                       0,
+                                       3,
+                                       array( 'etag' => '"1234567890"' )
+                               ),
+                               'expected_status' => 'good',
+                               'expected_label'  => $good_label,
+                       ),
+                       'cache-control-max-age-after-2-requests' => array(
+                               'responses'       => array(
+                                       array(),
+                                       array(),
+                                       array( 'cache-control' => 'public; max-age=600' ),
+                               ),
+                               'expected_status' => 'good',
+                               'expected_label'  => $good_label,
+                       ),
+                       'cache-control-with-future-expires'      => array(
+                               'responses'       => array_fill(
+                                       0,
+                                       3,
+                                       array( 'expires' => gmdate( 'r', time() + HOUR_IN_SECONDS ) )
+                               ),
+                               'expected_status' => 'good',
+                               'expected_label'  => $good_label,
+                       ),
+                       'cache-control-with-past-expires'        => array(
+                               'responses'          => array_fill(
+                                       0,
+                                       3,
+                                       array( 'expires' => gmdate( 'r', time() - HOUR_IN_SECONDS ) )
+                               ),
+                               'expected_status'    => 'critical',
+                               'expected_label'     => $critical_label,
+                               'good_basic_auth'    => null,
+                               'delay_the_response' => true,
+                       ),
+                       'cache-control-with-basic-auth'          => array(
+                               'responses'       => array_fill(
+                                       0,
+                                       3,
+                                       array( 'cache-control' => 'public; max-age=600' )
+                               ),
+                               'expected_status' => 'good',
+                               'expected_label'  => $good_label,
+                               'good_basic_auth' => true,
+                       ),
+                       'x-cache-enabled'                        => array(
+                               'responses'       => array_fill(
+                                       0,
+                                       3,
+                                       array( 'x-cache-enabled' => 'true' )
+                               ),
+                               'expected_status' => 'good',
+                               'expected_label'  => $good_label,
+                       ),
+                       'x-cache-enabled-with-delay'             => array(
+                               'responses'          => array_fill(
+                                       0,
+                                       3,
+                                       array( 'x-cache-enabled' => 'false' )
+                               ),
+                               'expected_status'    => 'critical',
+                               'expected_label'     => $critical_label,
+                               'good_basic_auth'    => null,
+                               'delay_the_response' => true,
+                       ),
+                       'x-cache-disabled'                       => array(
+                               'responses'       => array_fill(
+                                       0,
+                                       3,
+                                       array( 'x-cache-disabled' => 'off' )
+                               ),
+                               'expected_status' => 'good',
+                               'expected_label'  => $good_label,
+                       ),
+               );
+       }
+
+       /**
+        * @group ms-excluded
+        * @ticket 56040
+        */
+       public function test_object_cache_default_thresholds_non_multisite() {
+               // Set thresholds so high they should never be exceeded.
+               add_filter(
+                       'site_status_persistent_object_cache_thresholds',
+                       function() {
+                               return array(
+                                       'alloptions_count' => PHP_INT_MAX,
+                                       'alloptions_bytes' => PHP_INT_MAX,
+                                       'comments_count'   => PHP_INT_MAX,
+                                       'options_count'    => PHP_INT_MAX,
+                                       'posts_count'      => PHP_INT_MAX,
+                                       'terms_count'      => PHP_INT_MAX,
+                                       'users_count'      => PHP_INT_MAX,
+                               );
+                       }
+               );
+
+               $this->assertFalse(
+                       $this->instance->should_suggest_persistent_object_cache()
+               );
+       }
+
+
+       /**
+        * @group ms-required
+        * @ticket 56040
+        */
+       public function test_object_cache_default_thresholds_on_multisite() {
+               $this->assertTrue(
+                       $this->instance->should_suggest_persistent_object_cache()
+               );
+       }
+
+       /**
+        * @ticket 56040
+        */
+       public function test_object_cache_thresholds_check_can_be_bypassed() {
+               add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_true' );
+               $this->assertTrue(
+                       $this->instance->should_suggest_persistent_object_cache()
+               );
+
+               add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_false', 11 );
+               $this->assertFalse(
+                       $this->instance->should_suggest_persistent_object_cache()
+               );
+       }
+
+       /**
+        * @dataProvider data_object_cache_thresholds
+        * @ticket 56040
+        */
+       public function test_object_cache_thresholds( $threshold, $count ) {
+               add_filter(
+                       'site_status_persistent_object_cache_thresholds',
+                       function ( $thresholds ) use ( $threshold, $count ) {
+                               return array_merge( $thresholds, array( $threshold => $count ) );
+                       }
+               );
+
+               $this->assertTrue(
+                       $this->instance->should_suggest_persistent_object_cache()
+               );
+       }
+
+       /**
+        * Data provider for test_object_cache_thresholds().
+        *
+        * @ticket 56040
+        */
+       public function data_object_cache_thresholds() {
+               return array(
+                       array( 'comments_count', 0 ),
+                       array( 'posts_count', 0 ),
+                       array( 'terms_count', 1 ),
+                       array( 'options_count', 100 ),
+                       array( 'users_count', 0 ),
+                       array( 'alloptions_count', 100 ),
+                       array( 'alloptions_bytes', 1000 ),
+               );
+       }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestssitehealthphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/site-health.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/site-health.php 2022-09-05 21:14:38 UTC (rev 54074)
+++ trunk/tests/phpunit/tests/site-health.php   2022-09-05 22:25:54 UTC (rev 54075)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,498 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-/**
- * @group site-health
- *
- * @coversDefaultClass WP_Site_Health
- */
-class Tests_Site_Health extends WP_UnitTestCase {
-       public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
-               // Include the `WP_Site_Health` file.
-               require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
-       }
-
-       /**
-        * @ticket 55791
-        * @covers ::prepare_sql_data()
-        * @covers ::get_test_sql_server()
-        */
-       public function test_mysql_recommended_version_matches_readme_html() {
-               // This test is designed to only run on trunk.
-               $this->skipOnAutomatedBranches();
-
-               $wp_site_health = new WP_Site_Health();
-               $wp_site_health->get_test_sql_server();
-
-               $reflection          = new ReflectionClass( $wp_site_health );
-               $reflection_property = $reflection->getProperty( 'mysql_recommended_version' );
-               $reflection_property->setAccessible( true );
-
-               $readme = file_get_contents( ABSPATH . 'readme.html' );
-
-               preg_match( '#Recommendations.*MySQL</a> version <strong>([0-9.]*)#s', $readme, $matches );
-
-               $this->assertSame( $matches[1], $reflection_property->getValue( $wp_site_health ) );
-       }
-
-       /**
-        * @ticket 55791
-        * @covers ::prepare_sql_data()
-        * @covers ::get_test_sql_server()
-        */
-       public function test_mariadb_recommended_version_matches_readme_html() {
-               // This test is designed to only run on trunk.
-               $this->skipOnAutomatedBranches();
-
-               $wp_site_health = new WP_Site_Health();
-               $wp_site_health->get_test_sql_server();
-
-               $reflection          = new ReflectionClass( $wp_site_health );
-               $reflection_property = $reflection->getProperty( 'mariadb_recommended_version' );
-               $reflection_property->setAccessible( true );
-
-               $readme = file_get_contents( ABSPATH . 'readme.html' );
-
-               preg_match( '#Recommendations.*MariaDB</a> version <strong>([0-9.]*)#s', $readme, $matches );
-
-               $this->assertSame( $matches[1], $reflection_property->getValue( $wp_site_health ) );
-       }
-
-       /**
-        * Ensure Site Health reports correctly cron job reports.
-        *
-        * @ticket 47223
-        */
-       public function test_cron_health_checks_critical() {
-               $wp_site_health = new WP_Site_Health();
-
-               // Clear the cron array.
-               _set_cron_array( array() );
-
-               $cron_health = $wp_site_health->get_test_scheduled_events();
-
-               $this->assertSame( 'critical', $cron_health['status'] );
-               $this->assertSame( __( 'It was not possible to check your scheduled events' ), $cron_health['label'] );
-               $this->assertWPError( $wp_site_health->has_late_cron() );
-               $this->assertWPError( $wp_site_health->has_missed_cron() );
-       }
-
-       /**
-        * Ensure Site Health reports correctly cron job reports.
-        *
-        * @dataProvider data_cron_health_checks
-        * @ticket 47223
-        */
-       public function test_cron_health_checks( $times, $expected_status, $expected_label, $expected_late, $expected_missed ) {
-               $wp_site_health = new WP_Site_Health();
-
-               /*
-                * Clear the cron array.
-                *
-                * The core jobs may register as late/missed in the test suite as they
-                * are not run. Clearing the array ensures the site health tests are only
-                * reported based on the jobs set in the test.
-                */
-               _set_cron_array( array() );
-               $times = (array) $times;
-               foreach ( $times as $job => $time ) {
-                       $timestamp = strtotime( $time );
-                       wp_schedule_event( $timestamp, 'daily', __FUNCTION__ . "_{$job}" );
-               }
-
-               $cron_health = $wp_site_health->get_test_scheduled_events();
-
-               $this->assertSame( $expected_status, $cron_health['status'] );
-               $this->assertSame( $expected_label, $cron_health['label'] );
-               $this->assertSame( $expected_late, $wp_site_health->has_late_cron() );
-               $this->assertSame( $expected_missed, $wp_site_health->has_missed_cron() );
-       }
-
-       /**
-        * Data provider for Site Health cron reports.
-        *
-        * The test suite runs with `DISABLE_WP_CRON === true` so the
-        * missed and late tests need to account for the extended periods
-        * allowed for with this flag enabled.
-        *
-        * 1. string|array Times to schedule (run through strtotime())
-        * 2. string       Expected status
-        * 3. string       Expected label
-        * 4. bool         Expected outcome has_late_cron()
-        * 5. bool         Expected outcome has_missed_cron()
-        */
-       public function data_cron_health_checks() {
-               return array(
-                       array(
-                               '+5 minutes',
-                               'good',
-                               __( 'Scheduled events are running' ),
-                               false,
-                               false,
-                       ),
-                       array(
-                               '-50 minutes',
-                               'recommended',
-                               __( 'A scheduled event is late' ),
-                               true,
-                               false,
-                       ),
-                       array(
-                               '-500 minutes',
-                               'recommended',
-                               __( 'A scheduled event has failed' ),
-                               false,
-                               true,
-                       ),
-                       array(
-                               array(
-                                       '-50 minutes',
-                                       '-500 minutes',
-                               ),
-                               'recommended',
-                               __( 'A scheduled event has failed' ),
-                               true,
-                               true,
-                       ),
-               );
-       }
-
-       /**
-        * @ticket 56041
-        * @dataProvider data_get_page_cache
-        * @covers ::get_test_page_cache()
-        * @covers ::get_page_cache_detail()
-        * @covers ::get_page_cache_headers()
-        * @covers ::check_for_page_caching()
-        */
-       public function test_get_page_cache( $responses, $expected_status, $expected_label, $good_basic_auth = null, $delay_the_response = false ) {
-               $wp_site_health = new WP_Site_Health();
-
-               $expected_props = array(
-                       'badge'  => array(
-                               'label' => __( 'Performance' ),
-                               'color' => 'blue',
-                       ),
-                       'test'   => 'page_cache',
-                       'status' => $expected_status,
-                       'label'  => $expected_label,
-               );
-
-               if ( null !== $good_basic_auth ) {
-                       $_SERVER['PHP_AUTH_USER'] = 'admin';
-                       $_SERVER['PHP_AUTH_PW']   = 'password';
-               }
-
-               $threshold = 10;
-               if ( $delay_the_response ) {
-                       add_filter(
-                               'site_status_good_response_time_threshold',
-                               static function () use ( $threshold ) {
-                                       return $threshold;
-                               }
-                       );
-               }
-
-               add_filter(
-                       'pre_http_request',
-                       function ( $r, $parsed_args ) use ( &$responses, &$is_unauthorized, $good_basic_auth, $delay_the_response, $threshold ) {
-
-                               $expected_response = array_shift( $responses );
-
-                               if ( $delay_the_response ) {
-                                       usleep( $threshold * 1000 + 1 );
-                               }
-
-                               if ( 'unauthorized' === $expected_response ) {
-                                       $is_unauthorized = true;
-
-                                       return array(
-                                               'response' => array(
-                                                       'code'    => 401,
-                                                       'message' => 'Unauthorized',
-                                               ),
-                                       );
-                               }
-
-                               if ( null !== $good_basic_auth ) {
-                                       $this->assertArrayHasKey(
-                                               'Authorization',
-                                               $parsed_args['headers']
-                                       );
-                               }
-
-                               $this->assertIsArray( $expected_response );
-
-                               return array(
-                                       'headers'  => $expected_response,
-                                       'response' => array(
-                                               'code'    => 200,
-                                               'message' => 'OK',
-                                       ),
-                               );
-                       },
-                       20,
-                       2
-               );
-
-               $actual = $wp_site_health->get_test_page_cache();
-               $this->assertArrayHasKey( 'description', $actual );
-               $this->assertArrayHasKey( 'actions', $actual );
-               if ( $is_unauthorized ) {
-                       $this->assertStringContainsString( 'Unauthorized', $actual['description'] );
-               } else {
-                       $this->assertStringNotContainsString( 'Unauthorized', $actual['description'] );
-               }
-
-               $this->assertEquals(
-                       $expected_props,
-                       wp_array_slice_assoc( $actual, array_keys( $expected_props ) )
-               );
-       }
-
-       /**
-        * Data provider for test_get_page_cache().
-        *
-        * Gets response data for WP_Site_Health::get_test_page_cache().
-        *
-        * @ticket 56041
-        *
-        * @return array[]
-        */
-       public function data_get_page_cache() {
-               $recommended_label = 'Page cache is not detected but the server response time is OK';
-               $good_label        = 'Page cache is detected and the server response time is good';
-               $critical_label    = 'Page cache is not detected and the server response time is slow';
-               $error_label       = 'Unable to detect the presence of page cache';
-
-               return array(
-                       'basic-auth-fail'                        => array(
-                               'responses'       => array(
-                                       'unauthorized',
-                               ),
-                               'expected_status' => 'recommended',
-                               'expected_label'  => $error_label,
-                               'good_basic_auth' => false,
-                       ),
-                       'no-cache-control'                       => array(
-                               'responses'          => array_fill( 0, 3, array() ),
-                               'expected_status'    => 'critical',
-                               'expected_label'     => $critical_label,
-                               'good_basic_auth'    => null,
-                               'delay_the_response' => true,
-                       ),
-                       'no-cache'                               => array(
-                               'responses'       => array_fill( 0, 3, array( 'cache-control' => 'no-cache' ) ),
-                               'expected_status' => 'recommended',
-                               'expected_label'  => $recommended_label,
-                       ),
-                       'no-cache-arrays'                        => array(
-                               'responses'       => array_fill(
-                                       0,
-                                       3,
-                                       array(
-                                               'cache-control' => array(
-                                                       'no-cache',
-                                                       'no-store',
-                                               ),
-                                       )
-                               ),
-                               'expected_status' => 'recommended',
-                               'expected_label'  => $recommended_label,
-                       ),
-                       'no-cache-with-delayed-response'         => array(
-                               'responses'          => array_fill( 0, 3, array( 'cache-control' => 'no-cache' ) ),
-                               'expected_status'    => 'critical',
-                               'expected_label'     => $critical_label,
-                               'good_basic_auth'    => null,
-                               'delay_the_response' => true,
-                       ),
-                       'age'                                    => array(
-                               'responses'       => array_fill(
-                                       0,
-                                       3,
-                                       array( 'age' => '1345' )
-                               ),
-                               'expected_status' => 'good',
-                               'expected_label'  => $good_label,
-                       ),
-                       'cache-control-max-age'                  => array(
-                               'responses'       => array_fill(
-                                       0,
-                                       3,
-                                       array( 'cache-control' => 'public; max-age=600' )
-                               ),
-                               'expected_status' => 'good',
-                               'expected_label'  => $good_label,
-                       ),
-                       'etag'                                   => array(
-                               'responses'       => array_fill(
-                                       0,
-                                       3,
-                                       array( 'etag' => '"1234567890"' )
-                               ),
-                               'expected_status' => 'good',
-                               'expected_label'  => $good_label,
-                       ),
-                       'cache-control-max-age-after-2-requests' => array(
-                               'responses'       => array(
-                                       array(),
-                                       array(),
-                                       array( 'cache-control' => 'public; max-age=600' ),
-                               ),
-                               'expected_status' => 'good',
-                               'expected_label'  => $good_label,
-                       ),
-                       'cache-control-with-future-expires'      => array(
-                               'responses'       => array_fill(
-                                       0,
-                                       3,
-                                       array( 'expires' => gmdate( 'r', time() + HOUR_IN_SECONDS ) )
-                               ),
-                               'expected_status' => 'good',
-                               'expected_label'  => $good_label,
-                       ),
-                       'cache-control-with-past-expires'        => array(
-                               'responses'          => array_fill(
-                                       0,
-                                       3,
-                                       array( 'expires' => gmdate( 'r', time() - HOUR_IN_SECONDS ) )
-                               ),
-                               'expected_status'    => 'critical',
-                               'expected_label'     => $critical_label,
-                               'good_basic_auth'    => null,
-                               'delay_the_response' => true,
-                       ),
-                       'cache-control-with-basic-auth'          => array(
-                               'responses'       => array_fill(
-                                       0,
-                                       3,
-                                       array( 'cache-control' => 'public; max-age=600' )
-                               ),
-                               'expected_status' => 'good',
-                               'expected_label'  => $good_label,
-                               'good_basic_auth' => true,
-                       ),
-                       'x-cache-enabled'                        => array(
-                               'responses'       => array_fill(
-                                       0,
-                                       3,
-                                       array( 'x-cache-enabled' => 'true' )
-                               ),
-                               'expected_status' => 'good',
-                               'expected_label'  => $good_label,
-                       ),
-                       'x-cache-enabled-with-delay'             => array(
-                               'responses'          => array_fill(
-                                       0,
-                                       3,
-                                       array( 'x-cache-enabled' => 'false' )
-                               ),
-                               'expected_status'    => 'critical',
-                               'expected_label'     => $critical_label,
-                               'good_basic_auth'    => null,
-                               'delay_the_response' => true,
-                       ),
-                       'x-cache-disabled'                       => array(
-                               'responses'       => array_fill(
-                                       0,
-                                       3,
-                                       array( 'x-cache-disabled' => 'off' )
-                               ),
-                               'expected_status' => 'good',
-                               'expected_label'  => $good_label,
-                       ),
-               );
-       }
-
-       /**
-        * @group ms-excluded
-        * @ticket 56040
-        */
-       public function test_object_cache_default_thresholds_non_multisite() {
-               $wp_site_health = new WP_Site_Health();
-
-               // Set thresholds so high they should never be exceeded.
-               add_filter(
-                       'site_status_persistent_object_cache_thresholds',
-                       function() {
-                               return array(
-                                       'alloptions_count' => PHP_INT_MAX,
-                                       'alloptions_bytes' => PHP_INT_MAX,
-                                       'comments_count'   => PHP_INT_MAX,
-                                       'options_count'    => PHP_INT_MAX,
-                                       'posts_count'      => PHP_INT_MAX,
-                                       'terms_count'      => PHP_INT_MAX,
-                                       'users_count'      => PHP_INT_MAX,
-                               );
-                       }
-               );
-
-               $this->assertFalse(
-                       $wp_site_health->should_suggest_persistent_object_cache()
-               );
-       }
-
-
-       /**
-        * @group ms-required
-        * @ticket 56040
-        */
-       public function test_object_cache_default_thresholds_on_multisite() {
-               $wp_site_health = new WP_Site_Health();
-               $this->assertTrue(
-                       $wp_site_health->should_suggest_persistent_object_cache()
-               );
-       }
-
-       /**
-        * @ticket 56040
-        */
-       public function test_object_cache_thresholds_check_can_be_bypassed() {
-               $wp_site_health = new WP_Site_Health();
-
-               add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_true' );
-               $this->assertTrue(
-                       $wp_site_health->should_suggest_persistent_object_cache()
-               );
-
-               add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_false', 11 );
-               $this->assertFalse(
-                       $wp_site_health->should_suggest_persistent_object_cache()
-               );
-       }
-
-       /**
-        * @dataProvider data_object_cache_thresholds
-        * @ticket 56040
-        */
-       public function test_object_cache_thresholds( $threshold, $count ) {
-               $wp_site_health = new WP_Site_Health();
-               add_filter(
-                       'site_status_persistent_object_cache_thresholds',
-                       function ( $thresholds ) use ( $threshold, $count ) {
-                               return array_merge( $thresholds, array( $threshold => $count ) );
-                       }
-               );
-
-               $this->assertTrue(
-                       $wp_site_health->should_suggest_persistent_object_cache()
-               );
-       }
-
-       /**
-        * Data provider for test_object_cache_thresholds().
-        *
-        * @ticket 56040
-        */
-       public function data_object_cache_thresholds() {
-               return array(
-                       array( 'comments_count', 0 ),
-                       array( 'posts_count', 0 ),
-                       array( 'terms_count', 1 ),
-                       array( 'options_count', 100 ),
-                       array( 'users_count', 0 ),
-                       array( 'alloptions_count', 100 ),
-                       array( 'alloptions_bytes', 1000 ),
-               );
-       }
-}
</del></span></pre>
</div>
</div>

</body>
</html>