Changeset 57623
- Timestamp:
- 02/13/2024 01:46:45 PM (8 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r57312 r57623 744 744 } 745 745 746 if ( empty( $request['per_page'] ) ) { 747 $matched = $this->match_request_to_handler( $request ); 748 if ( ! is_wp_error( $matched ) && isset( $matched[1]['args']['per_page']['maximum'] ) ) { 749 $request['per_page'] = (int) $matched[1]['args']['per_page']['maximum']; 750 } 751 } 752 746 753 // Embedded resources get passed context=embed. 747 754 if ( empty( $request['context'] ) ) { -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r57108 r57623 19 19 protected static $supported_formats; 20 20 protected static $post_ids = array(); 21 protected static $terms = array(); 21 22 protected static $total_posts = 30; 22 23 protected static $per_page = 50; … … 29 30 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 30 31 self::$post_id = $factory->post->create(); 32 self::$terms = $factory->term->create_many( 15, array( 'taxonomy' => 'category' ) ); 33 wp_set_object_terms( self::$post_id, self::$terms, 'category' ); 31 34 32 35 self::$superadmin_id = $factory->user->create( … … 222 225 sort( $keys ); 223 226 $this->assertSame( array( 'context', 'id', 'password' ), $keys ); 227 } 228 229 public function test_registered_get_items_embed() { 230 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 231 $request->set_param( 'include', array( self::$post_id ) ); 232 $response = rest_get_server()->dispatch( $request ); 233 $response = rest_get_server()->response_to_data( $response, true ); 234 $this->assertArrayHasKey( '_embedded', $response[0], 'The _embedded key must exist' ); 235 $this->assertArrayHasKey( 'wp:term', $response[0]['_embedded'], 'The wp:term key must exist' ); 236 $this->assertCount( 15, $response[0]['_embedded']['wp:term'][0], 'Should should be 15 terms and not the default 10' ); 237 $i = 0; 238 foreach ( $response[0]['_embedded']['wp:term'][0] as $term ) { 239 $this->assertSame( self::$terms[ $i ], $term['id'], 'Check term id existing in response' ); 240 ++$i; 241 } 224 242 } 225 243 -
trunk/tests/phpunit/tests/rest-api/rest-server.php
r57147 r57623 930 930 $this->assertArrayNotHasKey( '_embedded', $result ); 931 931 $this->assertSame( 'data', $result['untouched'] ); 932 } 933 934 /** 935 * Ensure embedding is with links in the data. 936 * 937 * @ticket 43439 938 */ 939 public function test_link_embedding_with_links() { 940 $data = array( 941 '_links' => array( 942 'wp:term' => array( 943 array( 944 'taxonomy' => 'category', 945 'embeddable' => true, 946 'href' => get_rest_url( 0, '/wp/v2/categories' ), 947 ), 948 array( 949 'taxonomy' => 'post_tag', 950 'embeddable' => true, 951 'href' => get_rest_url( 0, '/wp/v2/tags' ), 952 ), 953 ), 954 ), 955 ); 956 957 $mock = new MockAction(); 958 add_filter( 'rest_post_dispatch', array( $mock, 'filter' ), 10, 3 ); 959 960 rest_get_server()->embed_links( $data, true ); 961 $args = $mock->get_args(); 962 foreach ( $args as $arg ) { 963 $this->assertSame( 100, $arg[2]['per_page'], 'Posts per page should be 100' ); 964 } 932 965 } 933 966
Note: See TracChangeset
for help on using the changeset viewer.