Changeset 34817 for trunk/tests/phpunit/tests/widgets.php
- Timestamp:
- 10/04/2015 05:22:11 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/widgets.php
r34816 r34817 7 7 */ 8 8 class Tests_Widgets extends WP_UnitTestCase { 9 public $sidebar_index; 10 public $valid_sidebar; 9 11 10 12 function clean_up_global_scope() { … … 23 25 global $wp_customize; 24 26 $wp_customize = null; 27 25 28 parent::tearDown(); 26 29 } … … 42 45 43 46 /** 44 * @ see register_sidebars()47 * @group sidebar 45 48 */ 46 49 function test_register_sidebars_single() { … … 55 58 56 59 /** 57 * @ see register_sidebars()60 * @group sidebar 58 61 */ 59 62 function test_register_sidebars_multiple() { … … 78 81 79 82 /** 80 * @see register_sidebar 81 * @see unregister_sidebar 82 */ 83 function test_register_and_unregister_sidebar() { 83 * @group sidebar 84 */ 85 function test_register_sidebar_with_no_id() { 86 global $wp_registered_sidebars; 87 88 $this->setExpectedIncorrectUsage( 'register_sidebar' ); 89 90 // Incorrectly register a couple of sidebars for fun. 91 register_sidebar(); 92 register_sidebar(); 93 94 $derived_sidebar_id = "sidebar-2"; // Number of sidebars in the global + 1. 95 96 $this->assertArrayHasKey( $derived_sidebar_id, $wp_registered_sidebars ); 97 } 98 99 /** 100 * @group sidebar 101 */ 102 function test_unregister_sidebar_registered_with_no_id() { 103 global $wp_registered_sidebars; 104 105 $this->setExpectedIncorrectUsage( 'register_sidebar' ); 106 107 // Incorrectly register a couple of sidebars for fun. 108 register_sidebar(); 109 register_sidebar(); 110 111 $derived_sidebar_id = "sidebar-2"; // Number of sidebars in the global + 1. 112 113 unregister_sidebar( $derived_sidebar_id ); 114 115 $this->assertArrayNotHasKey( $derived_sidebar_id, $wp_registered_sidebars ); 116 } 117 118 /** 119 * @group sidebar 120 */ 121 function test_register_sidebar_with_string_id() { 84 122 85 123 global $wp_registered_sidebars; … … 87 125 $sidebar_id = 'wp-unit-test'; 88 126 register_sidebar( array( 'id' => $sidebar_id ) ); 127 89 128 $this->assertArrayHasKey( $sidebar_id, $wp_registered_sidebars ); 129 } 130 131 /** 132 * @group sidebar 133 */ 134 function test_unregister_sidebar_with_string_id() { 135 global $wp_registered_sidebars; 136 137 $sidebar_id = 'wp-unit-tests'; 138 register_sidebar( array( 'id' => $sidebar_id ) ); 90 139 91 140 unregister_sidebar( $sidebar_id ); 92 $this->assertArrayNotHasKey( 'wp-unit-test', $wp_registered_sidebars ); 141 $this->assertArrayNotHasKey( $sidebar_id, $wp_registered_sidebars ); 142 } 143 144 /** 145 * @group sidebar 146 */ 147 function test_register_sidebar_with_numeric_id() { 148 global $wp_registered_sidebars; 149 150 $sidebar_id = 2; 151 register_sidebar( array( 'id' => $sidebar_id ) ); 152 153 $this->assertArrayHasKey( $sidebar_id, $wp_registered_sidebars ); 154 } 155 156 /** 157 * @group sidebar 158 */ 159 function test_unregister_sidebar_with_numeric_id() { 160 global $wp_registered_sidebars; 161 162 $sidebar_id = 2; 163 register_sidebar( array( 'id' => $sidebar_id ) ); 164 165 unregister_sidebar( $sidebar_id ); 166 $this->assertArrayNotHasKey( $sidebar_id, $wp_registered_sidebars ); 93 167 } 94 168 … … 96 170 * Utility hook callback used to store a sidebar ID mid-function. 97 171 */ 98 function retrieve_sidebar_id( $index ) {172 function retrieve_sidebar_id( $index, $valid_sidebar ) { 99 173 $this->sidebar_index = $index; 100 } 101 102 /** 103 * @group sidebar 174 $this->valid_sidebar = $valid_sidebar; 175 } 176 177 /** 178 * @group sidebar 179 * @group drew 104 180 */ 105 181 function test_dynamic_sidebar_using_sidebar_registered_with_no_id() { 106 global $wp_registered_sidebars;107 108 182 $this->setExpectedIncorrectUsage( 'register_sidebar' ); 109 183 110 // Register a couple of sidebars for fun.184 // Incorrectly register a couple of sidebars for fun. 111 185 register_sidebar(); 112 186 register_sidebar(); 113 187 114 $derived_sidebar_id = "sidebar- 3"; // Number of sidebars in the global + 1.115 116 add_action( 'dynamic_sidebar_before', array( $this, 'retrieve_sidebar_id' ) );117 118 dynamic_sidebar( 3);188 $derived_sidebar_id = "sidebar-2"; // Number of sidebars in the global + 1. 189 190 add_action( 'dynamic_sidebar_before', array( $this, 'retrieve_sidebar_id' ), 10, 2 ); 191 192 dynamic_sidebar( 2 ); 119 193 120 194 $this->assertSame( $derived_sidebar_id, $this->sidebar_index ); 195 } 196 197 /** 198 * @group sidebar 199 */ 200 function test_dynamic_sidebar_using_invalid_sidebar_id() { 201 register_sidebar( array( 'id' => 'wp-unit-text' ) ); 202 203 add_action( 'dynamic_sidebar_before', array( $this, 'retrieve_sidebar_id' ), 10, 2 ); 204 205 // 5 is a fake sidebar ID. 206 dynamic_sidebar( 5 ); 207 208 /* 209 * If the sidebar ID is invalid, the second argument passed to 210 * the 'dynamic_sidebar_before' hook will be false. 211 */ 212 $this->assertSame( false, $this->valid_sidebar ); 121 213 } 122 214 … … 128 220 register_sidebar( array( 'id' => $sidebar_id ) ); 129 221 130 add_action( 'dynamic_sidebar_before', array( $this, 'retrieve_sidebar_id' ) );222 add_action( 'dynamic_sidebar_before', array( $this, 'retrieve_sidebar_id' ), 10, 2 ); 131 223 132 224 dynamic_sidebar( $sidebar_id ); … … 142 234 register_sidebar( array( 'id' => $sidebar_id ) ); 143 235 144 add_action( 'dynamic_sidebar_before', array( $this, 'retrieve_sidebar_id' ) );236 add_action( 'dynamic_sidebar_before', array( $this, 'retrieve_sidebar_id' ), 10, 2 ); 145 237 146 238 dynamic_sidebar( $sidebar_id );
Note: See TracChangeset
for help on using the changeset viewer.