Changeset 51235
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php
r51210 r51235 99 99 */ 100 100 public function get_items( $request ) { 101 retrieve_widgets(); 102 101 103 $data = array(); 102 foreach ( (array)wp_get_sidebars_widgets() as $id => $widgets ) {104 foreach ( wp_get_sidebars_widgets() as $id => $widgets ) { 103 105 $sidebar = $this->get_sidebar( $id ); 104 106 … … 136 138 */ 137 139 public function get_item( $request ) { 140 retrieve_widgets(); 141 138 142 $sidebar = $this->get_sidebar( $request['id'] ); 139 143 -
trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php
r51079 r51235 9 9 10 10 /** 11 * Tests for REST API for Menus.11 * Tests for REST API for Widgets. 12 12 * 13 13 * @see WP_Test_REST_Controller_Testcase 14 14 * @group restapi 15 * @group widgets 15 16 * @covers WP_REST_Sidebars_Controller 16 17 */ … … 60 61 $_wp_sidebars_widgets = array(); 61 62 update_option( 'sidebars_widgets', array() ); 63 } 64 65 function clean_up_global_scope() { 66 global $wp_widget_factory, $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates; 67 68 $wp_registered_sidebars = array(); 69 $wp_registered_widgets = array(); 70 $wp_registered_widget_controls = array(); 71 $wp_registered_widget_updates = array(); 72 $wp_widget_factory->widgets = array(); 73 74 parent::clean_up_global_scope(); 62 75 } 63 76 … … 129 142 */ 130 143 public function test_get_items() { 144 wp_widgets_init(); 145 131 146 $request = new WP_REST_Request( 'GET', '/wp/v2/sidebars' ); 132 147 $response = rest_get_server()->dispatch( $request ); … … 194 209 */ 195 210 public function test_get_items_active_sidebar_with_widgets() { 211 wp_widgets_init(); 212 196 213 $this->setup_widget( 197 214 'widget_rss', … … 243 260 244 261 /** 262 * @ticket 53489 263 */ 264 public function test_get_items_when_registering_new_sidebars() { 265 register_sidebar( 266 array( 267 'name' => 'New Sidebar', 268 'id' => 'new-sidebar', 269 'before_widget' => '', 270 'after_widget' => '', 271 'before_title' => '', 272 'after_title' => '', 273 ) 274 ); 275 276 $request = new WP_REST_Request( 'GET', '/wp/v2/sidebars' ); 277 $response = rest_get_server()->dispatch( $request ); 278 $data = $response->get_data(); 279 $data = $this->remove_links( $data ); 280 $this->assertSame( 281 array( 282 array( 283 'id' => 'wp_inactive_widgets', 284 'name' => 'Inactive widgets', 285 'description' => '', 286 'class' => '', 287 'before_widget' => '', 288 'after_widget' => '', 289 'before_title' => '', 290 'after_title' => '', 291 'status' => 'inactive', 292 'widgets' => array(), 293 ), 294 array( 295 'id' => 'new-sidebar', 296 'name' => 'New Sidebar', 297 'description' => '', 298 'class' => '', 299 'before_widget' => '', 300 'after_widget' => '', 301 'before_title' => '', 302 'after_title' => '', 303 'status' => 'active', 304 'widgets' => array(), 305 ), 306 ), 307 $data 308 ); 309 } 310 311 /** 245 312 * @ticket 41683 246 313 */ … … 318 385 */ 319 386 public function test_update_item() { 387 wp_widgets_init(); 388 320 389 $this->setup_widget( 321 390 'widget_rss', … … 383 452 */ 384 453 public function test_update_item_removes_widget_from_existing_sidebar() { 454 wp_widgets_init(); 455 385 456 $this->setup_widget( 386 457 'widget_text', … … 424 495 */ 425 496 public function test_update_item_moves_omitted_widget_to_inactive_sidebar() { 497 wp_widgets_init(); 498 426 499 $this->setup_widget( 427 500 'widget_text', … … 466 539 */ 467 540 public function test_get_items_inactive_widgets() { 541 wp_widgets_init(); 542 468 543 $this->setup_widget( 469 544 'widget_rss', -
trunk/tests/phpunit/tests/rest-api/rest-widget-types-controller.php
r51183 r51235 113 113 */ 114 114 public function test_get_items() { 115 wp_widgets_init(); 115 116 wp_set_current_user( self::$admin_id ); 116 117 $request = new WP_REST_Request( 'GET', '/wp/v2/widget-types' );
Note: See TracChangeset
for help on using the changeset viewer.