Commit d1d66380 authored by Erick Hitter's avatar Erick Hitter

PHPCS fixes

parent 48bf21f7
......@@ -32,7 +32,7 @@ function _manually_load_plugin() {
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
// Utilities
// Utilities.
require_once __DIR__ . '/includes/class-utils.php';
// Start up the WP testing environment.
......
<?php
/**
* Class Events_Store_Tests
* Test Events Store, which uses a custom table
*
* @package Automattic_Cron_Control
* @package a8c_Cron_Control
*/
namespace Automattic\WP\Cron_Control\Tests;
/**
* Sample test case.
* Events Store Tests
*/
class Events_Store_Tests extends \WP_UnitTestCase {
/**
......@@ -17,7 +17,7 @@ class Events_Store_Tests extends \WP_UnitTestCase {
function setUp() {
parent::setUp();
// make sure the schedule is clear
// make sure the schedule is clear.
_set_cron_array( array() );
}
......@@ -25,7 +25,7 @@ class Events_Store_Tests extends \WP_UnitTestCase {
* Clean up after our tests
*/
function tearDown() {
// make sure the schedule is clear
// make sure the schedule is clear.
_set_cron_array( array() );
parent::tearDown();
......@@ -39,7 +39,7 @@ class Events_Store_Tests extends \WP_UnitTestCase {
$table_name = Utils::get_table_name();
$this->assertEquals( count( $wpdb->get_col( "SHOW TABLES LIKE '{$table_name}'" ) ), 1 );
$this->assertEquals( count( $wpdb->get_col( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) ), 1 );
}
/**
......@@ -51,7 +51,7 @@ class Events_Store_Tests extends \WP_UnitTestCase {
$event = Utils::create_test_event();
$table_name = Utils::get_table_name();
$entry = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE timestamp = %d AND action = %s AND instance = %s AND status = %s LIMIT 1", $event['timestamp'], $event['action'], md5( maybe_serialize( $event['args'] ) ), \Automattic\WP\Cron_Control\Events_Store::STATUS_PENDING ) );
$entry = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE timestamp = %d AND action = %s AND instance = %s AND status = %s LIMIT 1", $event['timestamp'], $event['action'], md5( maybe_serialize( $event['args'] ) ), \Automattic\WP\Cron_Control\Events_Store::STATUS_PENDING ) ); // Cannot prepare table name. @codingStandardsIgnoreLine
$this->assertEquals( count( $entry ), 1 );
......@@ -70,12 +70,12 @@ class Events_Store_Tests extends \WP_UnitTestCase {
$cron = get_option( 'cron' );
// Core versions the cron option (see `_upgrade_cron_array()`)
// Without this in the filtered result, all events continually requeue as Core tries to "upgrade" the option
// Core versions the cron option (see `_upgrade_cron_array()`).
// Without this in the filtered result, all events continually requeue as Core tries to "upgrade" the option.
$this->assertArrayHasKey( 'version', $cron );
$this->assertEquals( $cron['version'], 2 );
// Validate the remaining structure
// Validate the remaining structure.
$cron = \Automattic\WP\Cron_Control\collapse_events_array( $cron );
foreach ( $cron as $single_cron ) {
......@@ -118,28 +118,28 @@ class Events_Store_Tests extends \WP_UnitTestCase {
* Test that events are unscheduled correctly by checking the table
*/
function test_event_unscheduling_against_event_store() {
// Schedule two events and prepare their data a bit for further testing
// Schedule two events and prepare their data a bit for further testing.
$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
sleep( 2 ); // More-thorough to test with events that don't have matching timestamps.
$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
// First, check that posts were created for the two events.
Utils::compare_arrays( array( $first_event, $second_event ), Utils::get_events_from_store(), $this );
// Second, unschedule an event and confirm that the post is removed
// Second, unschedule an event and confirm that the post is removed.
wp_unschedule_event( $first_event['timestamp'], $first_event['action'], $first_event_args );
Utils::compare_arrays( array( $second_event ), Utils::get_events_from_store(), $this );
// Finally, unschedule the second event and confirm its post is also deleted
// 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( Utils::get_events_from_store() );
......
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