Changeset 64784
- Timestamp:
- 10/27/2026 12:15:09 AM (31 hours ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/wpRestMenuLocationsController.php
r64004 r64784 227 227 228 228 /** 229 * The prepare_item() method does not exist for menu locations.230 * 231 * @ doesNotPerformAssertions229 * @ticket 40538 230 * 231 * @covers ::prepare_item_for_response 232 232 */ 233 233 public function test_prepare_item() { 234 // Controller does not implement prepare_item(). 234 $this->register_nav_menu_locations( array( 'primary' ) ); 235 236 $menu = wp_create_nav_menu( 'Primary Menu' ); 237 set_theme_mod( 'nav_menu_locations', array( 'primary' => $menu ) ); 238 239 $location = (object) array( 240 'name' => 'primary', 241 'description' => 'Primary', 242 ); 243 244 $endpoint = new WP_REST_Menu_Locations_Controller(); 245 $request = new WP_REST_Request( 'GET', '/wp/v2/menu-locations/primary' ); 246 $response = $endpoint->prepare_item_for_response( $location, $request ); 247 248 $this->assertInstanceOf( WP_REST_Response::class, $response ); 249 $this->assertSame( 200, $response->get_status() ); 250 251 $data = $response->get_data(); 252 $this->assertSame( 'primary', $data['name'] ); 253 $this->assertSame( 'Primary', $data['description'] ); 254 $this->assertSame( $menu, $data['menu'] ); 255 256 $links = $response->get_links(); 257 $this->assertArrayHasKey( 'self', $links ); 258 $this->assertSame( rest_url( 'wp/v2/menu-locations/primary' ), $links['self'][0]['href'] ); 259 $this->assertArrayHasKey( 'collection', $links ); 260 $this->assertSame( rest_url( 'wp/v2/menu-locations' ), $links['collection'][0]['href'] ); 261 $this->assertArrayHasKey( 'https://api.w.org/menu', $links ); 262 $this->assertSame( rest_url( rest_get_route_for_term( $menu ) ), $links['https://api.w.org/menu'][0]['href'] ); 263 } 264 265 /** 266 * @ticket 40538 267 * 268 * @covers ::prepare_item_for_response 269 */ 270 public function test_prepare_item_limit_fields() { 271 $location = (object) array( 272 'name' => 'primary', 273 'description' => 'Primary', 274 ); 275 276 $endpoint = new WP_REST_Menu_Locations_Controller(); 277 $request = new WP_REST_Request( 'GET', '/wp/v2/menu-locations/primary' ); 278 $request->set_param( '_fields', 'name' ); 279 280 $response = $endpoint->prepare_item_for_response( $location, $request ); 281 $this->assertSame( array( 'name' => 'primary' ), $response->get_data() ); 282 $this->assertEmpty( $response->get_links() ); 235 283 } 236 284
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)