Changeset 34780 for trunk/tests/phpunit/tests/widgets.php
- Timestamp:
- 10/02/2015 08:23:54 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/widgets.php
r34563 r34780 158 158 /** 159 159 * @see WP_Widget::get_field_name() 160 */ 161 function test_wp_widget_get_field_name() { 160 * @dataProvider data_wp_widget_get_field_name 161 * 162 */ 163 function test_wp_widget_get_field_name( $expected, $value_to_test ) { 162 164 $widget = new WP_Widget( 'foo', 'Foo' ); 163 165 $widget->_set( 2 ); 164 $this->assertEquals( 'widget-foo[2][title]', $widget->get_field_name( 'title' ) ); 166 $this->assertEquals( $expected, $widget->get_field_name( $value_to_test ) ); 167 } 168 169 /** 170 * Data provider. 171 * 172 * Passes the expected field name and the value to test. 173 * 174 * @since 4.4.0 175 * 176 * @return array { 177 * @type array { 178 * @type string $expected The expected field id to be returned. 179 * @type string $value_to_test The value being passed to the get_field_name method. 180 * } 181 * } 182 */ 183 function data_wp_widget_get_field_name( ) { 184 185 return array( 186 array( 187 'widget-foo[2][title]', 188 'title', 189 ), 190 array( 191 'widget-foo[2][posttypes][]', 192 'posttypes[]', 193 ), 194 array( 195 'widget-foo[2][posttypes][4]', 196 'posttypes[4]', 197 ), 198 array( 199 'widget-foo[2][posttypes][4][]', 200 'posttypes[4][]', 201 ), 202 array( 203 'widget-foo[2][posttypes][4][][6]', 204 'posttypes[4][][6]', 205 ), 206 ); 165 207 } 166 208 167 209 /** 168 210 * @see WP_Widget::get_field_id() 169 */ 170 function test_wp_widget_get_field_id() { 211 * @dataProvider data_wp_widget_get_field_id 212 * 213 */ 214 function test_wp_widget_get_field_id( $expected, $value_to_test ) { 171 215 $widget = new WP_Widget( 'foo', 'Foo' ); 172 216 $widget->_set( 2 ); 173 $this->assertEquals( 'widget-foo-2-title', $widget->get_field_id( 'title' ) ); 217 $this->assertEquals( $expected, $widget->get_field_id( $value_to_test ) ); 218 } 219 220 221 /** 222 * Data provider. 223 * 224 * Passes the expected field id and the value to be used in the tests. 225 * 226 * @since 4.4.0 227 * 228 * @return array { 229 * @type array { 230 * @type string $expected The expected field id to be returned. 231 * @type string $value_to_test The value being passed to the get_field_id method. 232 * } 233 * } 234 */ 235 function data_wp_widget_get_field_id() { 236 return array( 237 array( 238 'widget-foo-2-title', 239 'title', 240 ), 241 array( 242 'widget-foo-2-posttypes', 243 'posttypes[]', 244 ), 245 array( 246 'widget-foo-2-posttypes-4', 247 'posttypes[4]', 248 ), 249 array( 250 'widget-foo-2-posttypes-4', 251 'posttypes[4][]', 252 ), 253 array( 254 'widget-foo-2-posttypes-4-6', 255 'posttypes[4][][6]', 256 ), 257 ); 174 258 } 175 259
Note: See TracChangeset
for help on using the changeset viewer.