Code Duplication    Length = 16-18 lines in 5 locations

projects/packages/identity-crisis/tests/php/test-rest-endpoints.php 1 location

@@ 160-175 (lines=16) @@
157
	/**
158
	 * Testing the `/jetpack/v4/identity-crisis/start-fresh` endpoint.
159
	 */
160
	public function test_start_fresh() {
161
162
		$user = wp_get_current_user();
163
		$user->add_cap( 'jetpack_disconnect' );
164
165
		$request = new WP_REST_Request( 'POST', '/jetpack/v4/identity-crisis/start-fresh' );
166
		$request->set_header( 'Content-Type', 'application/json' );
167
168
		$response = $this->server->dispatch( $request );
169
		$data     = $response->get_data();
170
171
		$user->remove_cap( 'jetpack_disconnect' );
172
173
		$this->assertEquals( 200, $response->get_status() );
174
		$this->assertSame( '', $data );
175
	}
176
177
	/**
178
	 * Testing the `/jetpack/v4/identity-crisis/start-fresh` endpoint returns an error when user does not have permissions.

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

@@ 76-93 (lines=18) @@
73
	/**
74
	 * Testing the `/jetpack/v4/sync/settings` GET endpoint.
75
	 */
76
	public function test_sync_settings() {
77
78
		$settings = Settings::get_settings();
79
80
		$user = wp_get_current_user();
81
		$user->add_cap( 'manage_options' );
82
83
		$request = new WP_REST_Request( 'GET', '/jetpack/v4/sync/settings' );
84
		$request->set_header( 'Content-Type', 'application/json' );
85
86
		$response = $this->server->dispatch( $request );
87
		$data     = $response->get_data();
88
89
		$user->remove_cap( 'manage_options' );
90
91
		$this->assertEquals( 200, $response->get_status() );
92
		$this->assertEquals( $settings, $data );
93
	}
94
95
	/**
96
	 * Testing the `/jetpack/v4/sync/settings` POST endpoint.
@@ 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.