|
@@ 76-91 (lines=16) @@
|
| 73 |
|
/** |
| 74 |
|
* Testing the `POST /jetpack/v4/backup-helper-script` endpoint with admin user. |
| 75 |
|
*/ |
| 76 |
|
public function test_install_backup_helper_script_unauthorized() { |
| 77 |
|
$user = wp_get_current_user(); |
| 78 |
|
$user->set_role( 'administrator' ); |
| 79 |
|
$body = array( |
| 80 |
|
'helper' => 'dummy', |
| 81 |
|
); |
| 82 |
|
$request = new WP_REST_Request( 'POST', '/jetpack/v4/backup-helper-script' ); |
| 83 |
|
$request->set_header( 'content-type', 'application/json' ); |
| 84 |
|
$request->set_body( wp_json_encode( $body ) ); |
| 85 |
|
$response = $this->server->dispatch( $request ); |
| 86 |
|
$this->assertEquals( 401, $response->get_status() ); |
| 87 |
|
$this->assertEquals( 'You are not allowed to perform this action.', $response->get_data()['message'] ); |
| 88 |
|
|
| 89 |
|
// Cleanup. |
| 90 |
|
$user->remove_role( 'administrator' ); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
/** |
| 94 |
|
* Testing the `POST /jetpack/v4/backup-helper-script` endpoint on success. |
|
@@ 131-146 (lines=16) @@
|
| 128 |
|
/** |
| 129 |
|
* Testing the `DELETE /jetpack/v4/backup-helper-script` endpoint with admin user. |
| 130 |
|
*/ |
| 131 |
|
public function test_delete_backup_helper_script_unauthorized() { |
| 132 |
|
$user = wp_get_current_user(); |
| 133 |
|
$user->set_role( 'administrator' ); |
| 134 |
|
$body = array( |
| 135 |
|
'path' => 'dummy', |
| 136 |
|
); |
| 137 |
|
|
| 138 |
|
$request = new WP_REST_Request( 'DELETE', '/jetpack/v4/backup-helper-script' ); |
| 139 |
|
$request->set_header( 'content-type', 'application/json' ); |
| 140 |
|
$request->set_body( wp_json_encode( $body ) ); |
| 141 |
|
$response = $this->server->dispatch( $request ); |
| 142 |
|
|
| 143 |
|
$this->assertEquals( 401, $response->get_status() ); |
| 144 |
|
$this->assertEquals( 'You are not allowed to perform this action.', $response->get_data()['message'] ); |
| 145 |
|
|
| 146 |
|
// Cleanup. |
| 147 |
|
$user->remove_role( 'administrator' ); |
| 148 |
|
} |
| 149 |
|
|