Skip to content
Permalink
Browse files

Site Health Check: New tests file missed in [45801].

git-svn-id: https://develop.svn.wordpress.org/trunk@45802 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
peterwilsoncc committed Aug 15, 2019
1 parent f29952a commit 0d2b94a44a3548fecb60ef57cbb4e4691e9a77e4
Showing with 107 additions and 0 deletions.
  1. +107 −0 tests/phpunit/tests/site-health.php
@@ -0,0 +1,107 @@
<?php
/**
* @group site-health
*/
class Tests_Site_Health extends WP_UnitTestCase {
public static function wpSetUpBeforeClass() {
// Include the `WP_Site_Health` file.
include_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
}
/**
* Ensure Site Health reports correctly cron job reports.
*
* @ticket 47223
*/
function test_cron_health_checks_critical() {
// Clear the cron array.
_set_cron_array( array() );
$wp_site_health = new WP_Site_Health();
$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
*/
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}" );
}
$wp_site_health = new WP_Site_Health();
$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()
*/
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,
),
);
}
}

0 comments on commit 0d2b94a

Please sign in to comment.
You can’t perform that action at this time.