Changeset 48937 for trunk/tests/phpunit/tests/oembed/controller.php
- Timestamp:
- 09/02/2020 12:35:36 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/oembed/controller.php
r48135 r48937 176 176 177 177 function test_wp_oembed_ensure_format() { 178 $this->assert Equals( 'json', wp_oembed_ensure_format( 'json' ) );179 $this->assert Equals( 'xml', wp_oembed_ensure_format( 'xml' ) );180 $this->assert Equals( 'json', wp_oembed_ensure_format( 123 ) );181 $this->assert Equals( 'json', wp_oembed_ensure_format( 'random' ) );182 $this->assert Equals( 'json', wp_oembed_ensure_format( array() ) );178 $this->assertSame( 'json', wp_oembed_ensure_format( 'json' ) ); 179 $this->assertSame( 'xml', wp_oembed_ensure_format( 'xml' ) ); 180 $this->assertSame( 'json', wp_oembed_ensure_format( 123 ) ); 181 $this->assertSame( 'json', wp_oembed_ensure_format( 'random' ) ); 182 $this->assertSame( 'json', wp_oembed_ensure_format( array() ) ); 183 183 } 184 184 … … 266 266 $data = $response->get_data(); 267 267 268 $this->assert Equals( 'rest_no_route', $data['code'] );268 $this->assertSame( 'rest_no_route', $data['code'] ); 269 269 } 270 270 … … 275 275 $data = $response->get_data(); 276 276 277 $this->assert Equals( 'rest_missing_callback_param', $data['code'] );278 $this->assert Equals( 'url', $data['data']['params'][0] );277 $this->assertSame( 'rest_missing_callback_param', $data['code'] ); 278 $this->assertSame( 'url', $data['data']['params'][0] ); 279 279 } 280 280 … … 286 286 $data = $response->get_data(); 287 287 288 $this->assert Equals( 'oembed_invalid_url', $data['code'] );288 $this->assertSame( 'oembed_invalid_url', $data['code'] ); 289 289 } 290 290 … … 335 335 $this->assertArrayHasKey( 'width', $data ); 336 336 337 $this->assert Equals( '1.0', $data['version'] );338 $this->assert Equals( get_bloginfo( 'name' ), $data['provider_name'] );339 $this->assert Equals( home_url(), $data['provider_url'] );340 $this->assert Equals( $user->display_name, $data['author_name'] );341 $this->assert Equals( get_author_posts_url( $user->ID, $user->user_nicename ), $data['author_url'] );342 $this->assert Equals( $post->post_title, $data['title'] );343 $this->assert Equals( 'rich', $data['type'] );337 $this->assertSame( '1.0', $data['version'] ); 338 $this->assertSame( get_bloginfo( 'name' ), $data['provider_name'] ); 339 $this->assertSame( home_url(), $data['provider_url'] ); 340 $this->assertSame( $user->display_name, $data['author_name'] ); 341 $this->assertSame( get_author_posts_url( $user->ID, $user->user_nicename ), $data['author_url'] ); 342 $this->assertSame( $post->post_title, $data['title'] ); 343 $this->assertSame( 'rich', $data['type'] ); 344 344 $this->assertTrue( $data['width'] <= $request['maxwidth'] ); 345 345 } … … 378 378 $this->assertArrayHasKey( 'width', $data ); 379 379 380 $this->assert Equals( '1.0', $data['version'] );381 $this->assert Equals( get_bloginfo( 'name' ), $data['provider_name'] );382 $this->assert Equals( home_url(), $data['provider_url'] );383 $this->assert Equals( get_bloginfo( 'name' ), $data['author_name'] );384 $this->assert Equals( home_url(), $data['author_url'] );385 $this->assert Equals( $post->post_title, $data['title'] );386 $this->assert Equals( 'rich', $data['type'] );380 $this->assertSame( '1.0', $data['version'] ); 381 $this->assertSame( get_bloginfo( 'name' ), $data['provider_name'] ); 382 $this->assertSame( home_url(), $data['provider_url'] ); 383 $this->assertSame( get_bloginfo( 'name' ), $data['author_name'] ); 384 $this->assertSame( home_url(), $data['author_url'] ); 385 $this->assertSame( $post->post_title, $data['title'] ); 386 $this->assertSame( 'rich', $data['type'] ); 387 387 $this->assertTrue( $data['width'] <= $request['maxwidth'] ); 388 388 … … 423 423 $this->assertArrayHasKey( 'width', $data ); 424 424 425 $this->assert Equals( '1.0', $data['version'] );426 $this->assert Equals( get_bloginfo( 'name' ), $data['provider_name'] );427 $this->assert Equals( home_url(), $data['provider_url'] );428 $this->assert Equals( $user->display_name, $data['author_name'] );429 $this->assert Equals( get_author_posts_url( $user->ID, $user->user_nicename ), $data['author_url'] );430 $this->assert Equals( $post->post_title, $data['title'] );431 $this->assert Equals( 'rich', $data['type'] );425 $this->assertSame( '1.0', $data['version'] ); 426 $this->assertSame( get_bloginfo( 'name' ), $data['provider_name'] ); 427 $this->assertSame( home_url(), $data['provider_url'] ); 428 $this->assertSame( $user->display_name, $data['author_name'] ); 429 $this->assertSame( get_author_posts_url( $user->ID, $user->user_nicename ), $data['author_url'] ); 430 $this->assertSame( $post->post_title, $data['title'] ); 431 $this->assertSame( 'rich', $data['type'] ); 432 432 $this->assertTrue( $data['width'] <= $request['maxwidth'] ); 433 433 } … … 509 509 510 510 function test_get_oembed_endpoint_url() { 511 $this->assert Equals( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url() );512 $this->assert Equals( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url( '', 'json' ) );513 $this->assert Equals( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url( '', 'xml' ) );511 $this->assertSame( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url() ); 512 $this->assertSame( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url( '', 'json' ) ); 513 $this->assertSame( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url( '', 'xml' ) ); 514 514 515 515 $post_id = $this->factory()->post->create(); … … 517 517 $url_encoded = urlencode( $url ); 518 518 519 $this->assert Equals( home_url() . '/index.php?rest_route=%2Foembed%2F1.0%2Fembed&url=' . $url_encoded, get_oembed_endpoint_url( $url ) );520 $this->assert Equals( home_url() . '/index.php?rest_route=%2Foembed%2F1.0%2Fembed&url=' . $url_encoded . '&format=xml', get_oembed_endpoint_url( $url, 'xml' ) );519 $this->assertSame( home_url() . '/index.php?rest_route=%2Foembed%2F1.0%2Fembed&url=' . $url_encoded, get_oembed_endpoint_url( $url ) ); 520 $this->assertSame( home_url() . '/index.php?rest_route=%2Foembed%2F1.0%2Fembed&url=' . $url_encoded . '&format=xml', get_oembed_endpoint_url( $url, 'xml' ) ); 521 521 } 522 522 … … 524 524 update_option( 'permalink_structure', '/%postname%' ); 525 525 526 $this->assert Equals( home_url() . '/wp-json/oembed/1.0/embed', get_oembed_endpoint_url() );527 $this->assert Equals( home_url() . '/wp-json/oembed/1.0/embed', get_oembed_endpoint_url( '', 'xml' ) );526 $this->assertSame( home_url() . '/wp-json/oembed/1.0/embed', get_oembed_endpoint_url() ); 527 $this->assertSame( home_url() . '/wp-json/oembed/1.0/embed', get_oembed_endpoint_url( '', 'xml' ) ); 528 528 529 529 $post_id = $this->factory()->post->create(); … … 531 531 $url_encoded = urlencode( $url ); 532 532 533 $this->assert Equals( home_url() . '/wp-json/oembed/1.0/embed?url=' . $url_encoded, get_oembed_endpoint_url( $url ) );534 $this->assert Equals( home_url() . '/wp-json/oembed/1.0/embed?url=' . $url_encoded . '&format=xml', get_oembed_endpoint_url( $url, 'xml' ) );533 $this->assertSame( home_url() . '/wp-json/oembed/1.0/embed?url=' . $url_encoded, get_oembed_endpoint_url( $url ) ); 534 $this->assertSame( home_url() . '/wp-json/oembed/1.0/embed?url=' . $url_encoded . '&format=xml', get_oembed_endpoint_url( $url, 'xml' ) ); 535 535 536 536 update_option( 'permalink_structure', '' ); … … 542 542 $response = rest_get_server()->dispatch( $request ); 543 543 544 $this->assert Equals( 400, $response->get_status() );544 $this->assertSame( 400, $response->get_status() ); 545 545 546 546 // Test with a user that does not have edit_posts capability. … … 550 550 $response = rest_get_server()->dispatch( $request ); 551 551 552 $this->assert Equals( 403, $response->get_status() );552 $this->assertSame( 403, $response->get_status() ); 553 553 $data = $response->get_data(); 554 $this->assert Equals( $data['code'], 'rest_forbidden' );554 $this->assertSame( $data['code'], 'rest_forbidden' ); 555 555 } 556 556 … … 560 560 $request->set_param( 'url', self::INVALID_OEMBED_URL ); 561 561 $response = rest_get_server()->dispatch( $request ); 562 $this->assert Equals( 404, $response->get_status() );562 $this->assertSame( 404, $response->get_status() ); 563 563 $data = $response->get_data(); 564 $this->assert Equals( 'oembed_invalid_url', $data['code'] );564 $this->assertSame( 'oembed_invalid_url', $data['code'] ); 565 565 } 566 566 … … 571 571 $response = rest_get_server()->dispatch( $request ); 572 572 573 $this->assert Equals( 400, $response->get_status() );573 $this->assertSame( 400, $response->get_status() ); 574 574 } 575 575 … … 582 582 $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) ); 583 583 $response = rest_get_server()->dispatch( $request ); 584 $this->assert Equals( 200, $response->get_status() );585 $this->assert Equals( 1, $this->request_count );584 $this->assertSame( 200, $response->get_status() ); 585 $this->assertSame( 1, $this->request_count ); 586 586 587 587 // Subsequent request is cached and so it should not cause a request. 588 588 rest_get_server()->dispatch( $request ); 589 $this->assert Equals( 1, $this->request_count );589 $this->assertSame( 1, $this->request_count ); 590 590 591 591 // Rest with another user should also be cached. … … 597 597 $request->set_param( 'maxheight', 789 ); 598 598 $response = rest_get_server()->dispatch( $request ); 599 $this->assert Equals( 1, $this->request_count );599 $this->assertSame( 1, $this->request_count ); 600 600 601 601 // Test data object. … … 604 604 $this->assertNotEmpty( $data ); 605 605 $this->assertInternalType( 'object', $data ); 606 $this->assert Equals( 'YouTube', $data->provider_name );607 $this->assert Equals( 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', $data->thumbnail_url );606 $this->assertSame( 'YouTube', $data->provider_name ); 607 $this->assertSame( 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', $data->thumbnail_url ); 608 608 $this->assertEquals( $data->width, $request['maxwidth'] ); 609 609 $this->assertEquals( $data->height, $request['maxheight'] ); … … 623 623 $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) ); 624 624 $response = rest_get_server()->dispatch( $request ); 625 $this->assert Equals( 200, $response->get_status() );626 $this->assert Equals( 2, $this->request_count );625 $this->assertSame( 200, $response->get_status() ); 626 $this->assertSame( 2, $this->request_count ); 627 627 628 628 // Test data object. … … 643 643 $request->set_param( 'discover', false ); 644 644 $response = rest_get_server()->dispatch( $request ); 645 $this->assert Equals( 404, $response->get_status() );646 $this->assert Equals( 0, $this->request_count );645 $this->assertSame( 404, $response->get_status() ); 646 $this->assertSame( 0, $this->request_count ); 647 647 } 648 648 … … 654 654 $request->set_param( 'url', self::INVALID_OEMBED_URL ); 655 655 $response = rest_get_server()->dispatch( $request ); 656 $this->assert Equals( 404, $response->get_status() );657 $this->assert Equals( 1, $this->request_count );656 $this->assertSame( 404, $response->get_status() ); 657 $this->assertSame( 1, $this->request_count ); 658 658 } 659 659 … … 666 666 $response = rest_get_server()->dispatch( $request ); 667 667 668 $this->assert Equals( 400, $response->get_status() );668 $this->assertSame( 400, $response->get_status() ); 669 669 $data = $response->get_data(); 670 $this->assert Equals( $data['code'], 'rest_invalid_param' );670 $this->assertSame( $data['code'], 'rest_invalid_param' ); 671 671 } 672 672 … … 709 709 $this->assertArrayHasKey( 'width', $data ); 710 710 711 $this->assert Equals( '1.0', $data['version'] );712 $this->assert Equals( get_bloginfo( 'name' ), $data['provider_name'] );713 $this->assert Equals( home_url(), $data['provider_url'] );714 $this->assert Equals( $user->display_name, $data['author_name'] );715 $this->assert Equals( get_author_posts_url( $user->ID, $user->user_nicename ), $data['author_url'] );716 $this->assert Equals( $post->post_title, $data['title'] );717 $this->assert Equals( 'rich', $data['type'] );711 $this->assertSame( '1.0', $data['version'] ); 712 $this->assertSame( get_bloginfo( 'name' ), $data['provider_name'] ); 713 $this->assertSame( home_url(), $data['provider_url'] ); 714 $this->assertSame( $user->display_name, $data['author_name'] ); 715 $this->assertSame( get_author_posts_url( $user->ID, $user->user_nicename ), $data['author_url'] ); 716 $this->assertSame( $post->post_title, $data['title'] ); 717 $this->assertSame( 'rich', $data['type'] ); 718 718 $this->assertTrue( $data['width'] <= $request['maxwidth'] ); 719 719 } … … 758 758 $this->assertArrayHasKey( 'width', $data ); 759 759 760 $this->assert Equals( '1.0', $data['version'] );761 $this->assert Equals( get_bloginfo( 'name' ), $data['provider_name'] );762 $this->assert Equals( home_url(), $data['provider_url'] );763 $this->assert Equals( get_bloginfo( 'name' ), $data['author_name'] );764 $this->assert Equals( home_url(), $data['author_url'] );765 $this->assert Equals( $post->post_title, $data['title'] );766 $this->assert Equals( 'rich', $data['type'] );760 $this->assertSame( '1.0', $data['version'] ); 761 $this->assertSame( get_bloginfo( 'name' ), $data['provider_name'] ); 762 $this->assertSame( home_url(), $data['provider_url'] ); 763 $this->assertSame( get_bloginfo( 'name' ), $data['author_name'] ); 764 $this->assertSame( home_url(), $data['author_url'] ); 765 $this->assertSame( $post->post_title, $data['title'] ); 766 $this->assertSame( 'rich', $data['type'] ); 767 767 $this->assertTrue( $data['width'] <= $request['maxwidth'] ); 768 768 … … 785 785 $data = $response->get_data(); 786 786 787 $this->assert Equals( 1, $this->oembed_result_filter_count );787 $this->assertSame( 1, $this->oembed_result_filter_count ); 788 788 $this->assertInternalType( 'object', $data ); 789 $this->assert Equals( 'Untrusted', $data->provider_name );790 $this->assert Equals( self::UNTRUSTED_PROVIDER_URL, $data->provider_url );791 $this->assert Equals( 'rich', $data->type );789 $this->assertSame( 'Untrusted', $data->provider_name ); 790 $this->assertSame( self::UNTRUSTED_PROVIDER_URL, $data->provider_url ); 791 $this->assertSame( 'rich', $data->type ); 792 792 $this->assertFalse( $data->html ); 793 793 } … … 808 808 $data = $response->get_data(); 809 809 810 $this->assert Equals( 1, $this->oembed_result_filter_count );810 $this->assertSame( 1, $this->oembed_result_filter_count ); 811 811 $this->assertInternalType( 'object', $data ); 812 812
Note: See TracChangeset
for help on using the changeset viewer.