- Timestamp:
- 06/07/2021 11:16:29 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php
r51059 r51079 212 212 $data = $response->get_data(); 213 213 214 $this->assert Equals( array(), $data );214 $this->assertSame( array(), $data ); 215 215 } 216 216 … … 277 277 array( 278 278 'id' => 'block-1', 279 'id_base' => 'block', 279 280 'sidebar' => 'sidebar-1', 280 281 'instance' => array( … … 297 298 ), 298 299 ), 299 'id_base' => 'block',300 300 'rendered' => '<p>Block test</p>', 301 301 ), 302 302 array( 303 303 'id' => 'rss-1', 304 'id_base' => 'rss', 304 305 'sidebar' => 'sidebar-1', 305 306 'instance' => array( … … 321 322 ), 322 323 ), 323 'id_base' => 'rss',324 324 '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>', 325 325 ), 326 326 array( 327 327 'id' => 'testwidget', 328 'id_base' => 'testwidget', 328 329 'sidebar' => 'sidebar-1', 329 330 'instance' => null, 330 'id_base' => 'testwidget',331 331 'rendered' => '<h1>Default id</h1><span>Default text</span>', 332 332 ), … … 386 386 array( 387 387 'id' => 'text-1', 388 'id_base' => 'text', 388 389 'sidebar' => 'sidebar-1', 389 390 'instance' => array( … … 406 407 ), 407 408 ), 408 'id_base' => 'text',409 409 'rendered' => '<div class="textwidget">Custom text test</div>', 410 410 'rendered_form' => '<input id="widget-text-1-title" name="widget-text[1][title]" class="title sync-input" type="hidden" value="">' . "\n" . … … 415 415 array( 416 416 'id' => 'testwidget', 417 'id_base' => 'testwidget', 417 418 'sidebar' => 'sidebar-1', 418 'instance' => null,419 'id_base' => 'testwidget',420 419 'rendered' => '<h1>Default id</h1><span>Default text</span>', 421 420 'rendered_form' => 'WP test widget form', 421 'instance' => null, 422 422 ), 423 423 ), … … 451 451 array( 452 452 'id' => 'text-1', 453 'id_base' => 'text', 453 454 'sidebar' => 'sidebar-1', 454 455 'instance' => array( … … 471 472 ), 472 473 ), 473 'id_base' => 'text',474 474 'rendered' => '<div class="textwidget">Custom text test</div>', 475 475 ), … … 542 542 $request->set_body_params( 543 543 array( 544 'id_base' => 'text', 544 545 'sidebar' => 'sidebar-1', 545 546 'instance' => array( … … 559 560 ), 560 561 ), 561 'id_base' => 'text',562 562 ) 563 563 ); 564 564 $response = rest_get_server()->dispatch( $request ); 565 565 $data = $response->get_data(); 566 $this->assert Equals( 'text-2', $data['id'] );567 $this->assert Equals( 'sidebar-1', $data['sidebar'] );566 $this->assertSame( 'text-2', $data['id'] ); 567 $this->assertSame( 'sidebar-1', $data['sidebar'] ); 568 568 $this->assertEqualSets( 569 569 array( … … 590 590 $request->set_body_params( 591 591 array( 592 'id_base' => 'text', 592 593 'sidebar' => 'sidebar-1', 593 594 'instance' => array( … … 601 602 'hash' => 'badhash', 602 603 ), 604 ) 605 ); 606 $response = rest_get_server()->dispatch( $request ); 607 $this->assertErrorResponse( 'rest_invalid_widget', $response, 400 ); 608 } 609 610 /** 611 * @ticket 41683 612 */ 613 public function test_create_item_bad_instance() { 614 $this->setup_sidebar( 615 'sidebar-1', 616 array( 617 'name' => 'Test sidebar', 618 ) 619 ); 620 621 $request = new WP_REST_Request( 'POST', '/wp/v2/widgets' ); 622 $request->set_body_params( 623 array( 603 624 'id_base' => 'text', 604 )605 );606 $response = rest_get_server()->dispatch( $request );607 $this->assertErrorResponse( 'rest_invalid_widget', $response, 400 );608 }609 610 /**611 * @ticket 41683612 */613 public function test_create_item_bad_instance() {614 $this->setup_sidebar(615 'sidebar-1',616 array(617 'name' => 'Test sidebar',618 )619 );620 621 $request = new WP_REST_Request( 'POST', '/wp/v2/widgets' );622 $request->set_body_params(623 array(624 625 'sidebar' => 'sidebar-1', 625 626 'instance' => array(), 626 'id_base' => 'text',627 627 ) 628 628 ); … … 645 645 $request->set_body_params( 646 646 array( 647 'id_base' => 'block', 647 648 'sidebar' => 'sidebar-1', 648 649 'instance' => array( … … 651 652 ), 652 653 ), 653 'id_base' => 'block',654 654 ) 655 655 ); 656 656 $response = rest_get_server()->dispatch( $request ); 657 657 $data = $response->get_data(); 658 $this->assert Equals( 'block-2', $data['id'] );659 $this->assert Equals( 'sidebar-1', $data['sidebar'] );658 $this->assertSame( 'block-2', $data['id'] ); 659 $this->assertSame( 'sidebar-1', $data['sidebar'] ); 660 660 $this->assertEqualSets( 661 661 array( … … 684 684 $request->set_body_params( 685 685 array( 686 'id_base' => 'text', 686 687 'sidebar' => 'sidebar-1', 687 688 'instance' => array( … … 690 691 ), 691 692 ), 692 'id_base' => 'text',693 693 ) 694 694 ); … … 713 713 $request->set_body_params( 714 714 array( 715 'id_base' => 'text', 715 716 'sidebar' => 'sidebar-1', 716 717 'form_data' => 'widget-text[2][text]=Updated+text+test', 717 'id_base' => 'text',718 718 ) 719 719 ); 720 720 $response = rest_get_server()->dispatch( $request ); 721 721 $data = $response->get_data(); 722 $this->assert Equals( 'text-2', $data['id'] );723 $this->assert Equals( 'sidebar-1', $data['sidebar'] );722 $this->assertSame( 'text-2', $data['id'] ); 723 $this->assertSame( 'sidebar-1', $data['sidebar'] ); 724 724 $this->assertEqualSets( 725 725 array( … … 746 746 $request->set_body_params( 747 747 array( 748 'id_base' => 'text', 748 749 'sidebar' => 'sidebar-1', 749 750 'instance' => array( 750 751 'raw' => array( 'text' => 'Text 1' ), 751 752 ), 752 'id_base' => 'text',753 753 ) 754 754 ); 755 755 $response = rest_get_server()->dispatch( $request ); 756 756 $data = $response->get_data(); 757 $this->assert Equals( 'text-2', $data['id'] );758 $this->assert Equals( 'sidebar-1', $data['sidebar'] );757 $this->assertSame( 'text-2', $data['id'] ); 758 $this->assertSame( 'sidebar-1', $data['sidebar'] ); 759 759 $this->assertEqualSets( 760 760 array( … … 769 769 $request->set_body_params( 770 770 array( 771 'id_base' => 'text', 771 772 'sidebar' => 'sidebar-1', 772 773 'instance' => array( 773 774 'raw' => array( 'text' => 'Text 2' ), 774 775 ), 775 'id_base' => 'text',776 776 ) 777 777 ); 778 778 $response = rest_get_server()->dispatch( $request ); 779 779 $data = $response->get_data(); 780 $this->assert Equals( 'text-3', $data['id'] );781 $this->assert Equals( 'sidebar-1', $data['sidebar'] );780 $this->assertSame( 'text-3', $data['id'] ); 781 $this->assertSame( 'sidebar-1', $data['sidebar'] ); 782 782 $this->assertEqualSets( 783 783 array( … … 815 815 $request->set_body_params( 816 816 array( 817 'id_base' => 'text', 817 818 'sidebar' => 'sidebar-1', 818 819 'instance' => array( … … 821 822 ), 822 823 ), 823 'id_base' => 'text',824 824 ) 825 825 ); 826 826 $response = rest_get_server()->dispatch( $request ); 827 827 $data = $response->get_data(); 828 $this->assert Equals( 'text-2', $data['id'] );829 $this->assert Equals( 'sidebar-1', $data['sidebar'] );828 $this->assertSame( 'text-2', $data['id'] ); 829 $this->assertSame( 'sidebar-1', $data['sidebar'] ); 830 830 $this->assertEqualSets( 831 831 array( … … 861 861 array( 862 862 'id' => 'text-1', 863 'id_base' => 'text', 863 864 'sidebar' => 'sidebar-1', 864 865 'instance' => array( … … 867 868 ), 868 869 ), 869 'id_base' => 'text',870 870 ) 871 871 ); … … 873 873 $data = $response->get_data(); 874 874 875 $this->assert Equals( 'text-1', $data['id'] );876 $this->assert Equals( 'sidebar-1', $data['sidebar'] );875 $this->assertSame( 'text-1', $data['id'] ); 876 $this->assertSame( 'sidebar-1', $data['sidebar'] ); 877 877 $this->assertEqualSets( 878 878 array( … … 920 920 $error = $response->as_error(); 921 921 $this->assertNotWPError( $error, $error ? $error->get_error_message() : '' ); 922 $this->assert Equals( 'sidebar-2', $response->get_data()['sidebar'] );922 $this->assertSame( 'sidebar-2', $response->get_data()['sidebar'] ); 923 923 924 924 $sidebar1 = rest_do_request( '/wp/v2/sidebars/sidebar-1' ); … … 962 962 $data = $response->get_data(); 963 963 964 $this->assert Equals( 'text-1', $data['id'] );965 $this->assert Equals( 'sidebar-1', $data['sidebar'] );964 $this->assertSame( 'text-1', $data['id'] ); 965 $this->assertSame( 'sidebar-1', $data['sidebar'] ); 966 966 $this->assertEqualSets( 967 967 array( … … 979 979 public function test_store_html_as_admin() { 980 980 if ( is_multisite() ) { 981 $this->assert Equals(981 $this->assertSame( 982 982 '<div class="textwidget">alert(1)</div>', 983 983 $this->update_text_widget_with_raw_html( '<script>alert(1)</script>' ) 984 984 ); 985 985 } else { 986 $this->assert Equals(986 $this->assertSame( 987 987 '<div class="textwidget"><script>alert(1)</script></div>', 988 988 $this->update_text_widget_with_raw_html( '<script>alert(1)</script>' ) … … 997 997 wp_set_current_user( self::$superadmin_id ); 998 998 if ( is_multisite() ) { 999 $this->assert Equals(999 $this->assertSame( 1000 1000 '<div class="textwidget"><script>alert(1)</script></div>', 1001 1001 $this->update_text_widget_with_raw_html( '<script>alert(1)</script>' ) 1002 1002 ); 1003 1003 } else { 1004 $this->assert Equals(1004 $this->assertSame( 1005 1005 '<div class="textwidget"><script>alert(1)</script></div>', 1006 1006 $this->update_text_widget_with_raw_html( '<script>alert(1)</script>' ) … … 1029 1029 array( 1030 1030 'id' => 'text-1', 1031 'id_base' => 'text', 1031 1032 'instance' => array( 1032 1033 'raw' => array( … … 1034 1035 ), 1035 1036 ), 1036 'id_base' => 'text',1037 1037 ) 1038 1038 ); … … 1066 1066 $data = $response->get_data(); 1067 1067 $data = $this->remove_links( $data ); 1068 $this->assert Equals(1068 $this->assertSame( 1069 1069 array( 1070 1070 'id' => 'testwidget', 1071 'id_base' => 'testwidget', 1071 1072 'sidebar' => 'sidebar-1', 1072 'instance' => null,1073 1073 'rendered' => '<h1>My test id</h1><span>My test title</span>', 1074 1074 'rendered_form' => 'WP test widget form', 1075 'i d_base' => 'testwidget',1075 'instance' => null, 1076 1076 ), 1077 1077 $data … … 1103 1103 $data = $response->get_data(); 1104 1104 $data = $this->remove_links( $data ); 1105 $this->assert Equals(1105 $this->assertSame( 1106 1106 array( 1107 1107 'id' => 'testwidget', 1108 'id_base' => 'testwidget', 1108 1109 'sidebar' => 'sidebar-1', 1109 'instance' => null,1110 1110 'rendered' => '<h1>My test id</h1><span>My test title</span>', 1111 1111 'rendered_form' => 'WP test widget form', 1112 'i d_base' => 'testwidget',1112 'instance' => null, 1113 1113 ), 1114 1114 $data … … 1159 1159 array( 1160 1160 'id' => 'text-1', 1161 'id_base' => 'text', 1161 1162 'sidebar' => 'sidebar-1', 1162 1163 'instance' => array( … … 1165 1166 ), 1166 1167 ), 1167 'id_base' => 'text',1168 1168 ) 1169 1169 ); … … 1180 1180 ); 1181 1181 1182 $this->assert Equals(1182 $this->assertSame( 1183 1183 '<div class="textwidget">Updated \\" \\\' text test</div>', 1184 1184 $data['rendered'] … … 1211 1211 array( 1212 1212 'id' => 'text-1', 1213 'id_base' => 'text', 1213 1214 'sidebar' => 'wp_inactive_widgets', 1214 1215 'instance' => array( … … 1231 1232 ), 1232 1233 ), 1233 'id_base' => 'text',1234 1234 'rendered' => '', 1235 1235 'rendered_form' => '<input id="widget-text-1-title" name="widget-text[1][title]" class="title sync-input" type="hidden" value="">' . "\n" . … … 1271 1271 1272 1272 'id' => 'text-1', 1273 'id_base' => 'text', 1273 1274 'sidebar' => 'sidebar-1', 1274 1275 'instance' => array( … … 1291 1292 ), 1292 1293 ), 1293 'id_base' => 'text',1294 1294 'rendered' => '<div class="textwidget">Custom text test</div>', 1295 1295 'rendered_form' => '<input id="widget-text-1-title" name="widget-text[1][title]" class="title sync-input" type="hidden" value="">' . "\n" . … … 1304 1304 1305 1305 $response = rest_do_request( '/wp/v2/widgets/text-1' ); 1306 $this->assert Equals( 404, $response->get_status() );1306 $this->assertSame( 404, $response->get_status() ); 1307 1307 1308 1308 $this->assertArrayNotHasKey( 'text-1', get_option( 'sidebars_widgets' )['sidebar-1'] ); … … 1380 1380 $properties = $data['schema']['properties']; 1381 1381 1382 $this->assert Equals( 7, count( $properties ) );1382 $this->assertSame( 7, count( $properties ) ); 1383 1383 $this->assertArrayHasKey( 'id', $properties ); 1384 1384 $this->assertArrayHasKey( 'id_base', $properties );
Note: See TracChangeset
for help on using the changeset viewer.