Verified Commit 49e7e3bc authored by Erick Hitter's avatar Erick Hitter
Browse files

Namespace tests and update phpdoc to reflect ongoing renaming

parent f106ac24
......@@ -2,7 +2,7 @@
/**
* PHPUnit bootstrap file
*
* @package WP_Cron_Control_Revisited
* @package Automattic_Cron_Control
*/
$_tests_dir = getenv( 'WP_TESTS_DIR' );
......@@ -19,7 +19,7 @@ require_once $_tests_dir . '/includes/functions.php';
function _manually_load_plugin() {
define( 'WP_CRON_CONTROL_SECRET', 'testtesttest' );
require dirname( dirname( __FILE__ ) ) . '/wp-cron-control-revisited.php';
require dirname( dirname( __FILE__ ) ) . '/cron-control.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
......
<?php
/**
* Class WPCCR_Cron_Options_CPT_Test
* Class Cron_Options_CPT_Tests
*
* @package WP_Cron_Control_Revisited
* @package Automattic_Cron_Control
*/
namespace Automattic\WP\Cron_Control\Tests;
/**
* Sample test case.
*/
class WPCCR_Cron_Options_CPT_Test extends WP_UnitTestCase {
class Cron_Options_CPT_Tests extends \WP_UnitTestCase {
/**
* Custom post type exists
*/
function test_cpt_exists() {
$this->assertTrue( post_type_exists( Automattic\WP\Cron_Control\Cron_Options_CPT::POST_TYPE ) );
$this->assertTrue( post_type_exists( \Automattic\WP\Cron_Control\Cron_Options_CPT::POST_TYPE ) );
}
/**
......@@ -23,10 +25,10 @@ class WPCCR_Cron_Options_CPT_Test extends WP_UnitTestCase {
function test_events_exist() {
global $wpdb;
$event = Automattic\WP\Cron_Control\Tests\Utils::create_test_event();
$event = \Automattic\WP\Cron_Control\Tests\Utils::create_test_event();
$post_name = sprintf( '%s-%s-%s', $event['timestamp'], md5( $event['action'] ), md5( maybe_serialize( $event['args'] ) ) );
$entry = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = %s AND post_status = %s AND post_name = %s LIMIT 1", Automattic\WP\Cron_Control\Cron_Options_CPT::POST_TYPE, Automattic\WP\Cron_Control\Cron_Options_CPT::POST_STATUS, $post_name ) );
$entry = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = %s AND post_status = %s AND post_name = %s LIMIT 1", \Automattic\WP\Cron_Control\Cron_Options_CPT::POST_TYPE, \Automattic\WP\Cron_Control\Cron_Options_CPT::POST_STATUS, $post_name ) );
$this->assertEquals( count( $entry ), 1 );
......@@ -35,14 +37,14 @@ class WPCCR_Cron_Options_CPT_Test extends WP_UnitTestCase {
$this->assertEquals( $event['action'], $instance['action'] );
$this->assertEquals( md5( maybe_serialize( $event['args'] ) ), $instance['instance'] );
Automattic\WP\Cron_Control\Tests\Utils::compare_arrays( $event['args'], $instance['args'], $this );
Utils::compare_arrays( $event['args'], $instance['args'], $this );
}
/**
* Check format of filtered array returned from CPT
*/
function test_filter_cron_option_get() {
$event = Automattic\WP\Cron_Control\Tests\Utils::create_test_event();
$event = Utils::create_test_event();
$cron = get_option( 'cron' );
......@@ -68,8 +70,8 @@ class WPCCR_Cron_Options_CPT_Test extends WP_UnitTestCase {
* Test that events are unscheduled correctly using Core functions
*/
function test_event_unscheduling_using_core_functions() {
$first_event = Automattic\WP\Cron_Control\Tests\Utils::create_test_event();
$second_event = Automattic\WP\Cron_Control\Tests\Utils::create_test_event( true );
$first_event = Utils::create_test_event();
$second_event = Utils::create_test_event( true );
$first_event_ts = wp_next_scheduled( $first_event['action'], $first_event['args'] );
......@@ -95,29 +97,29 @@ class WPCCR_Cron_Options_CPT_Test extends WP_UnitTestCase {
*/
function test_event_unscheduling_against_cpt() {
// Schedule two events and prepare their data a bit for further testing
$first_event = Automattic\WP\Cron_Control\Tests\Utils::create_test_event();
$first_event = Utils::create_test_event();
$first_event['instance'] = md5( maybe_serialize( $first_event['args'] ) );
$first_event_args = $first_event['args'];
unset( $first_event['args'] );
sleep( 2 ); // More-thorough to test with events that don't have matching timestamps
$second_event = Automattic\WP\Cron_Control\Tests\Utils::create_test_event( true );
$second_event = Utils::create_test_event( true );
$second_event['instance'] = md5( maybe_serialize( $second_event['args'] ) );
$second_event_args = $second_event['args'];
unset( $second_event['args'] );
// First, check that posts were created for the two events
Automattic\WP\Cron_Control\Tests\Utils::compare_arrays( array( $first_event, $second_event ), Automattic\WP\Cron_Control\Tests\Utils::get_events_from_post_objects(), $this );
Utils::compare_arrays( array( $first_event, $second_event ), Utils::get_events_from_post_objects(), $this );
// Second, unschedule an event and confirm that the post is removed
wp_unschedule_event( $first_event['timestamp'], $first_event['action'], $first_event_args );
Automattic\WP\Cron_Control\Tests\Utils::compare_arrays( array( $second_event ), Automattic\WP\Cron_Control\Tests\Utils::get_events_from_post_objects(), $this );
Utils::compare_arrays( array( $second_event ), Utils::get_events_from_post_objects(), $this );
// Finally, unschedule the second event and confirm its post is also deleted
wp_unschedule_event( $second_event['timestamp'], $second_event['action'], $second_event_args );
$this->assertEmpty( Automattic\WP\Cron_Control\Tests\Utils::get_events_from_post_objects() );
$this->assertEmpty( Utils::get_events_from_post_objects() );
}
}
<?php
/**
* Class WPCCR_Internal_Events_Test
* Class Internal_Events_Tests
*
* @package WP_Cron_Control_Revisited
* @package Automattic_Cron_Control
*/
namespace Automattic\WP\Cron_Control\Tests;
/**
* Sample test case.
*/
class WPCCR_Internal_Events_Test extends WP_UnitTestCase {
class Internal_Events_Tests extends \WP_UnitTestCase {
/**
* Internal events should be scheduled
*/
function test_events() {
Automattic\WP\Cron_Control\Internal_Events::instance()->schedule_internal_events();
\Automattic\WP\Cron_Control\Internal_Events::instance()->schedule_internal_events();
$events = \Automattic\WP\Cron_Control\collapse_events_array( get_option( 'cron' ) );
......
<?php
/**
* Class WPCCR_Misc_Test
* Class Misc_Tests
*
* @package WP_Cron_Control_Revisited
* @package Automattic_Cron_Control
*/
namespace Automattic\WP\Cron_Control\Tests;
/**
* Sample test case.
*/
class WPCCR_Misc_Test extends WP_UnitTestCase {
class Misc_Tests extends \WP_UnitTestCase {
/**
* Expected values for certain constants
......
<?php
/**
* Class WPCCR_REST_API_Test
* Class REST_API_Tests
*
* @package WP_Cron_Control_Revisited
* @package Automattic_Cron_Control
*/
namespace Automattic\WP\Cron_Control\Tests;
/**
* Sample test case.
*/
class WPCCR_REST_API_Test extends WP_UnitTestCase {
class REST_API_Tests extends \WP_UnitTestCase {
/**
* Prepare for REST API tests
*/
......@@ -16,7 +18,7 @@ class WPCCR_REST_API_Test extends WP_UnitTestCase {
parent::setUp();
global $wp_rest_server;
$this->server = $wp_rest_server = new WP_REST_Server;
$this->server = $wp_rest_server = new \WP_REST_Server;
do_action( 'rest_api_init' );
}
......@@ -24,7 +26,7 @@ class WPCCR_REST_API_Test extends WP_UnitTestCase {
* Verify that GET requests to the endpoint fail
*/
public function test_invalid_request() {
$request = new WP_REST_Request( 'GET', '/' . Automattic\WP\Cron_Control\REST_API_NAMESPACE . '/' . Automattic\WP\Cron_Control\REST_API_ENDPOINT_LIST );
$request = new \WP_REST_Request( 'GET', '/' . \Automattic\WP\Cron_Control\REST_API_NAMESPACE . '/' . \Automattic\WP\Cron_Control\REST_API_ENDPOINT_LIST );
$response = $this->server->dispatch( $request );
$this->assertResponseStatus( 404, $response );
}
......@@ -33,9 +35,9 @@ class WPCCR_REST_API_Test extends WP_UnitTestCase {
* Test that list endpoint returns expected format
*/
public function test_get_items() {
$ev = Automattic\WP\Cron_Control\Tests\Utils::create_test_event();
$ev = Utils::create_test_event();
$request = new WP_REST_Request( 'POST', '/' . Automattic\WP\Cron_Control\REST_API_NAMESPACE . '/' . Automattic\WP\Cron_Control\REST_API_ENDPOINT_LIST );
$request = new \WP_REST_Request( 'POST', '/' . \Automattic\WP\Cron_Control\REST_API_NAMESPACE . '/' . \Automattic\WP\Cron_Control\REST_API_ENDPOINT_LIST );
$request->set_body( wp_json_encode( array( 'secret' => WP_CRON_CONTROL_SECRET, ) ) );
$request->set_header( 'content-type', 'application/json' );
......@@ -54,7 +56,7 @@ class WPCCR_REST_API_Test extends WP_UnitTestCase {
'instance' => md5( maybe_serialize( $ev['args'] ) ),
),
),
'endpoint' => get_rest_url( null, Automattic\WP\Cron_Control\REST_API_NAMESPACE . '/' . Automattic\WP\Cron_Control\REST_API_ENDPOINT_RUN ),
'endpoint' => get_rest_url( null, \Automattic\WP\Cron_Control\REST_API_NAMESPACE . '/' . \Automattic\WP\Cron_Control\REST_API_ENDPOINT_RUN ),
), $response );
}
......@@ -62,13 +64,13 @@ class WPCCR_REST_API_Test extends WP_UnitTestCase {
* Test that list endpoint returns expected format
*/
public function test_run_event() {
$ev = Automattic\WP\Cron_Control\Tests\Utils::create_test_event();
$ev = Utils::create_test_event();
$ev['action'] = md5( $ev['action'] );
$ev['instance'] = md5( maybe_serialize( $ev['args'] ) );
$ev['secret'] = WP_CRON_CONTROL_SECRET;
unset( $ev['args'] );
$request = new WP_REST_Request( 'PUT', '/' . Automattic\WP\Cron_Control\REST_API_NAMESPACE . '/' . Automattic\WP\Cron_Control\REST_API_ENDPOINT_RUN );
$request = new \WP_REST_Request( 'PUT', '/' . \Automattic\WP\Cron_Control\REST_API_NAMESPACE . '/' . \Automattic\WP\Cron_Control\REST_API_ENDPOINT_RUN );
$request->set_body( wp_json_encode( $ev ) );
$request->set_header( 'content-type', 'application/json' );
......@@ -93,7 +95,7 @@ class WPCCR_REST_API_Test extends WP_UnitTestCase {
* Ensure response includes the expected data
*/
protected function assertResponseData( $data, $response ) {
Automattic\WP\Cron_Control\Tests\Utils::compare_arrays( $data, $response->get_data(), $this );
Utils::compare_arrays( $data, $response->get_data(), $this );
}
/**
......
Supports Markdown
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