|
@@ 365-387 (lines=23) @@
|
| 362 |
|
/** |
| 363 |
|
* Testing the `connection/register` endpoint. |
| 364 |
|
*/ |
| 365 |
|
public function test_connection_register() { |
| 366 |
|
add_filter( 'pre_http_request', array( static::class, 'intercept_register_request' ), 10, 3 ); |
| 367 |
|
|
| 368 |
|
$this->request = new WP_REST_Request( 'POST', '/jetpack/v4/connection/register' ); |
| 369 |
|
$this->request->set_header( 'Content-Type', 'application/json' ); |
| 370 |
|
|
| 371 |
|
$this->request->set_body( wp_json_encode( array( 'registration_nonce' => wp_create_nonce( 'jetpack-registration-nonce' ) ) ) ); |
| 372 |
|
|
| 373 |
|
$response = $this->server->dispatch( $this->request ); |
| 374 |
|
$data = $response->get_data(); |
| 375 |
|
|
| 376 |
|
remove_filter( 'pre_http_request', array( static::class, 'intercept_register_request' ), 10 ); |
| 377 |
|
|
| 378 |
|
// Manually clears filter added by Manager::register(). |
| 379 |
|
remove_filter( 'jetpack_use_iframe_authorization_flow', '__return_false', 20 ); |
| 380 |
|
|
| 381 |
|
$this->assertEquals( 200, $response->get_status() ); |
| 382 |
|
$this->assertSame( 0, strpos( $data['authorizeUrl'], 'https://jetpack.wordpress.com/jetpack.authorize/' ) ); |
| 383 |
|
|
| 384 |
|
// Asserts jetpack_register_site_rest_response filter is being properly hooked to add data from wpcom register endpoint response. |
| 385 |
|
$this->assertFalse( $data['allowInplaceAuthorization'] ); |
| 386 |
|
$this->assertSame( '', $data['alternateAuthorizeUrl'] ); |
| 387 |
|
} |
| 388 |
|
|
| 389 |
|
/** |
| 390 |
|
* Testing the `connection/register` endpoint with allow_inplace_authorization as true. |
|
@@ 416-438 (lines=23) @@
|
| 413 |
|
/** |
| 414 |
|
* Testing the `connection/register` endpoint with alternate_authorization_url |
| 415 |
|
*/ |
| 416 |
|
public function test_connection_register_with_alternate_auth_url() { |
| 417 |
|
add_filter( 'pre_http_request', array( static::class, 'intercept_register_request_with_alternate_auth_url' ), 10, 3 ); |
| 418 |
|
|
| 419 |
|
$this->request = new WP_REST_Request( 'POST', '/jetpack/v4/connection/register' ); |
| 420 |
|
$this->request->set_header( 'Content-Type', 'application/json' ); |
| 421 |
|
|
| 422 |
|
$this->request->set_body( wp_json_encode( array( 'registration_nonce' => wp_create_nonce( 'jetpack-registration-nonce' ) ) ) ); |
| 423 |
|
|
| 424 |
|
$response = $this->server->dispatch( $this->request ); |
| 425 |
|
$data = $response->get_data(); |
| 426 |
|
|
| 427 |
|
remove_filter( 'pre_http_request', array( static::class, 'intercept_register_request_with_alternate_auth_url' ), 10 ); |
| 428 |
|
|
| 429 |
|
// Manually clears filter added by Manager::register(). |
| 430 |
|
remove_filter( 'jetpack_use_iframe_authorization_flow', '__return_false', 20 ); |
| 431 |
|
|
| 432 |
|
$this->assertEquals( 200, $response->get_status() ); |
| 433 |
|
$this->assertSame( 0, strpos( $data['authorizeUrl'], 'https://jetpack.wordpress.com/jetpack.authorize/' ) ); |
| 434 |
|
|
| 435 |
|
// Asserts jetpack_register_site_rest_response filter is being properly hooked to add data from wpcom register endpoint response. |
| 436 |
|
$this->assertFalse( $data['allowInplaceAuthorization'] ); |
| 437 |
|
$this->assertSame( Redirect::get_url( 'https://dummy.com' ), $data['alternateAuthorizeUrl'] ); |
| 438 |
|
} |
| 439 |
|
|
| 440 |
|
/** |
| 441 |
|
* Testing the `user-token` endpoint without authentication. |