Skip to content
Snippets Groups Projects
Commit 797e802e authored by Erick Hitter's avatar Erick Hitter
Browse files

Review feedback

parent 7e7fe4c9
No related branches found
No related tags found
No related merge requests found
...@@ -28,11 +28,6 @@ class Command extends WP_CLI_Command { ...@@ -28,11 +28,6 @@ class Command extends WP_CLI_Command {
*/ */
public function create( $args, $assoc_args ) { public function create( $args, $assoc_args ) {
$command = WP_CLI\Utils\get_flag_value( $assoc_args, 'command', '' ); $command = WP_CLI\Utils\get_flag_value( $assoc_args, 'command', '' );
$command = validate_command( $command );
if ( is_wp_error( $command ) ) {
WP_CLI::error( $command->get_error_message() );
}
$timestamp = WP_CLI\Utils\get_flag_value( $assoc_args, 'timestamp', null ); $timestamp = WP_CLI\Utils\get_flag_value( $assoc_args, 'timestamp', null );
if ( is_numeric( $timestamp ) ) { if ( is_numeric( $timestamp ) ) {
......
...@@ -51,11 +51,18 @@ class Plugin_Functions extends WP_UnitTestCase { ...@@ -51,11 +51,18 @@ class Plugin_Functions extends WP_UnitTestCase {
* Test whitelisted command validation * Test whitelisted command validation
* *
* @dataProvider whitelisted_command_provider * @dataProvider whitelisted_command_provider
*
* @param string $command Command to test.
*/ */
function test_whitelist_using_validate_command( $command ) { function test_whitelist_using_validate_command( $command ) {
$this->assertTrue( is_string( WP_CLI_Cron_Control_Offload\validate_command( $command ) ) ); $this->assertTrue( is_string( WP_CLI_Cron_Control_Offload\validate_command( $command ) ) );
} }
/**
* Data provider for command whitelisting
*
* @return array
*/
function whitelisted_command_provider() { function whitelisted_command_provider() {
return array( return array(
array( 'wp post list' ), array( 'wp post list' ),
...@@ -67,11 +74,18 @@ class Plugin_Functions extends WP_UnitTestCase { ...@@ -67,11 +74,18 @@ class Plugin_Functions extends WP_UnitTestCase {
* Test blacklisted command validation * Test blacklisted command validation
* *
* @dataProvider blacklisted_command_provider * @dataProvider blacklisted_command_provider
*
* @param string $command Command to test.
*/ */
function test_blacklist_using_validate_command( $command ) { function test_blacklist_using_validate_command( $command ) {
$this->assertWPError( WP_CLI_Cron_Control_Offload\validate_command( $command ) ); $this->assertWPError( WP_CLI_Cron_Control_Offload\validate_command( $command ) );
} }
/**
* Data provider for command blacklisting
*
* @return array
*/
function blacklisted_command_provider() { function blacklisted_command_provider() {
return array( return array(
array( 'wp cli info' ), array( 'wp cli info' ),
...@@ -97,16 +111,23 @@ class Plugin_Functions extends WP_UnitTestCase { ...@@ -97,16 +111,23 @@ class Plugin_Functions extends WP_UnitTestCase {
* Test scheduling several of the same blocked event * Test scheduling several of the same blocked event
* *
* @dataProvider blocked_events_provider * @dataProvider blocked_events_provider
*
* @param string $command Command to test.
*/ */
function test_blocked_event_scheduling( $command ) { function test_blocked_event_scheduling( $command ) {
$this->assertWPError( WP_CLI_Cron_Control_Offload\schedule_cli_command( $command ) ); $this->assertWPError( WP_CLI_Cron_Control_Offload\schedule_cli_command( $command ) );
} }
/**
* Data provider for blocked-event scheduling
*
* @return array
*/
function blocked_events_provider() { function blocked_events_provider() {
return array( return array(
array( 'wp cli info' ), // Should fail, is a blocked event. array( 'wp cli info' ), // Should fail, is a blocked event.
array( 'wp cli info' ), // Should fail as a blocked event, would otherwise fail as a duplicate. array( 'wp cli info' ), // Should fail as a blocked event, would otherwise fail as a duplicate.
array( 'cli info'), // Should also fail as a blocked event, though normalization would also block it as a duplicate. array( 'cli info' ), // Should also fail as a blocked event, though normalization would also block it as a duplicate.
); );
} }
...@@ -114,11 +135,18 @@ class Plugin_Functions extends WP_UnitTestCase { ...@@ -114,11 +135,18 @@ class Plugin_Functions extends WP_UnitTestCase {
* Test each blocked bash operator * Test each blocked bash operator
* *
* @dataProvider invalid_bash_operators_provider * @dataProvider invalid_bash_operators_provider
*
* @param string $command Command to test.
*/ */
function test_for_invalid_bash_operators( $command ) { function test_for_invalid_bash_operators( $command ) {
$this->assertWPError( WP_CLI_Cron_Control_Offload\validate_command( $command ) ); $this->assertWPError( WP_CLI_Cron_Control_Offload\validate_command( $command ) );
} }
/**
* Data provider for unsupported bash operators
*
* @return array
*/
function invalid_bash_operators_provider() { function invalid_bash_operators_provider() {
return array( return array(
array( 'post list & date' ), array( 'post list & date' ),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment