Changeset 48937 for trunk/tests/phpunit/tests/rest-api.php
- Timestamp:
- 09/02/2020 12:35:36 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api.php
r48881 r48937 43 43 */ 44 44 function test_init_action_added() { 45 $this->assert Equals( 10, has_action( 'init', 'rest_api_init' ) );45 $this->assertSame( 10, has_action( 'init', 'rest_api_init' ) ); 46 46 } 47 47 … … 49 49 $taxonomy = get_taxonomy( 'category' ); 50 50 $this->assertTrue( $taxonomy->show_in_rest ); 51 $this->assert Equals( 'categories', $taxonomy->rest_base );52 $this->assert Equals( 'WP_REST_Terms_Controller', $taxonomy->rest_controller_class );51 $this->assertSame( 'categories', $taxonomy->rest_base ); 52 $this->assertSame( 'WP_REST_Terms_Controller', $taxonomy->rest_controller_class ); 53 53 54 54 $taxonomy = get_taxonomy( 'post_tag' ); 55 55 $this->assertTrue( $taxonomy->show_in_rest ); 56 $this->assert Equals( 'tags', $taxonomy->rest_base );57 $this->assert Equals( 'WP_REST_Terms_Controller', $taxonomy->rest_controller_class );56 $this->assertSame( 'tags', $taxonomy->rest_base ); 57 $this->assertSame( 'WP_REST_Terms_Controller', $taxonomy->rest_controller_class ); 58 58 } 59 59 … … 61 61 $post_type = get_post_type_object( 'post' ); 62 62 $this->assertTrue( $post_type->show_in_rest ); 63 $this->assert Equals( 'posts', $post_type->rest_base );64 $this->assert Equals( 'WP_REST_Posts_Controller', $post_type->rest_controller_class );63 $this->assertSame( 'posts', $post_type->rest_base ); 64 $this->assertSame( 'WP_REST_Posts_Controller', $post_type->rest_controller_class ); 65 65 66 66 $post_type = get_post_type_object( 'page' ); 67 67 $this->assertTrue( $post_type->show_in_rest ); 68 $this->assert Equals( 'pages', $post_type->rest_base );69 $this->assert Equals( 'WP_REST_Posts_Controller', $post_type->rest_controller_class );68 $this->assertSame( 'pages', $post_type->rest_base ); 69 $this->assertSame( 'WP_REST_Posts_Controller', $post_type->rest_controller_class ); 70 70 71 71 $post_type = get_post_type_object( 'attachment' ); 72 72 $this->assertTrue( $post_type->show_in_rest ); 73 $this->assert Equals( 'media', $post_type->rest_base );74 $this->assert Equals( 'WP_REST_Attachments_Controller', $post_type->rest_controller_class );73 $this->assertSame( 'media', $post_type->rest_base ); 74 $this->assertSame( 'WP_REST_Attachments_Controller', $post_type->rest_controller_class ); 75 75 } 76 76 … … 99 99 $this->assertArrayNotHasKey( 'callback', $endpoint ); 100 100 $this->assertArrayHasKey( 'namespace', $endpoint ); 101 $this->assert Equals( 'test-ns', $endpoint['namespace'] );101 $this->assertSame( 'test-ns', $endpoint['namespace'] ); 102 102 103 103 // Grab the filtered data. … … 142 142 $this->assertArrayNotHasKey( 'callback', $endpoint ); 143 143 $this->assertArrayHasKey( 'namespace', $endpoint ); 144 $this->assert Equals( 'test-ns', $endpoint['namespace'] );144 $this->assertSame( 'test-ns', $endpoint['namespace'] ); 145 145 146 146 $filtered_endpoints = $GLOBALS['wp_rest_server']->get_routes(); … … 282 282 $routes = $GLOBALS['wp_rest_server']->get_routes(); 283 283 284 $this->assert Equals( $routes['/test-ns/test'][0]['methods'], array( 'GET' => true ) );284 $this->assertSame( $routes['/test-ns/test'][0]['methods'], array( 'GET' => true ) ); 285 285 } 286 286 … … 301 301 $routes = $GLOBALS['wp_rest_server']->get_routes(); 302 302 303 $this->assert Equals( $routes['/test-ns/test'][0]['methods'], array( 'GET' => true ) );303 $this->assertSame( $routes['/test-ns/test'][0]['methods'], array( 'GET' => true ) ); 304 304 } 305 305 … … 320 320 $routes = $GLOBALS['wp_rest_server']->get_routes(); 321 321 322 $this->assert Equals(322 $this->assertSame( 323 323 $routes['/test-ns/test'][0]['methods'], 324 324 array( … … 345 345 $routes = $GLOBALS['wp_rest_server']->get_routes(); 346 346 347 $this->assert Equals(347 $this->assertSame( 348 348 $routes['/test-ns/test'][0]['methods'], 349 349 array( … … 371 371 $this->assertArrayHasKey( 'Allow', $headers ); 372 372 373 $this->assert Equals( 'GET, POST', $headers['Allow'] );373 $this->assertSame( 'GET, POST', $headers['Allow'] ); 374 374 } 375 375 … … 403 403 404 404 $response = rest_filter_response_fields( $response, null, $request ); 405 $this->assert Equals( array( 'a' => true ), $response->get_data() );405 $this->assertSame( array( 'a' => true ), $response->get_data() ); 406 406 } 407 407 … … 423 423 424 424 $response = rest_filter_response_fields( $response, null, $request ); 425 $this->assert Equals( array( 'b' => 1 ), $response->get_data() );425 $this->assertSame( array( 'b' => 1 ), $response->get_data() ); 426 426 } 427 427 … … 446 446 447 447 $response = rest_filter_response_fields( $response, null, $request ); 448 $this->assert Equals(448 $this->assertSame( 449 449 array( 450 450 'b' => 1, … … 478 478 479 479 $response = rest_filter_response_fields( $response, null, $request ); 480 $this->assert Equals(480 $this->assertSame( 481 481 array( 482 482 'b' => 1, … … 517 517 518 518 $response = rest_filter_response_fields( $response, null, $request ); 519 $this->assert Equals(519 $this->assertSame( 520 520 array( 521 521 array( … … 563 563 564 564 $response = rest_filter_response_fields( $response, null, $request ); 565 $this->assert Equals(565 $this->assertSame( 566 566 array( 567 567 'b' => array( … … 604 604 605 605 $response = rest_filter_response_fields( $response, null, $request ); 606 $this->assert Equals(606 $this->assertSame( 607 607 array( 608 608 'field' => array( … … 640 640 641 641 $response = rest_filter_response_fields( $response, null, $request ); 642 $this->assert Equals(642 $this->assertSame( 643 643 array( 644 644 'meta' => array( … … 672 672 673 673 $response = rest_filter_response_fields( $response, null, $request ); 674 $this->assert Equals(674 $this->assertSame( 675 675 array( 676 676 'meta' => array( … … 704 704 705 705 $response = rest_filter_response_fields( $response, null, $request ); 706 $this->assert Equals(706 $this->assertSame( 707 707 array( 708 708 'meta' => array( … … 746 746 // In pretty permalinks case, we expect a path of wp-json/ with no query. 747 747 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 748 $this->assert Equals( 'http://' . WP_TESTS_DOMAIN . '/wp-json/', get_rest_url() );748 $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/wp-json/', get_rest_url() ); 749 749 750 750 // In index permalinks case, we expect a path of index.php/wp-json/ with no query. 751 751 $this->set_permalink_structure( '/index.php/%year%/%monthnum%/%day%/%postname%/' ); 752 $this->assert Equals( 'http://' . WP_TESTS_DOMAIN . '/index.php/wp-json/', get_rest_url() );752 $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/index.php/wp-json/', get_rest_url() ); 753 753 754 754 // In non-pretty case, we get a query string to invoke the rest router. 755 755 $this->set_permalink_structure( '' ); 756 $this->assert Equals( 'http://' . WP_TESTS_DOMAIN . '/index.php?rest_route=/', get_rest_url() );756 $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/index.php?rest_route=/', get_rest_url() ); 757 757 } 758 758 … … 808 808 get_rest_url(); 809 809 $args = $filter->get_args(); 810 $this->assert Equals( '/', $args[0][1] );810 $this->assertSame( '/', $args[0][1] ); 811 811 $filter->reset(); 812 812 … … 814 814 get_rest_url( null, 'wp/media/' ); 815 815 $args = $filter->get_args(); 816 $this->assert Equals( '/wp/media/', $args[0][1] );816 $this->assertSame( '/wp/media/', $args[0][1] ); 817 817 $filter->reset(); 818 818 … … 820 820 get_rest_url( null, '/wp/media/' ); 821 821 $args = $filter->get_args(); 822 $this->assert Equals( '/wp/media/', $args[0][1] );822 $this->assertSame( '/wp/media/', $args[0][1] ); 823 823 824 824 unset( $filter ); … … 847 847 */ 848 848 public function test_jsonp_callback_check( $callback, $valid ) { 849 $this->assert Equals( $valid, wp_check_jsonp_callback( $callback ) );849 $this->assertSame( $valid, wp_check_jsonp_callback( $callback ) ); 850 850 } 851 851 … … 911 911 */ 912 912 public function test_rest_parse_date_force_utc( $string, $value ) { 913 $this->assert Equals( $value, rest_parse_date( $string, true ) );913 $this->assertSame( $value, rest_parse_date( $string, true ) ); 914 914 } 915 915 … … 933 933 934 934 $routes = $GLOBALS['wp_rest_server']->get_routes(); 935 $this->assert Equals( $routes['/test-ns/test'][0]['methods'], array( 'GET' => true ) );935 $this->assertSame( $routes['/test-ns/test'][0]['methods'], array( 'GET' => true ) ); 936 936 } 937 937 … … 963 963 $request = rest_ensure_request( '/wp/v2/posts' ); 964 964 $this->assertInstanceOf( 'WP_REST_Request', $request ); 965 $this->assert Equals( '/wp/v2/posts', $request->get_route() );966 $this->assert Equals( 'GET', $request->get_method() );965 $this->assertSame( '/wp/v2/posts', $request->get_route() ); 966 $this->assertSame( 'GET', $request->get_method() ); 967 967 } 968 968 … … 971 971 */ 972 972 public function test_rest_parse_embed_param( $expected, $embed ) { 973 $this->assert Equals( $expected, rest_parse_embed_param( $embed ) );973 $this->assertSame( $expected, rest_parse_embed_param( $embed ) ); 974 974 } 975 975 … … 1000 1000 */ 1001 1001 public function test_rest_filter_response_by_context( $schema, $data, $expected ) { 1002 $this->assert Equals( $expected, rest_filter_response_by_context( $data, $schema, 'view' ) );1002 $this->assertSame( $expected, rest_filter_response_by_context( $data, $schema, 'view' ) ); 1003 1003 } 1004 1004 … … 1553 1553 */ 1554 1554 public function test_rest_get_route_for_post_non_post() { 1555 $this->assert Equals( '', rest_get_route_for_post( 'garbage' ) );1555 $this->assertSame( '', rest_get_route_for_post( 'garbage' ) ); 1556 1556 } 1557 1557 … … 1564 1564 unregister_post_type( 'invalid' ); 1565 1565 1566 $this->assert Equals( '', rest_get_route_for_post( $post ) );1566 $this->assertSame( '', rest_get_route_for_post( $post ) ); 1567 1567 } 1568 1568 … … 1572 1572 public function test_rest_get_route_for_post_non_rest() { 1573 1573 $post = self::factory()->post->create_and_get( array( 'post_type' => 'custom_css' ) ); 1574 $this->assert Equals( '', rest_get_route_for_post( $post ) );1574 $this->assertSame( '', rest_get_route_for_post( $post ) ); 1575 1575 } 1576 1576 … … 1580 1580 public function test_rest_get_route_for_post_custom_controller() { 1581 1581 $post = self::factory()->post->create_and_get( array( 'post_type' => 'wp_block' ) ); 1582 $this->assert Equals( '', rest_get_route_for_post( $post ) );1582 $this->assertSame( '', rest_get_route_for_post( $post ) ); 1583 1583 } 1584 1584 … … 1588 1588 public function test_rest_get_route_for_post() { 1589 1589 $post = self::factory()->post->create_and_get(); 1590 $this->assert Equals( '/wp/v2/posts/' . $post->ID, rest_get_route_for_post( $post ) );1590 $this->assertSame( '/wp/v2/posts/' . $post->ID, rest_get_route_for_post( $post ) ); 1591 1591 } 1592 1592 … … 1596 1596 public function test_rest_get_route_for_media() { 1597 1597 $post = self::factory()->attachment->create_and_get(); 1598 $this->assert Equals( '/wp/v2/media/' . $post->ID, rest_get_route_for_post( $post ) );1598 $this->assertSame( '/wp/v2/media/' . $post->ID, rest_get_route_for_post( $post ) ); 1599 1599 } 1600 1600 … … 1604 1604 public function test_rest_get_route_for_post_id() { 1605 1605 $post = self::factory()->post->create_and_get(); 1606 $this->assert Equals( '/wp/v2/posts/' . $post->ID, rest_get_route_for_post( $post->ID ) );1606 $this->assertSame( '/wp/v2/posts/' . $post->ID, rest_get_route_for_post( $post->ID ) ); 1607 1607 } 1608 1608 … … 1611 1611 */ 1612 1612 public function test_rest_get_route_for_term_non_term() { 1613 $this->assert Equals( '', rest_get_route_for_term( 'garbage' ) );1613 $this->assertSame( '', rest_get_route_for_term( 'garbage' ) ); 1614 1614 } 1615 1615 … … 1622 1622 unregister_taxonomy( 'invalid' ); 1623 1623 1624 $this->assert Equals( '', rest_get_route_for_term( $term ) );1624 $this->assertSame( '', rest_get_route_for_term( $term ) ); 1625 1625 } 1626 1626 … … 1630 1630 public function test_rest_get_route_for_term_non_rest() { 1631 1631 $term = self::factory()->term->create_and_get( array( 'taxonomy' => 'post_format' ) ); 1632 $this->assert Equals( '', rest_get_route_for_term( $term ) );1632 $this->assertSame( '', rest_get_route_for_term( $term ) ); 1633 1633 } 1634 1634 … … 1638 1638 public function test_rest_get_route_for_term() { 1639 1639 $term = self::factory()->term->create_and_get(); 1640 $this->assert Equals( '/wp/v2/tags/' . $term->term_id, rest_get_route_for_term( $term ) );1640 $this->assertSame( '/wp/v2/tags/' . $term->term_id, rest_get_route_for_term( $term ) ); 1641 1641 } 1642 1642 … … 1646 1646 public function test_rest_get_route_for_category() { 1647 1647 $term = self::factory()->category->create_and_get(); 1648 $this->assert Equals( '/wp/v2/categories/' . $term->term_id, rest_get_route_for_term( $term ) );1648 $this->assertSame( '/wp/v2/categories/' . $term->term_id, rest_get_route_for_term( $term ) ); 1649 1649 } 1650 1650 … … 1654 1654 public function test_rest_get_route_for_term_id() { 1655 1655 $term = self::factory()->term->create_and_get(); 1656 $this->assert Equals( '/wp/v2/tags/' . $term->term_id, rest_get_route_for_term( $term->term_id ) );1656 $this->assertSame( '/wp/v2/tags/' . $term->term_id, rest_get_route_for_term( $term->term_id ) ); 1657 1657 } 1658 1658 … … 1730 1730 public function test_rest_sanitize_object( $expected, $value ) { 1731 1731 $sanitized = rest_sanitize_object( $value ); 1732 $this->assert Equals( $expected, $sanitized );1732 $this->assertSame( $expected, $sanitized ); 1733 1733 } 1734 1734 … … 1859 1859 public function test_rest_sanitize_array( $expected, $value ) { 1860 1860 $sanitized = rest_sanitize_array( $value ); 1861 $this->assert Equals( $expected, $sanitized );1861 $this->assertSame( $expected, $sanitized ); 1862 1862 } 1863 1863 … … 1992 1992 */ 1993 1993 public function test_get_best_type_for_value( $expected, $value, $types ) { 1994 $this->assert Equals( $expected, rest_get_best_type_for_value( $value, $types ) );1994 $this->assertSame( $expected, rest_get_best_type_for_value( $value, $types ) ); 1995 1995 } 1996 1996
Note: See TracChangeset
for help on using the changeset viewer.