Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-cli-cron-control-offload
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
WP Plugins
wp-cli-cron-control-offload
Commits
7e7fe4c9
Commit
7e7fe4c9
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Better tests
parent
35c2831f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/tests/class-plugin-functions.php
+51
-24
51 additions, 24 deletions
tests/tests/class-plugin-functions.php
with
51 additions
and
24 deletions
tests/tests/class-plugin-functions.php
+
51
−
24
View file @
7e7fe4c9
...
...
@@ -49,18 +49,34 @@ class Plugin_Functions extends WP_UnitTestCase {
/**
* Test whitelisted command validation
*
* @dataProvider whitelisted_command_provider
*/
function
test_whitelist_using_validate_command
()
{
$this
->
assertTrue
(
is_string
(
WP_CLI_Cron_Control_Offload\validate_command
(
'wp post list'
)
)
);
$this
->
assertTrue
(
is_string
(
WP_CLI_Cron_Control_Offload\validate_command
(
'post list'
)
)
);
function
test_whitelist_using_validate_command
(
$command
)
{
$this
->
assertTrue
(
is_string
(
WP_CLI_Cron_Control_Offload\validate_command
(
$command
)
)
);
}
function
whitelisted_command_provider
()
{
return
array
(
array
(
'wp post list'
),
array
(
'post list'
),
);
}
/**
* Test blacklisted command validation
*
* @dataProvider blacklisted_command_provider
*/
function
test_blacklist_using_validate_command
()
{
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\validate_command
(
'wp cli info'
)
)
);
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\validate_command
(
'cli info'
)
)
);
function
test_blacklist_using_validate_command
(
$command
)
{
$this
->
assertWPError
(
WP_CLI_Cron_Control_Offload\validate_command
(
$command
)
);
}
function
blacklisted_command_provider
()
{
return
array
(
array
(
'wp cli info'
),
array
(
'cli info'
),
);
}
/**
...
...
@@ -71,36 +87,47 @@ class Plugin_Functions extends WP_UnitTestCase {
$this
->
assertTrue
(
is_int
(
WP_CLI_Cron_Control_Offload\schedule_cli_command
(
'wp post list'
)
)
);
// Should be blocked as a duplicate, thanks to Core's 10-minute lookahead.
$this
->
assert
True
(
is_wp_e
rror
(
WP_CLI_Cron_Control_Offload\schedule_cli_command
(
'wp post list'
)
)
);
$this
->
assert
WPE
rror
(
WP_CLI_Cron_Control_Offload\schedule_cli_command
(
'wp post list'
)
);
// Should also fail as normalization makes it a duplicate.
$this
->
assert
True
(
is_wp_e
rror
(
WP_CLI_Cron_Control_Offload\schedule_cli_command
(
'post list'
)
)
);
$this
->
assert
WPE
rror
(
WP_CLI_Cron_Control_Offload\schedule_cli_command
(
'post list'
)
);
}
/**
* Test scheduling several of the same blocked event
*
* @dataProvider blocked_events_provider
*/
function
test_blocked_event_scheduling
()
{
// Should fail, is a blocked event.
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\schedule_cli_command
(
'wp cli info'
)
)
);
// Should fail as a blocked event, would otherwise fail as a duplicate.
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\schedule_cli_command
(
'wp cli info'
)
)
);
function
test_blocked_event_scheduling
(
$command
)
{
$this
->
assertWPError
(
WP_CLI_Cron_Control_Offload\schedule_cli_command
(
$command
)
);
}
// Should also fail as a blocked event, though normalization would also block it as a duplicate.
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\schedule_cli_command
(
'cli info'
)
)
);
function
blocked_events_provider
()
{
return
array
(
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
(
'cli info'
),
// Should also fail as a blocked event, though normalization would also block it as a duplicate.
);
}
/**
* Test each blocked bash operator
*
* @dataProvider invalid_bash_operators_provider
*/
function
test_for_invalid_bash_operators
()
{
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\validate_command
(
'post list & date'
)
)
);
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\validate_command
(
'post list | date'
)
)
);
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\validate_command
(
'post list > /tmp/nope'
)
)
);
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\validate_command
(
'post list 2> /tmp/nope'
)
)
);
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\validate_command
(
'post list 1>&2 /tmp/nope'
)
)
);
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\validate_command
(
'post list 2>&1 /tmp/nope'
)
)
);
$this
->
assertTrue
(
is_wp_error
(
WP_CLI_Cron_Control_Offload\validate_command
(
'post list &> /tmp/nope'
)
)
);
function
test_for_invalid_bash_operators
(
$command
)
{
$this
->
assertWPError
(
WP_CLI_Cron_Control_Offload\validate_command
(
$command
)
);
}
function
invalid_bash_operators_provider
()
{
return
array
(
array
(
'post list & date'
),
array
(
'post list | date'
),
array
(
'post list > /tmp/nope'
),
array
(
'post list 2> /tmp/nope'
),
array
(
'post list 1>&2 /tmp/nope'
),
array
(
'post list 2>&1 /tmp/nope'
),
array
(
'post list &> /tmp/nope'
),
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment