Code Duplication    Length = 13-16 lines in 6 locations

projects/packages/sync/tests/php/test-rest-endpoints.php 3 locations

@@ 179-194 (lines=16) @@
176
	/**
177
	 * Testing the `/jetpack/v4/sync/now` endpoint.
178
	 */
179
	public function test_sync_now() {
180
181
		// TODO add items to queue to verify response.
182
183
		$user = wp_get_current_user();
184
		$user->add_cap( 'manage_options' );
185
186
		$request = new WP_REST_Request( 'POST', '/jetpack/v4/sync/now' );
187
		$request->set_header( 'Content-Type', 'application/json' );
188
		$request->set_body( '{ "queue": "sync" }' );
189
190
		$response = $this->server->dispatch( $request );
191
		$user->remove_cap( 'manage_options' );
192
193
		$this->assertEquals( 200, $response->get_status() );
194
	}
195
196
	/**
197
	 * Testing the `/jetpack/v4/sync/checkout` endpoint.
@@ 199-214 (lines=16) @@
196
	/**
197
	 * Testing the `/jetpack/v4/sync/checkout` endpoint.
198
	 */
199
	public function test_sync_checkout() {
200
201
		// TODO add items to queue to verify response.
202
203
		$user = wp_get_current_user();
204
		$user->add_cap( 'manage_options' );
205
206
		$request = new WP_REST_Request( 'POST', '/jetpack/v4/sync/now' );
207
		$request->set_header( 'Content-Type', 'application/json' );
208
		$request->set_body( '{ "queue": "sync", "number_of_items": 50 }' );
209
210
		$response = $this->server->dispatch( $request );
211
		$user->remove_cap( 'manage_options' );
212
213
		$this->assertEquals( 200, $response->get_status() );
214
	}
215
216
	/**
217
	 * Testing the `/jetpack/v4/sync/unlock` endpoint.
@@ 219-234 (lines=16) @@
216
	/**
217
	 * Testing the `/jetpack/v4/sync/unlock` endpoint.
218
	 */
219
	public function test_sync_unlock() {
220
221
		$user = wp_get_current_user();
222
		$user->add_cap( 'manage_options' );
223
224
		$request = new WP_REST_Request( 'POST', '/jetpack/v4/sync/unlock' );
225
		$request->set_header( 'Content-Type', 'application/json' );
226
		$request->set_body( '{ "queue": "sync" }' );
227
228
		$response = $this->server->dispatch( $request );
229
		$user->remove_cap( 'manage_options' );
230
231
		$this->assertEquals( 200, $response->get_status() );
232
		$this->assertFalse( get_option( 'jpsq_sync_checkout' ) );
233
234
	}
235
236
	/**
237
	 * Array of Sync Endpoints and method.

projects/packages/backup/tests/php/test-rest-controller.php 3 locations

@@ 90-102 (lines=13) @@
87
	/**
88
	 * Testing the `POST /jetpack/v4/backup-helper-script` endpoint with admin user.
89
	 */
90
	public function test_install_backup_helper_script_unauthorized() {
91
		wp_set_current_user( $this->admin_id );
92
93
		$body    = array(
94
			'helper' => 'dummy',
95
		);
96
		$request = new WP_REST_Request( 'POST', '/jetpack/v4/backup-helper-script' );
97
		$request->set_header( 'content-type', 'application/json' );
98
		$request->set_body( wp_json_encode( $body ) );
99
		$response = $this->server->dispatch( $request );
100
		$this->assertEquals( 403, $response->get_status() );
101
		$this->assertEquals( 'You are not allowed to perform this action.', $response->get_data()['message'] );
102
	}
103
104
	/**
105
	 * Testing the `POST /jetpack/v4/backup-helper-script` endpoint on success.
@@ 141-155 (lines=15) @@
138
	/**
139
	 * Testing the `DELETE /jetpack/v4/backup-helper-script` endpoint with admin user.
140
	 */
141
	public function test_delete_backup_helper_script_unauthorized() {
142
		wp_set_current_user( $this->admin_id );
143
144
		$body = array(
145
			'path' => 'dummy',
146
		);
147
148
		$request = new WP_REST_Request( 'DELETE', '/jetpack/v4/backup-helper-script' );
149
		$request->set_header( 'content-type', 'application/json' );
150
		$request->set_body( wp_json_encode( $body ) );
151
		$response = $this->server->dispatch( $request );
152
153
		$this->assertEquals( 403, $response->get_status() );
154
		$this->assertEquals( 'You are not allowed to perform this action.', $response->get_data()['message'] );
155
	}
156
157
	/**
158
	 * Testing the `DELETE /jetpack/v4/backup-helper-script` endpoint on success.
@@ 160-173 (lines=14) @@
157
	/**
158
	 * Testing the `DELETE /jetpack/v4/backup-helper-script` endpoint on success.
159
	 */
160
	public function test_delete_backup_helper_script_success() {
161
		$body = array(
162
			'path' => 'dummy',
163
		);
164
165
		$request = new WP_REST_Request( 'DELETE', '/jetpack/v4/backup-helper-script' );
166
		$request->set_header( 'content-type', 'application/json' );
167
		$request->set_body( wp_json_encode( $body ) );
168
169
		$response = $this->dispatch_request_signed_with_blog_token( $request );
170
		$this->assertEquals( 200, $response->get_status() );
171
172
		$this->assertTrue( $response->get_data()['success'] );
173
	}
174
175
	/**
176
	 * Testing the `/jetpack/v4/database-object/backup` endpoint with invalid params.