Skip to content

Commit 740e3a4

Browse files
committed
Update CMB2 REST API test coverage.. Should all be covered now
1 parent f9bde33 commit 740e3a4

File tree

2 files changed

+233
-116
lines changed

2 files changed

+233
-116
lines changed

tests/cmb-rest-tests-base.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,42 @@ public function tearDown() {
2323
parent::tearDown();
2424
}
2525

26-
protected function assertResponseStatuses( $url, $statuses ) {
27-
foreach ( $statuses as $method => $code ) {
28-
$this->assertResponseStatus( $code, rest_do_request( new WP_REST_Request( $method, $url ) ) );
26+
protected function assertResponseStatuses( $url, $statuses, $debug = false ) {
27+
foreach ( $statuses as $method => $status ) {
28+
$error_code = '';
29+
30+
if ( is_array( $status ) ) {
31+
$error_code = current( $status );
32+
$status = key( $status );
33+
}
34+
35+
$this->assertRequestResponseStatus( $method, $url, $status, $error_code, $debug );
2936
}
3037
}
3138

32-
protected function assertResponseStatus( $status, $response ) {
39+
protected function assertRequestResponseStatus( $method, $url, $status, $error_code = '', $debug = false ) {
40+
if ( $debug ) {
41+
error_log( $method . ' $url: '. print_r( $url, true ) );
42+
}
43+
44+
$request = new WP_REST_Request( $method, $url );
45+
$this->assertResponseStatus( $status, rest_do_request( $request ), $error_code, $debug );
46+
}
47+
48+
protected function assertResponseStatus( $status, $response, $error_code = '', $debug = false ) {
49+
if ( $debug ) {
50+
error_log( '$response->get_data(): '. print_r( $response->get_data(), true ) );
51+
}
3352
$this->assertEquals( $status, $response->get_status() );
53+
54+
if ( $error_code ) {
55+
$this->assertResponseErrorCode( $error_code, $response );
56+
}
57+
}
58+
59+
protected function assertResponseErrorCode( $error_code, $response ) {
60+
$response_data = $response->get_data();
61+
$this->assertEquals( $error_code, $response_data['code'] );
3462
}
3563

3664
protected function assertResponseData( $data, $response ) {

0 commit comments

Comments
 (0)