Changeset 51088 for trunk/tests/phpunit/tests/widgets.php
- Timestamp:
- 06/08/2021 01:54:27 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/widgets.php
r50961 r51088 575 575 global $wp_registered_widgets; 576 576 577 $settings = get_option( 'widget_ search' );577 $settings = get_option( 'widget_block' ); 578 578 unset( $settings['_multiwidget'] ); 579 579 $this->assertArrayHasKey( 2, $settings ); … … 584 584 // Note: We cannot use array_keys() here because $settings could be an ArrayIterator. 585 585 foreach ( $settings as $widget_number => $instance ) { 586 $widget_id = " search-$widget_number";586 $widget_id = "block-$widget_number"; 587 587 $this->assertArrayHasKey( $widget_id, $wp_registered_widgets ); 588 588 } … … 620 620 global $wp_registered_widgets; 621 621 622 $option_value = get_option( 'widget_ search' );622 $option_value = get_option( 'widget_block' ); 623 623 $this->assertArrayHasKey( '_multiwidget', $option_value ); 624 624 $this->assertSame( 1, $option_value['_multiwidget'] ); … … 626 626 $instance = $option_value[2]; 627 627 $this->assertInternalType( 'array', $instance ); 628 $this->assertArrayHasKey( ' title', $instance );628 $this->assertArrayHasKey( 'content', $instance ); 629 629 unset( $option_value['_multiwidget'] ); 630 630 … … 635 635 636 636 wp_widgets_init(); 637 $wp_widget_ search = $wp_registered_widgets['search-2']['callback'][0];638 639 $settings = $wp_widget_ search->get_settings();637 $wp_widget_block = $wp_registered_widgets['block-2']['callback'][0]; 638 639 $settings = $wp_widget_block->get_settings(); 640 640 // @todo $this->assertArrayNotHasKey( '_multiwidget', $settings ); ? 641 641 $this->assertArrayHasKey( 2, $settings ); … … 658 658 659 659 wp_widgets_init(); 660 $wp_widget_ search = $wp_registered_widgets['search-2']['callback'][0];661 662 $settings = $wp_widget_search->get_settings();663 $overridden_ title= 'Unit Tested';660 $wp_widget_block = $wp_registered_widgets['block-2']['callback'][0]; 661 662 $settings = $wp_widget_block->get_settings(); 663 $overridden_content = 'Unit Tested'; 664 664 665 665 /* … … 671 671 * So this is why the value must be obtained. 672 672 */ 673 $instance = $settings[2];674 $instance[' title'] = $overridden_title;675 $settings[2] = $instance;676 677 $wp_widget_ search->save_settings( $settings );678 679 $option_value = get_option( $wp_widget_ search->option_name );673 $instance = $settings[2]; 674 $instance['content'] = $overridden_content; 675 $settings[2] = $instance; 676 677 $wp_widget_block->save_settings( $settings ); 678 679 $option_value = get_option( $wp_widget_block->option_name ); 680 680 $this->assertArrayHasKey( '_multiwidget', $option_value ); 681 $this->assertSame( $overridden_ title, $option_value[2]['title'] );681 $this->assertSame( $overridden_content, $option_value[2]['content'] ); 682 682 } 683 683 … … 689 689 690 690 wp_widgets_init(); 691 $wp_widget_ search = $wp_registered_widgets['search-2']['callback'][0];692 693 $settings = $wp_widget_ search->get_settings();691 $wp_widget_block = $wp_registered_widgets['block-2']['callback'][0]; 692 693 $settings = $wp_widget_block->get_settings(); 694 694 $this->assertArrayHasKey( 2, $settings ); 695 695 unset( $settings[2] ); 696 $wp_widget_ search->save_settings( $settings );697 $option_value = get_option( $wp_widget_ search->option_name );696 $wp_widget_block->save_settings( $settings ); 697 $option_value = get_option( $wp_widget_block->option_name ); 698 698 $this->assertArrayNotHasKey( 2, $option_value ); 699 699 } … … 704 704 function test_wp_widget_control() { 705 705 global $wp_registered_widgets; 706 707 update_option( 708 'widget_search', 709 array( 710 2 => array( 'title' => '' ), 711 '_multiwidget' => 1, 712 ) 713 ); 714 update_option( 715 'sidebars_widgets', 716 array( 717 'wp_inactive_widgets' => array(), 718 'sidebar-1' => array( 'search-2' ), 719 'sidebar-2' => array(), 720 'array_version' => 3, 721 ) 722 ); 706 723 707 724 wp_widgets_init(); … … 874 891 $this->assertNotContains( 'unregistered_widget-1', $sidebars_widgets['sidebar-3'] ); 875 892 876 // 6 default widgets - 1 active text widget + 1 orphaned widget = 6. 877 $this->assertCount( 6, $sidebars_widgets['wp_inactive_widgets'] ); 878 879 $this->assertContains( 'meta-2', $sidebars_widgets['wp_inactive_widgets'] ); 880 $this->assertContains( 'search-2', $sidebars_widgets['wp_inactive_widgets'] ); 881 $this->assertContains( 'archives-2', $sidebars_widgets['wp_inactive_widgets'] ); 882 $this->assertContains( 'categories-2', $sidebars_widgets['wp_inactive_widgets'] ); 883 $this->assertContains( 'recent-posts-2', $sidebars_widgets['wp_inactive_widgets'] ); 884 $this->assertContains( 'recent-comments-2', $sidebars_widgets['wp_inactive_widgets'] ); 893 // 5 default widgets - 1 active text widget + 1 orphaned widget = 5. 894 $this->assertCount( 5, $sidebars_widgets['wp_inactive_widgets'] ); 895 896 $this->assertContains( 'block-2', $sidebars_widgets['wp_inactive_widgets'] ); 897 $this->assertContains( 'block-3', $sidebars_widgets['wp_inactive_widgets'] ); 898 $this->assertContains( 'block-4', $sidebars_widgets['wp_inactive_widgets'] ); 899 $this->assertContains( 'block-5', $sidebars_widgets['wp_inactive_widgets'] ); 900 $this->assertContains( 'block-6', $sidebars_widgets['wp_inactive_widgets'] ); 885 901 886 902 // Sidebar_widgets option was updated. … … 966 982 $this->assertArrayNotHasKey( 'orphaned_widgets_1', $sidebars_widgets ); 967 983 968 // 6 default widgets. 969 $this->assertCount( 6, $sidebars_widgets['wp_inactive_widgets'] ); 970 971 $this->assertContains( 'archives-2', $sidebars_widgets['wp_inactive_widgets'] ); 972 $this->assertContains( 'meta-2', $sidebars_widgets['wp_inactive_widgets'] ); 973 $this->assertContains( 'search-2', $sidebars_widgets['wp_inactive_widgets'] ); 974 $this->assertContains( 'categories-2', $sidebars_widgets['wp_inactive_widgets'] ); 975 $this->assertContains( 'recent-posts-2', $sidebars_widgets['wp_inactive_widgets'] ); 976 $this->assertContains( 'recent-comments-2', $sidebars_widgets['wp_inactive_widgets'] ); 984 // 5 default widgets. 985 $this->assertCount( 5, $sidebars_widgets['wp_inactive_widgets'] ); 986 987 $this->assertContains( 'block-2', $sidebars_widgets['wp_inactive_widgets'] ); 988 $this->assertContains( 'block-3', $sidebars_widgets['wp_inactive_widgets'] ); 989 $this->assertContains( 'block-4', $sidebars_widgets['wp_inactive_widgets'] ); 990 $this->assertContains( 'block-5', $sidebars_widgets['wp_inactive_widgets'] ); 991 $this->assertContains( 'block-6', $sidebars_widgets['wp_inactive_widgets'] ); 977 992 978 993 // Sidebar_widgets option was updated. … … 983 998 'sidebar-1' => array( 'tag_cloud-1' ), 984 999 'sidebar-2' => array( 'text-1' ), 985 'fantasy' => array( ' archives-2' ),1000 'fantasy' => array( 'block-4' ), 986 1001 'wp_inactive_widgets' => array(), 987 1002 ); … … 1005 1020 $this->assertContains( 'text-1', $sidebars_widgets['sidebar-2'] ); 1006 1021 1007 // 6 default widgets - 1 active text widget = 5. 1008 $this->assertCount( 6, $sidebars_widgets['wp_inactive_widgets'] ); 1009 1010 $this->assertContains( 'meta-2', $sidebars_widgets['wp_inactive_widgets'] ); 1011 $this->assertContains( 'search-2', $sidebars_widgets['wp_inactive_widgets'] ); 1012 // archives-2 ends up as inactive because fantasy sidebar doesn't exist. 1013 $this->assertContains( 'archives-2', $sidebars_widgets['wp_inactive_widgets'] ); 1014 $this->assertContains( 'categories-2', $sidebars_widgets['wp_inactive_widgets'] ); 1015 $this->assertContains( 'recent-posts-2', $sidebars_widgets['wp_inactive_widgets'] ); 1016 $this->assertContains( 'recent-comments-2', $sidebars_widgets['wp_inactive_widgets'] ); 1022 // 5 default widgets - 1 active text widget = 5. 1023 $this->assertCount( 5, $sidebars_widgets['wp_inactive_widgets'] ); 1024 1025 $this->assertContains( 'block-2', $sidebars_widgets['wp_inactive_widgets'] ); 1026 $this->assertContains( 'block-3', $sidebars_widgets['wp_inactive_widgets'] ); 1027 // block-4 ends up as inactive because fantasy sidebar doesn't exist. 1028 $this->assertContains( 'block-4', $sidebars_widgets['wp_inactive_widgets'] ); 1029 $this->assertContains( 'block-5', $sidebars_widgets['wp_inactive_widgets'] ); 1030 $this->assertContains( 'block-6', $sidebars_widgets['wp_inactive_widgets'] ); 1017 1031 1018 1032 // Sidebar_widgets option was updated. … … 1054 1068 $this->assertArrayHasKey( 'sidebar-3', $sidebars_widgets ); 1055 1069 $this->assertEmpty( $sidebars_widgets['sidebar-3'] ); 1056 $this->assertCount( 6, $sidebars_widgets['wp_inactive_widgets'] ); 1057 1058 $this->assertContains( 'meta-2', $sidebars_widgets['wp_inactive_widgets'] ); 1059 $this->assertContains( 'search-2', $sidebars_widgets['wp_inactive_widgets'] ); 1060 $this->assertContains( 'archives-2', $sidebars_widgets['wp_inactive_widgets'] ); 1061 $this->assertContains( 'categories-2', $sidebars_widgets['wp_inactive_widgets'] ); 1062 $this->assertContains( 'recent-posts-2', $sidebars_widgets['wp_inactive_widgets'] ); 1063 $this->assertContains( 'recent-comments-2', $sidebars_widgets['wp_inactive_widgets'] ); 1070 $this->assertCount( 5, $sidebars_widgets['wp_inactive_widgets'] ); 1071 1072 $this->assertContains( 'block-2', $sidebars_widgets['wp_inactive_widgets'] ); 1073 $this->assertContains( 'block-3', $sidebars_widgets['wp_inactive_widgets'] ); 1074 $this->assertContains( 'block-4', $sidebars_widgets['wp_inactive_widgets'] ); 1075 $this->assertContains( 'block-5', $sidebars_widgets['wp_inactive_widgets'] ); 1076 $this->assertContains( 'block-6', $sidebars_widgets['wp_inactive_widgets'] ); 1064 1077 1065 1078 // Theme mod with previous widgets was not removed. … … 1118 1131 } 1119 1132 1120 // 6 default widgets + 1 orphaned calendar widget = 7.1121 $this->assertCount( 7, $sidebars_widgets['wp_inactive_widgets'] );1133 // 5 default widgets + 1 orphaned calendar widget = 6. 1134 $this->assertCount( 6, $sidebars_widgets['wp_inactive_widgets'] ); 1122 1135 $this->assertContains( 'calendar-1', $sidebars_widgets['wp_inactive_widgets'] ); 1123 1136 $this->assertArrayNotHasKey( 'orphaned_widgets_1', $sidebars_widgets );
Note: See TracChangeset
for help on using the changeset viewer.