Tests: In Tests_Site_Health, create a WP_Site_Health instance before clearing the cron array, as the constructor schedules its own task now.

See #47606.

git-svn-id: https://develop.svn.wordpress.org/trunk@47064 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-01-12 14:16:57 +00:00
parent 396cc8205b
commit 2daa4b6c82

View File

@ -15,10 +15,12 @@ class Tests_Site_Health extends WP_UnitTestCase {
* @ticket 47223 * @ticket 47223
*/ */
function test_cron_health_checks_critical() { function test_cron_health_checks_critical() {
$wp_site_health = new WP_Site_Health();
// Clear the cron array. // Clear the cron array.
_set_cron_array( array() ); _set_cron_array( array() );
$wp_site_health = new WP_Site_Health();
$cron_health = $wp_site_health->get_test_scheduled_events(); $cron_health = $wp_site_health->get_test_scheduled_events();
$this->assertSame( 'critical', $cron_health['status'] ); $this->assertSame( 'critical', $cron_health['status'] );
$this->assertSame( __( 'It was not possible to check your scheduled events' ), $cron_health['label'] ); $this->assertSame( __( 'It was not possible to check your scheduled events' ), $cron_health['label'] );
@ -33,6 +35,8 @@ class Tests_Site_Health extends WP_UnitTestCase {
* @ticket 47223 * @ticket 47223
*/ */
function test_cron_health_checks( $times, $expected_status, $expected_label, $expected_late, $expected_missed ) { 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. * Clear the cron array.
* *
@ -47,8 +51,7 @@ class Tests_Site_Health extends WP_UnitTestCase {
wp_schedule_event( $timestamp, 'daily', __FUNCTION__ . "_{$job}" ); wp_schedule_event( $timestamp, 'daily', __FUNCTION__ . "_{$job}" );
} }
$wp_site_health = new WP_Site_Health(); $cron_health = $wp_site_health->get_test_scheduled_events();
$cron_health = $wp_site_health->get_test_scheduled_events();
$this->assertSame( $expected_status, $cron_health['status'] ); $this->assertSame( $expected_status, $cron_health['status'] );
$this->assertSame( $expected_label, $cron_health['label'] ); $this->assertSame( $expected_label, $cron_health['label'] );