Commit 52b77598 authored by Erick Hitter's avatar Erick Hitter
Browse files

Fix tests, following Core's lead

Core resets the option before its tests, so we perform the equivalent. Addressing #90 will make the non-Core approach unnecessary.
parent 3dd7e1fd
......@@ -10,6 +10,19 @@ class Utils {
return \Automattic\WP\Cron_Control\Events_Store::instance()->get_table_name();
}
/**
* Start with a clean events store when running tests
*
* To be called during tests' `setUp` and `tearDown` methods
*
* Follows Core's approach when running cron tests, but `_set_cron_array()` doesn't work for us
*/
static function reset_events_store() {
global $wpdb;
$wpdb->delete( Utils::get_table_name(), array( 'status' => \Automattic\WP\Cron_Control\Events_Store::STATUS_PENDING, ) );
\Automattic\WP\Cron_Control\_flush_internal_caches();
}
/**
* Build a test event
*/
......
......@@ -11,6 +11,25 @@ namespace Automattic\WP\Cron_Control\Tests;
* Sample test case.
*/
class Events_Store_Tests extends \WP_UnitTestCase {
/**
* Prepare test environment
*/
function setUp() {
parent::setUp();
// make sure the schedule is clear
Utils::reset_events_store();
}
/**
* Clean up after our tests
*/
function tearDown() {
// make sure the schedule is clear
Utils::reset_events_store();
parent::tearDown();
}
/**
* Custom table exists
......
......@@ -11,6 +11,25 @@ namespace Automattic\WP\Cron_Control\Tests;
* Sample test case.
*/
class Internal_Events_Tests extends \WP_UnitTestCase {
/**
* Prepare test environment
*/
function setUp() {
parent::setUp();
// make sure the schedule is clear
Utils::reset_events_store();
}
/**
* Clean up after our tests
*/
function tearDown() {
// make sure the schedule is clear
Utils::reset_events_store();
parent::tearDown();
}
/**
* Internal events should be scheduled
......
......@@ -11,6 +11,25 @@ namespace Automattic\WP\Cron_Control\Tests;
* Sample test case.
*/
class Misc_Tests extends \WP_UnitTestCase {
/**
* Prepare test environment
*/
function setUp() {
parent::setUp();
// make sure the schedule is clear
Utils::reset_events_store();
}
/**
* Clean up after our tests
*/
function tearDown() {
// make sure the schedule is clear
Utils::reset_events_store();
parent::tearDown();
}
/**
* Expected values for certain constants
......
......@@ -20,6 +20,22 @@ class REST_API_Tests extends \WP_UnitTestCase {
global $wp_rest_server;
$this->server = $wp_rest_server = new \WP_REST_Server;
do_action( 'rest_api_init' );
// make sure the schedule is clear
Utils::reset_events_store();
}
/**
* Clean up after our tests
*/
function tearDown() {
global $wp_rest_server;
$wp_rest_server = null;
// make sure the schedule is clear
Utils::reset_events_store();
parent::tearDown();
}
/**
......@@ -108,15 +124,4 @@ class REST_API_Tests extends \WP_UnitTestCase {
protected function assertResponseData( $data, $response ) {
Utils::compare_arrays( $data, $response->get_data(), $this );
}
/**
* Clean up
*/
public function tearDown() {
parent::tearDown();
global $wp_rest_server;
$wp_rest_server = null;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment