- Timestamp:
- 11/05/2021 02:14:07 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php
r51830 r52016 242 242 243 243 /** 244 * @ticket 53915 245 */ 246 public function test_get_items_no_permission_show_in_rest() { 247 $this->setup_widget( 248 'text', 249 1, 250 array( 251 'text' => 'Custom text test', 252 ) 253 ); 254 $this->setup_sidebar( 255 'sidebar-1', 256 array( 257 'name' => 'Test sidebar', 258 'show_in_rest' => true, 259 ), 260 array( 'text-1', 'testwidget' ) 261 ); 262 263 $request = new WP_REST_Request( 'GET', '/wp/v2/widgets' ); 264 $response = rest_get_server()->dispatch( $request ); 265 $data = $response->get_data(); 266 $data = $this->remove_links( $data ); 267 $this->assertSameIgnoreEOL( 268 array( 269 array( 270 'id' => 'text-1', 271 'id_base' => 'text', 272 'sidebar' => 'sidebar-1', 273 'rendered' => '<div class="textwidget">Custom text test</div>', 274 ), 275 array( 276 'id' => 'testwidget', 277 'id_base' => 'testwidget', 278 'sidebar' => 'sidebar-1', 279 'rendered' => '<h1>Default id</h1><span>Default text</span>', 280 ), 281 ), 282 $data 283 ); 284 } 285 286 /** 287 * @ticket 53915 288 */ 289 public function test_get_items_without_show_in_rest_are_removed_from_the_list() { 290 wp_set_current_user( self::$author_id ); 291 $this->setup_widget( 292 'text', 293 1, 294 array( 295 'text' => 'Custom text test', 296 ) 297 ); 298 $this->setup_sidebar( 299 'sidebar-1', 300 array( 301 'name' => 'Test sidebar 1', 302 'show_in_rest' => true, 303 ), 304 array( 'text-1', 'testwidget' ) 305 ); 306 $this->setup_sidebar( 307 'sidebar-2', 308 array( 309 'name' => 'Test sidebar 2', 310 'show_in_rest' => false, 311 ), 312 array( 'text-1', 'testwidget' ) 313 ); 314 $request = new WP_REST_Request( 'GET', '/wp/v2/widgets' ); 315 $response = rest_get_server()->dispatch( $request ); 316 $data = $response->get_data(); 317 $data = $this->remove_links( $data ); 318 $this->assertSameIgnoreEOL( 319 array( 320 array( 321 'id' => 'text-1', 322 'id_base' => 'text', 323 'sidebar' => 'sidebar-1', 324 'rendered' => '<div class="textwidget">Custom text test</div>', 325 ), 326 array( 327 'id' => 'testwidget', 328 'id_base' => 'testwidget', 329 'sidebar' => 'sidebar-1', 330 'rendered' => '<h1>Default id</h1><span>Default text</span>', 331 ), 332 ), 333 $data 334 ); 335 } 336 337 /** 244 338 * @ticket 41683 245 339 */ … … 296 390 'sidebar' => 'sidebar-1', 297 391 'rendered' => '<p>Block test</p>', 298 'instance' => array(299 'encoded' => base64_encode(300 serialize(301 array(302 'content' => $block_content,303 )304 )305 ),306 'hash' => wp_hash(307 serialize(308 array(309 'content' => $block_content,310 )311 )312 ),313 'raw' => array(314 'content' => $block_content,315 ),316 ),317 392 ), 318 393 array( … … 321 396 'sidebar' => 'sidebar-1', 322 397 'rendered' => '<a class="rsswidget" href="https://wordpress.org/news/feed"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="http://example.org/wp-includes/images/rss.png" alt="RSS" /></a> <a class="rsswidget" href="https://wordpress.org/news">RSS test</a><ul><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/introducing-learn-wordpress/\'>Introducing Learn WordPress</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/simone/\'>WordPress 5.6 “Simone”</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/state-of-the-word-2020/\'>State of the Word 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/the-month-in-wordpress-november-2020/\'>The Month in WordPress: November 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/wordpress-5-6-release-candidate-2/\'>WordPress 5.6 Release Candidate 2</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-release-candidate/\'>WordPress 5.6 Release Candidate</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-4/\'>WordPress 5.6 Beta 4</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-3/\'>WordPress 5.6 Beta 3</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/the-month-in-wordpress-october-2020/\'>The Month in WordPress: October 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/10/wordpress-5-5-3-maintenance-release/\'>WordPress 5.5.3 Maintenance Release</a></li></ul>', 323 'instance' => array(324 'encoded' => base64_encode(325 serialize(326 array(327 'title' => 'RSS test',328 'url' => 'https://wordpress.org/news/feed',329 )330 )331 ),332 'hash' => wp_hash(333 serialize(334 array(335 'title' => 'RSS test',336 'url' => 'https://wordpress.org/news/feed',337 )338 )339 ),340 ),341 398 ), 342 399 array( … … 345 402 'sidebar' => 'sidebar-1', 346 403 'rendered' => '<h1>Default id</h1><span>Default text</span>', 347 'instance' => null,348 404 ), 349 405 ), … … 470 526 'sidebar' => 'sidebar-1', 471 527 'rendered' => '<div class="textwidget">Custom text test</div>', 472 'instance' => array(473 'encoded' => base64_encode(474 serialize(475 array(476 'text' => 'Custom text test',477 )478 )479 ),480 'hash' => wp_hash(481 serialize(482 array(483 'text' => 'Custom text test',484 )485 )486 ),487 'raw' => array(488 'text' => 'Custom text test',489 ),490 ),491 528 ), 492 529 $data … … 542 579 $response = rest_get_server()->dispatch( $request ); 543 580 $this->assertErrorResponse( 'rest_cannot_manage_widgets', $response, 403 ); 581 } 582 583 /** 584 * @ticket 53915 585 */ 586 public function test_get_item_no_permission_show_in_rest() { 587 wp_set_current_user( 0 ); 588 589 $this->setup_widget( 590 'text', 591 1, 592 array( 593 'text' => 'Custom text test', 594 ) 595 ); 596 $this->setup_sidebar( 597 'sidebar-1', 598 array( 599 'name' => 'Test sidebar', 600 'show_in_rest' => true, 601 ), 602 array( 'text-1' ) 603 ); 604 605 $request = new WP_REST_Request( 'GET', '/wp/v2/widgets/text-1' ); 606 $response = rest_get_server()->dispatch( $request ); 607 $data = $response->get_data(); 608 $this->assertSameSets( 609 array( 610 'id' => 'text-1', 611 'id_base' => 'text', 612 'sidebar' => 'sidebar-1', 613 'rendered' => '<div class="textwidget">Custom text test</div>', 614 ), 615 $data 616 ); 544 617 } 545 618
Note: See TracChangeset
for help on using the changeset viewer.