@@ 340-362 (lines=23) @@ | ||
337 | /** |
|
338 | * Testing the `connection/register` endpoint. |
|
339 | */ |
|
340 | public function test_connection_register() { |
|
341 | add_filter( 'pre_http_request', array( static::class, 'intercept_register_request' ), 10, 3 ); |
|
342 | ||
343 | $this->request = new WP_REST_Request( 'POST', '/jetpack/v4/connection/register' ); |
|
344 | $this->request->set_header( 'Content-Type', 'application/json' ); |
|
345 | ||
346 | $this->request->set_body( wp_json_encode( array( 'registration_nonce' => wp_create_nonce( 'jetpack-registration-nonce' ) ) ) ); |
|
347 | ||
348 | $response = $this->server->dispatch( $this->request ); |
|
349 | $data = $response->get_data(); |
|
350 | ||
351 | remove_filter( 'pre_http_request', array( static::class, 'intercept_register_request' ), 10 ); |
|
352 | ||
353 | // Manually clears filter added by Manager::register(). |
|
354 | remove_filter( 'jetpack_use_iframe_authorization_flow', '__return_false', 20 ); |
|
355 | ||
356 | $this->assertEquals( 200, $response->get_status() ); |
|
357 | $this->assertSame( 0, strpos( $data['authorizeUrl'], 'https://jetpack.wordpress.com/jetpack.authorize/' ) ); |
|
358 | ||
359 | // Asserts jetpack_register_site_rest_response filter is being properly hooked to add data from wpcom register endpoint response. |
|
360 | $this->assertFalse( $data['allowInplaceAuthorization'] ); |
|
361 | $this->assertSame( '', $data['alternateAuthorizeUrl'] ); |
|
362 | } |
|
363 | ||
364 | /** |
|
365 | * Testing the `connection/register` endpoint with allow_inplace_authorization as true. |
|
@@ 391-413 (lines=23) @@ | ||
388 | /** |
|
389 | * Testing the `connection/register` endpoint with alternate_authorization_url |
|
390 | */ |
|
391 | public function test_connection_register_with_alternate_auth_url() { |
|
392 | add_filter( 'pre_http_request', array( static::class, 'intercept_register_request_with_alternate_auth_url' ), 10, 3 ); |
|
393 | ||
394 | $this->request = new WP_REST_Request( 'POST', '/jetpack/v4/connection/register' ); |
|
395 | $this->request->set_header( 'Content-Type', 'application/json' ); |
|
396 | ||
397 | $this->request->set_body( wp_json_encode( array( 'registration_nonce' => wp_create_nonce( 'jetpack-registration-nonce' ) ) ) ); |
|
398 | ||
399 | $response = $this->server->dispatch( $this->request ); |
|
400 | $data = $response->get_data(); |
|
401 | ||
402 | remove_filter( 'pre_http_request', array( static::class, 'intercept_register_request_with_alternate_auth_url' ), 10 ); |
|
403 | ||
404 | // Manually clears filter added by Manager::register(). |
|
405 | remove_filter( 'jetpack_use_iframe_authorization_flow', '__return_false', 20 ); |
|
406 | ||
407 | $this->assertEquals( 200, $response->get_status() ); |
|
408 | $this->assertSame( 0, strpos( $data['authorizeUrl'], 'https://jetpack.wordpress.com/jetpack.authorize/' ) ); |
|
409 | ||
410 | // Asserts jetpack_register_site_rest_response filter is being properly hooked to add data from wpcom register endpoint response. |
|
411 | $this->assertFalse( $data['allowInplaceAuthorization'] ); |
|
412 | $this->assertSame( Redirect::get_url( 'https://dummy.com' ), $data['alternateAuthorizeUrl'] ); |
|
413 | } |
|
414 | ||
415 | /** |
|
416 | * This filter callback allow us to skip the database query by `Jetpack_Options` to retrieve the option. |