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