@@ 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. |
@@ 153-167 (lines=15) @@ | ||
150 | /** |
|
151 | * Testing the `DELETE /jetpack/v4/backup-helper-script` endpoint on success. |
|
152 | */ |
|
153 | public function test_delete_backup_helper_script_success() { |
|
154 | wp_set_current_user( 0 ); |
|
155 | $body = array( |
|
156 | 'path' => 'dummy', |
|
157 | ); |
|
158 | ||
159 | $request = new WP_REST_Request( 'DELETE', '/jetpack/v4/backup-helper-script' ); |
|
160 | $request->set_header( 'content-type', 'application/json' ); |
|
161 | $request->set_body( wp_json_encode( $body ) ); |
|
162 | ||
163 | $response = $this->dispatch_request_signed_with_blog_token( $request ); |
|
164 | $this->assertEquals( 200, $response->get_status() ); |
|
165 | ||
166 | $this->assertTrue( $response->get_data()['success'] ); |
|
167 | } |
|
168 | ||
169 | /** |
|
170 | * Signs a request with a blog token before dispatching it. |