Changeset 37464 for trunk/tests/phpunit/tests/category.php
- Timestamp:
- 05/19/2016 02:22:59 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/category.php
r35242 r37464 243 243 $this->assertNull( get_category_by_path( 'nocat/nocat/', false) ); 244 244 } 245 246 /**247 * @ticket 30306248 */249 public function test_wp_dropdown_categories_value_field_should_default_to_term_id() {250 // Create a test category.251 $cat_id = self::factory()->category->create( array(252 'name' => 'Test Category',253 'slug' => 'test_category',254 ) );255 256 // Get the default functionality of wp_dropdown_categories().257 $dropdown_default = wp_dropdown_categories( array(258 'echo' => 0,259 'hide_empty' => 0,260 ) );261 262 // Test to see if it returns the default with the category ID.263 $this->assertContains( 'value="' . $cat_id . '"', $dropdown_default );264 }265 266 /**267 * @ticket 30306268 */269 public function test_wp_dropdown_categories_value_field_term_id() {270 // Create a test category.271 $cat_id = self::factory()->category->create( array(272 'name' => 'Test Category',273 'slug' => 'test_category',274 ) );275 276 // Get the default functionality of wp_dropdown_categories().277 $found = wp_dropdown_categories( array(278 'echo' => 0,279 'hide_empty' => 0,280 'value_field' => 'term_id',281 ) );282 283 // Test to see if it returns the default with the category ID.284 $this->assertContains( 'value="' . $cat_id . '"', $found );285 }286 287 /**288 * @ticket 30306289 */290 public function test_wp_dropdown_categories_value_field_slug() {291 // Create a test category.292 $cat_id = self::factory()->category->create( array(293 'name' => 'Test Category',294 'slug' => 'test_category',295 ) );296 297 // Get the default functionality of wp_dropdown_categories().298 $found = wp_dropdown_categories( array(299 'echo' => 0,300 'hide_empty' => 0,301 'value_field' => 'slug',302 ) );303 304 // Test to see if it returns the default with the category slug.305 $this->assertContains( 'value="test_category"', $found );306 }307 308 /**309 * @ticket 30306310 */311 public function test_wp_dropdown_categories_value_field_should_fall_back_on_term_id_when_an_invalid_value_is_provided() {312 // Create a test category.313 $cat_id = self::factory()->category->create( array(314 'name' => 'Test Category',315 'slug' => 'test_category',316 ) );317 318 // Get the default functionality of wp_dropdown_categories().319 $found = wp_dropdown_categories( array(320 'echo' => 0,321 'hide_empty' => 0,322 'value_field' => 'foo',323 ) );324 325 // Test to see if it returns the default with the category slug.326 $this->assertContains( 'value="' . $cat_id . '"', $found );327 }328 329 /**330 * @ticket 32330331 */332 public function test_wp_dropdown_categories_selected_should_respect_custom_value_field() {333 $c1 = self::factory()->category->create( array(334 'name' => 'Test Category 1',335 'slug' => 'test_category_1',336 ) );337 338 $c2 = self::factory()->category->create( array(339 'name' => 'Test Category 2',340 'slug' => 'test_category_2',341 ) );342 343 $found = wp_dropdown_categories( array(344 'echo' => 0,345 'hide_empty' => 0,346 'value_field' => 'slug',347 'selected' => 'test_category_2',348 ) );349 350 $this->assertContains( "value=\"test_category_2\" selected=\"selected\"", $found );351 }352 353 /**354 * @ticket 33452355 */356 public function test_wp_dropdown_categories_show_option_all_should_be_selected_if_no_selected_value_is_explicitly_passed_and_value_field_does_not_have_string_values() {357 $cats = self::factory()->category->create_many( 3 );358 359 $found = wp_dropdown_categories( array(360 'echo' => 0,361 'hide_empty' => 0,362 'show_option_all' => 'Foo',363 'value_field' => 'slug',364 ) );365 366 $this->assertContains( "value='0' selected='selected'", $found );367 368 foreach ( $cats as $cat ) {369 $_cat = get_term( $cat, 'category' );370 $this->assertNotContains( 'value="' . $_cat->slug . '" selected="selected"', $found );371 }372 }373 374 /**375 * @ticket 33452376 */377 public function test_wp_dropdown_categories_show_option_all_should_be_selected_if_selected_value_of_0_string_is_explicitly_passed_and_value_field_does_not_have_string_values() {378 $cats = self::factory()->category->create_many( 3 );379 380 $found = wp_dropdown_categories( array(381 'echo' => 0,382 'hide_empty' => 0,383 'show_option_all' => 'Foo',384 'value_field' => 'slug',385 'selected' => '0',386 ) );387 388 $this->assertContains( "value='0' selected='selected'", $found );389 390 foreach ( $cats as $cat ) {391 $_cat = get_term( $cat, 'category' );392 $this->assertNotContains( 'value="' . $_cat->slug . '" selected="selected"', $found );393 }394 }395 245 }
Note: See TracChangeset
for help on using the changeset viewer.