Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
Cron-Control
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
WP Plugins
Cron-Control
Commits
60baeb0d
Commit
60baeb0d
authored
Sep 10, 2017
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPCS fixes
parent
db7f4d31
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
tests/test-rest-api.php
tests/test-rest-api.php
+16
-10
No files found.
tests/test-rest-api.php
View file @
60baeb0d
<?php
/**
*
Class REST_API_Tests
*
Test plugin's REST API
*
* @package
Automatti
c_Cron_Control
* @package
a8
c_Cron_Control
*/
namespace
Automattic\WP\Cron_Control\Tests
;
/**
*
Sample test case.
*
REST API tests
*/
class
REST_API_Tests
extends
\
WP_UnitTestCase
{
/**
...
...
@@ -21,7 +21,7 @@ class REST_API_Tests extends \WP_UnitTestCase {
$this
->
server
=
$wp_rest_server
=
new
\
WP_REST_Server
;
do_action
(
'rest_api_init'
);
// make sure the schedule is clear
// make sure the schedule is clear
.
_set_cron_array
(
array
()
);
}
...
...
@@ -32,7 +32,7 @@ class REST_API_Tests extends \WP_UnitTestCase {
global
$wp_rest_server
;
$wp_rest_server
=
null
;
// make sure the schedule is clear
// make sure the schedule is clear
.
_set_cron_array
(
array
()
);
parent
::
tearDown
();
...
...
@@ -53,7 +53,7 @@ class REST_API_Tests extends \WP_UnitTestCase {
public
function
test_get_items
()
{
$ev
=
Utils
::
create_test_event
();
// Don't test internal events with this test
// Don't test internal events with this test
.
$internal_events
=
array
(
'a8c_cron_control_force_publish_missed_schedules'
,
'a8c_cron_control_confirm_scheduled_posts'
,
...
...
@@ -65,7 +65,9 @@ class REST_API_Tests extends \WP_UnitTestCase {
}
$request
=
new
\
WP_REST_Request
(
'POST'
,
'/'
.
\
Automattic\WP\Cron_Control\REST_API
::
API_NAMESPACE
.
'/'
.
\
Automattic\WP\Cron_Control\REST_API
::
ENDPOINT_LIST
);
$request
->
set_body
(
wp_json_encode
(
array
(
'secret'
=>
\
WP_CRON_CONTROL_SECRET
,
)
)
);
$request
->
set_body
(
wp_json_encode
(
array
(
'secret'
=>
\
WP_CRON_CONTROL_SECRET
,
)
)
);
$request
->
set_header
(
'content-type'
,
'application/json'
);
$response
=
$this
->
server
->
dispatch
(
$request
);
...
...
@@ -109,12 +111,13 @@ class REST_API_Tests extends \WP_UnitTestCase {
$this
->
assertResponseStatus
(
200
,
$response
);
$this
->
assertArrayHasKey
(
'success'
,
$data
);
$this
->
assertArrayHasKey
(
'message'
,
$data
);
}
/**
* Check response code
*
* @param string $status Status code.
* @param object $response REST API response object.
*/
protected
function
assertResponseStatus
(
$status
,
$response
)
{
$this
->
assertEquals
(
$status
,
$response
->
get_status
()
);
...
...
@@ -122,8 +125,11 @@ class REST_API_Tests extends \WP_UnitTestCase {
/**
* Ensure response includes the expected data
*
* @param array $data Expected data.
* @param object $response REST API response object.
*/
protected
function
assertResponseData
(
$data
,
$response
)
{
Utils
::
compare_arrays
(
$data
,
$response
->
get_data
(),
$this
);
}
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
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