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