Changeset 64827
- Timestamp:
- 10/27/2026 07:40:03 PM (4 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php
r64283 r64827 1138 1138 1139 1139 /** 1140 * The prepare_item() method does not exist for sidebar.1140 * @ticket 40538 1141 1141 * 1142 * @ doesNotPerformAssertions1142 * @covers WP_REST_Sidebars_Controller::prepare_item_for_response 1143 1143 */ 1144 1144 public function test_prepare_item() { 1145 // Controller does not implement prepare_item(). 1145 $this->setup_sidebar( 1146 'sidebar-1', 1147 array( 1148 'name' => 'Test sidebar', 1149 'description' => 'Test description', 1150 ) 1151 ); 1152 1153 $raw_sidebar = array( 1154 'id' => 'sidebar-1', 1155 'name' => 'Test sidebar', 1156 ); 1157 1158 $controller = new WP_REST_Sidebars_Controller(); 1159 $request = new WP_REST_Request( 'GET', '/wp/v2/sidebars/sidebar-1' ); 1160 $response = $controller->prepare_item_for_response( $raw_sidebar, $request ); 1161 1162 $this->assertInstanceOf( WP_REST_Response::class, $response ); 1163 $this->assertSame( 200, $response->get_status() ); 1164 1165 $data = $response->get_data(); 1166 $this->assertSame( 'sidebar-1', $data['id'] ); 1167 $this->assertSame( 'Test sidebar', $data['name'] ); 1168 $this->assertSame( 'Test description', $data['description'] ); 1169 $this->assertSame( 'active', $data['status'] ); 1170 $this->assertSame( array(), $data['widgets'] ); 1171 1172 $links = $response->get_links(); 1173 $this->assertArrayHasKey( 'self', $links ); 1174 $this->assertSame( rest_url( 'wp/v2/sidebars/sidebar-1' ), $links['self'][0]['href'] ); 1175 $this->assertArrayHasKey( 'collection', $links ); 1176 $this->assertSame( rest_url( 'wp/v2/sidebars' ), $links['collection'][0]['href'] ); 1177 } 1178 1179 /** 1180 * @ticket 40538 1181 * 1182 * @covers WP_REST_Sidebars_Controller::prepare_item_for_response 1183 */ 1184 public function test_prepare_item_limit_fields() { 1185 $this->setup_sidebar( 1186 'sidebar-1', 1187 array( 1188 'name' => 'Test sidebar', 1189 ) 1190 ); 1191 1192 $raw_sidebar = array( 1193 'id' => 'sidebar-1', 1194 'name' => 'Test sidebar', 1195 ); 1196 1197 $controller = new WP_REST_Sidebars_Controller(); 1198 $request = new WP_REST_Request( 'GET', '/wp/v2/sidebars/sidebar-1' ); 1199 $request->set_param( '_fields', 'id,name' ); 1200 1201 $response = $controller->prepare_item_for_response( $raw_sidebar, $request ); 1202 1203 $this->assertEmpty( $response->get_links(), 'Links should be omitted when _links is not in _fields.' ); 1146 1204 } 1147 1205
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)