Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
WP Plugins
Cron-Control
Commits
19a1e932
Verified
Commit
19a1e932
authored
Nov 11, 2016
by
Erick Hitter
Browse files
Improve test for events list by adding an event
parent
7408b779
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/test-rest-api.php
View file @
19a1e932
...
...
@@ -33,6 +33,8 @@ class WPCCR_REST_API_Test extends WP_UnitTestCase {
* Test that list endpoint returns expected format
*/
public
function
test_get_items
()
{
$ev
=
$this
->
create_test_event
();
$request
=
new
WP_REST_Request
(
'POST'
,
'/'
.
WP_Cron_Control_Revisited\REST_API_NAMESPACE
.
'/'
.
WP_Cron_Control_Revisited\REST_API_ENDPOINT_LIST
);
$request
->
set_body
(
wp_json_encode
(
array
(
'secret'
=>
WP_CRON_CONTROL_SECRET
,
)
)
);
$request
->
set_header
(
'content-type'
,
'application/json'
);
...
...
@@ -43,12 +45,40 @@ class WPCCR_REST_API_Test extends WP_UnitTestCase {
$this
->
assertResponseStatus
(
200
,
$response
);
$this
->
assertArrayHasKey
(
'events'
,
$data
);
$this
->
assertArrayHasKey
(
'endpoint'
,
$data
);
$this
->
assertResponseData
(
array
(
'events'
=>
array
(),
'events'
=>
array
(
array
(
'timestamp'
=>
$ev
[
'timestamp'
],
'action'
=>
md5
(
$ev
[
'action'
]
),
'instance'
=>
md5
(
serialize
(
$ev
[
'args'
]
)
),
),
),
'endpoint'
=>
get_rest_url
(
null
,
WP_Cron_Control_Revisited\REST_API_NAMESPACE
.
'/'
.
WP_Cron_Control_Revisited\REST_API_ENDPOINT_RUN
),
),
$response
);
}
/**
* Build a test event
*/
protected
function
create_test_event
()
{
$event
=
array
(
'timestamp'
=>
time
(),
'action'
=>
'wpccr_test_event'
,
'args'
=>
array
(),
);
$next
=
wp_next_scheduled
(
$event
[
'action'
],
$event
[
'args'
]
);
if
(
$next
)
{
$event
[
'timestamp'
]
=
$next
;
}
else
{
wp_schedule_single_event
(
$event
[
'timestamp'
],
$event
[
'action'
],
$event
[
'args'
]
);
}
return
$event
;
}
/**
* Check response code
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment