Changeset 42724 for trunk/tests/phpunit/tests/oembed/controller.php
- Timestamp:
- 02/21/2018 04:24:30 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/oembed/controller.php
r42343 r42724 46 46 /** @var WP_REST_Server $wp_rest_server */ 47 47 global $wp_rest_server; 48 $ this->server = $wp_rest_server = new Spy_REST_Server();49 50 do_action( 'rest_api_init', $this->server ); 48 $wp_rest_server = new Spy_REST_Server; 49 do_action( 'rest_api_init', $wp_rest_server ); 50 51 51 add_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 ); 52 52 $this->request_count = 0; … … 55 55 public function tearDown() { 56 56 parent::tearDown(); 57 /** @var WP_REST_Server $wp_rest_server */ 58 global $wp_rest_server; 59 $wp_rest_server = null; 57 60 58 61 remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10 ); … … 180 183 public function test_route_availability() { 181 184 // Check the route was registered correctly. 182 $filtered_routes = $this->server->get_routes();185 $filtered_routes = rest_get_server()->get_routes(); 183 186 $this->assertArrayHasKey( '/oembed/1.0/embed', $filtered_routes ); 184 187 $route = $filtered_routes['/oembed/1.0/embed']; … … 201 204 $request = new WP_REST_Request( 'POST', '/oembed/1.0/embed' ); 202 205 203 $response = $this->server->dispatch( $request );206 $response = rest_get_server()->dispatch( $request ); 204 207 $data = $response->get_data(); 205 208 … … 210 213 $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' ); 211 214 212 $response = $this->server->dispatch( $request );215 $response = rest_get_server()->dispatch( $request ); 213 216 $data = $response->get_data(); 214 217 … … 221 224 $request->set_param( 'url', 'http://google.com/' ); 222 225 223 $response = $this->server->dispatch( $request );226 $response = rest_get_server()->dispatch( $request ); 224 227 $data = $response->get_data(); 225 228 … … 234 237 $request->set_param( 'format', 'random' ); 235 238 236 $response = $this->server->dispatch( $request );239 $response = rest_get_server()->dispatch( $request ); 237 240 $data = $response->get_data(); 238 241 … … 258 261 $request->set_param( 'maxwidth', 400 ); 259 262 260 $response = $this->server->dispatch( $request );263 $response = rest_get_server()->dispatch( $request ); 261 264 $data = $response->get_data(); 262 265 … … 301 304 $request->set_param( 'maxwidth', 400 ); 302 305 303 $response = $this->server->dispatch( $request );306 $response = rest_get_server()->dispatch( $request ); 304 307 $data = $response->get_data(); 305 308 … … 346 349 $request->set_param( 'maxwidth', 400 ); 347 350 348 $response = $this->server->dispatch( $request );351 $response = rest_get_server()->dispatch( $request ); 349 352 $data = $response->get_data(); 350 353 … … 389 392 $request->set_param( 'maxwidth', 400 ); 390 393 391 $response = $this->server->dispatch( $request );394 $response = rest_get_server()->dispatch( $request ); 392 395 $data = $response->get_data(); 393 396 … … 415 418 $request->set_param( 'format', 'xml' ); 416 419 417 $response = $this->server->dispatch( $request );418 $output = get_echo( '_oembed_rest_pre_serve_request', array( true, $response, $request, $this->server) );420 $response = rest_get_server()->dispatch( $request ); 421 $output = get_echo( '_oembed_rest_pre_serve_request', array( true, $response, $request, rest_get_server() ) ); 419 422 420 423 $xml = simplexml_load_string( $output ); … … 429 432 $request->set_param( 'format', 'json' ); 430 433 431 $response = $this->server->dispatch( $request );432 433 $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, $this->server) );434 $response = rest_get_server()->dispatch( $request ); 435 436 $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, rest_get_server() ) ); 434 437 } 435 438 … … 441 444 $request->set_param( 'format', 'xml' ); 442 445 443 $response = $this->server->dispatch( $request );444 445 $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, $this->server) );446 $response = rest_get_server()->dispatch( $request ); 447 448 $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, rest_get_server() ) ); 446 449 } 447 450 … … 478 481 // Test without a login. 479 482 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); 480 $response = $this->server->dispatch( $request );483 $response = rest_get_server()->dispatch( $request ); 481 484 482 485 $this->assertEquals( 400, $response->get_status() ); … … 486 489 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); 487 490 $request->set_param( 'url', self::INVALID_OEMBED_URL ); 488 $response = $this->server->dispatch( $request );491 $response = rest_get_server()->dispatch( $request ); 489 492 490 493 $this->assertEquals( 403, $response->get_status() ); … … 497 500 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); 498 501 $request->set_param( 'url', self::INVALID_OEMBED_URL ); 499 $response = $this->server->dispatch( $request );502 $response = rest_get_server()->dispatch( $request ); 500 503 $this->assertEquals( 404, $response->get_status() ); 501 504 $data = $response->get_data(); … … 507 510 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); 508 511 $request->set_param( 'type', 'xml' ); 509 $response = $this->server->dispatch( $request );512 $response = rest_get_server()->dispatch( $request ); 510 513 511 514 $this->assertEquals( 400, $response->get_status() ); … … 519 522 $request->set_param( 'maxheight', 789 ); 520 523 $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) ); 521 $response = $this->server->dispatch( $request );524 $response = rest_get_server()->dispatch( $request ); 522 525 $this->assertEquals( 200, $response->get_status() ); 523 526 $this->assertEquals( 1, $this->request_count ); 524 527 525 528 // Subsequent request is cached and so it should not cause a request. 526 $this->server->dispatch( $request );529 rest_get_server()->dispatch( $request ); 527 530 $this->assertEquals( 1, $this->request_count ); 528 531 … … 534 537 $request->set_param( 'maxwidth', 456 ); 535 538 $request->set_param( 'maxheight', 789 ); 536 $response = $this->server->dispatch( $request );539 $response = rest_get_server()->dispatch( $request ); 537 540 $this->assertEquals( 1, $this->request_count ); 538 541 … … 555 558 $request->set_param( 'url', self::INVALID_OEMBED_URL ); 556 559 $request->set_param( 'discover', 0 ); 557 $response = $this->server->dispatch( $request );560 $response = rest_get_server()->dispatch( $request ); 558 561 $this->assertEquals( 404, $response->get_status() ); 559 562 $this->assertEquals( 0, $this->request_count ); … … 566 569 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); 567 570 $request->set_param( 'url', self::INVALID_OEMBED_URL ); 568 $response = $this->server->dispatch( $request );571 $response = rest_get_server()->dispatch( $request ); 569 572 $this->assertEquals( 404, $response->get_status() ); 570 573 $this->assertEquals( 1, $this->request_count ); … … 577 580 $request->set_param( 'discover', 'notaboolean' ); 578 581 579 $response = $this->server->dispatch( $request );582 $response = rest_get_server()->dispatch( $request ); 580 583 581 584 $this->assertEquals( 400, $response->get_status() );
Note: See TracChangeset
for help on using the changeset viewer.