| 249 | /** |
| 250 | * @ticket 30306 |
| 251 | * (https://core.trac.wordpress.org/ticket/30306) |
| 252 | */ |
| 253 | function test_wp_dropdown_categories_option_value_return() { |
| 254 | // Create a test category. |
| 255 | $cat_id = $this->factory->category->create( |
| 256 | array( |
| 257 | 'name' => 'Test Category', |
| 258 | 'slug' => 'test_category' |
| 259 | ) |
| 260 | ); |
| 261 | // Get the default functionality of wp_dropdown_categories(). |
| 262 | $dropdown_default = wp_dropdown_categories( |
| 263 | array( |
| 264 | 'echo' => 0, |
| 265 | 'hide_empty' => 0, |
| 266 | ) |
| 267 | ); |
| 268 | // Test to see if it returns the default with the category ID. |
| 269 | $this->assertContains( 'value="' . $cat_id . '"', $dropdown_default ); |
| 270 | |
| 271 | // Get the select dropdown with the 'value_field' set to 'slug'. |
| 272 | $dropdown_with_slug = wp_dropdown_categories( |
| 273 | array( |
| 274 | 'echo' => 0, |
| 275 | 'hide_empty' => 0, |
| 276 | 'value_field' => 'slug' |
| 277 | ) |
| 278 | ); |
| 279 | // Test to see if it properly returns the slug of the category you created. |
| 280 | $this->assertContains( 'value="test_category"', $dropdown_with_slug ); |
| 281 | |
| 282 | // Get the select dropdown with the 'value_field' set to something not part of the $category object. |
| 283 | $dropdown_with_odd_value = wp_dropdown_categories( |
| 284 | array( |
| 285 | 'echo' => 0, |
| 286 | 'hide_empty' => 0, |
| 287 | 'value_field' => 'banana' |
| 288 | ) |
| 289 | ); |
| 290 | |
| 291 | // Test to see if it returns the default with the category ID when the 'value_field' is set to something not in the $category object. |
| 292 | $this->assertContains( 'value="' . $cat_id . '"', $dropdown_default ); |