diff --git a/tests/phpunit/tests/category.php b/tests/phpunit/tests/category.php index 913f4dc776..255f767ea5 100644 --- a/tests/phpunit/tests/category.php +++ b/tests/phpunit/tests/category.php @@ -242,154 +242,4 @@ class Tests_Category extends WP_UnitTestCase { $this->assertEquals( $root_level_id, $ret_cat->term_id ); $this->assertNull( get_category_by_path( 'nocat/nocat/', false) ); } - - /** - * @ticket 30306 - */ - public function test_wp_dropdown_categories_value_field_should_default_to_term_id() { - // Create a test category. - $cat_id = self::factory()->category->create( array( - 'name' => 'Test Category', - 'slug' => 'test_category', - ) ); - - // Get the default functionality of wp_dropdown_categories(). - $dropdown_default = wp_dropdown_categories( array( - 'echo' => 0, - 'hide_empty' => 0, - ) ); - - // Test to see if it returns the default with the category ID. - $this->assertContains( 'value="' . $cat_id . '"', $dropdown_default ); - } - - /** - * @ticket 30306 - */ - public function test_wp_dropdown_categories_value_field_term_id() { - // Create a test category. - $cat_id = self::factory()->category->create( array( - 'name' => 'Test Category', - 'slug' => 'test_category', - ) ); - - // Get the default functionality of wp_dropdown_categories(). - $found = wp_dropdown_categories( array( - 'echo' => 0, - 'hide_empty' => 0, - 'value_field' => 'term_id', - ) ); - - // Test to see if it returns the default with the category ID. - $this->assertContains( 'value="' . $cat_id . '"', $found ); - } - - /** - * @ticket 30306 - */ - public function test_wp_dropdown_categories_value_field_slug() { - // Create a test category. - $cat_id = self::factory()->category->create( array( - 'name' => 'Test Category', - 'slug' => 'test_category', - ) ); - - // Get the default functionality of wp_dropdown_categories(). - $found = wp_dropdown_categories( array( - 'echo' => 0, - 'hide_empty' => 0, - 'value_field' => 'slug', - ) ); - - // Test to see if it returns the default with the category slug. - $this->assertContains( 'value="test_category"', $found ); - } - - /** - * @ticket 30306 - */ - public function test_wp_dropdown_categories_value_field_should_fall_back_on_term_id_when_an_invalid_value_is_provided() { - // Create a test category. - $cat_id = self::factory()->category->create( array( - 'name' => 'Test Category', - 'slug' => 'test_category', - ) ); - - // Get the default functionality of wp_dropdown_categories(). - $found = wp_dropdown_categories( array( - 'echo' => 0, - 'hide_empty' => 0, - 'value_field' => 'foo', - ) ); - - // Test to see if it returns the default with the category slug. - $this->assertContains( 'value="' . $cat_id . '"', $found ); - } - - /** - * @ticket 32330 - */ - public function test_wp_dropdown_categories_selected_should_respect_custom_value_field() { - $c1 = self::factory()->category->create( array( - 'name' => 'Test Category 1', - 'slug' => 'test_category_1', - ) ); - - $c2 = self::factory()->category->create( array( - 'name' => 'Test Category 2', - 'slug' => 'test_category_2', - ) ); - - $found = wp_dropdown_categories( array( - 'echo' => 0, - 'hide_empty' => 0, - 'value_field' => 'slug', - 'selected' => 'test_category_2', - ) ); - - $this->assertContains( "value=\"test_category_2\" selected=\"selected\"", $found ); - } - - /** - * @ticket 33452 - */ - 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() { - $cats = self::factory()->category->create_many( 3 ); - - $found = wp_dropdown_categories( array( - 'echo' => 0, - 'hide_empty' => 0, - 'show_option_all' => 'Foo', - 'value_field' => 'slug', - ) ); - - $this->assertContains( "value='0' selected='selected'", $found ); - - foreach ( $cats as $cat ) { - $_cat = get_term( $cat, 'category' ); - $this->assertNotContains( 'value="' . $_cat->slug . '" selected="selected"', $found ); - } - } - - /** - * @ticket 33452 - */ - 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() { - $cats = self::factory()->category->create_many( 3 ); - - $found = wp_dropdown_categories( array( - 'echo' => 0, - 'hide_empty' => 0, - 'show_option_all' => 'Foo', - 'value_field' => 'slug', - 'selected' => '0', - ) ); - - $this->assertContains( "value='0' selected='selected'", $found ); - - foreach ( $cats as $cat ) { - $_cat = get_term( $cat, 'category' ); - $this->assertNotContains( 'value="' . $_cat->slug . '" selected="selected"', $found ); - } - } } diff --git a/tests/phpunit/tests/category/wpDropdownCategories.php b/tests/phpunit/tests/category/wpDropdownCategories.php new file mode 100644 index 0000000000..4750370222 --- /dev/null +++ b/tests/phpunit/tests/category/wpDropdownCategories.php @@ -0,0 +1,156 @@ +category->create( array( + 'name' => 'Test Category', + 'slug' => 'test_category', + ) ); + + // Get the default functionality of wp_dropdown_categories(). + $dropdown_default = wp_dropdown_categories( array( + 'echo' => 0, + 'hide_empty' => 0, + ) ); + + // Test to see if it returns the default with the category ID. + $this->assertContains( 'value="' . $cat_id . '"', $dropdown_default ); + } + + /** + * @ticket 30306 + */ + public function test_wp_dropdown_categories_value_field_term_id() { + // Create a test category. + $cat_id = self::factory()->category->create( array( + 'name' => 'Test Category', + 'slug' => 'test_category', + ) ); + + // Get the default functionality of wp_dropdown_categories(). + $found = wp_dropdown_categories( array( + 'echo' => 0, + 'hide_empty' => 0, + 'value_field' => 'term_id', + ) ); + + // Test to see if it returns the default with the category ID. + $this->assertContains( 'value="' . $cat_id . '"', $found ); + } + + /** + * @ticket 30306 + */ + public function test_wp_dropdown_categories_value_field_slug() { + // Create a test category. + $cat_id = self::factory()->category->create( array( + 'name' => 'Test Category', + 'slug' => 'test_category', + ) ); + + // Get the default functionality of wp_dropdown_categories(). + $found = wp_dropdown_categories( array( + 'echo' => 0, + 'hide_empty' => 0, + 'value_field' => 'slug', + ) ); + + // Test to see if it returns the default with the category slug. + $this->assertContains( 'value="test_category"', $found ); + } + + /** + * @ticket 30306 + */ + public function test_wp_dropdown_categories_value_field_should_fall_back_on_term_id_when_an_invalid_value_is_provided() { + // Create a test category. + $cat_id = self::factory()->category->create( array( + 'name' => 'Test Category', + 'slug' => 'test_category', + ) ); + + // Get the default functionality of wp_dropdown_categories(). + $found = wp_dropdown_categories( array( + 'echo' => 0, + 'hide_empty' => 0, + 'value_field' => 'foo', + ) ); + + // Test to see if it returns the default with the category slug. + $this->assertContains( 'value="' . $cat_id . '"', $found ); + } + + /** + * @ticket 32330 + */ + public function test_wp_dropdown_categories_selected_should_respect_custom_value_field() { + $c1 = self::factory()->category->create( array( + 'name' => 'Test Category 1', + 'slug' => 'test_category_1', + ) ); + + $c2 = self::factory()->category->create( array( + 'name' => 'Test Category 2', + 'slug' => 'test_category_2', + ) ); + + $found = wp_dropdown_categories( array( + 'echo' => 0, + 'hide_empty' => 0, + 'value_field' => 'slug', + 'selected' => 'test_category_2', + ) ); + + $this->assertContains( "value=\"test_category_2\" selected=\"selected\"", $found ); + } + + /** + * @ticket 33452 + */ + 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() { + $cats = self::factory()->category->create_many( 3 ); + + $found = wp_dropdown_categories( array( + 'echo' => 0, + 'hide_empty' => 0, + 'show_option_all' => 'Foo', + 'value_field' => 'slug', + ) ); + + $this->assertContains( "value='0' selected='selected'", $found ); + + foreach ( $cats as $cat ) { + $_cat = get_term( $cat, 'category' ); + $this->assertNotContains( 'value="' . $_cat->slug . '" selected="selected"', $found ); + } + } + + /** + * @ticket 33452 + */ + 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() { + $cats = self::factory()->category->create_many( 3 ); + + $found = wp_dropdown_categories( array( + 'echo' => 0, + 'hide_empty' => 0, + 'show_option_all' => 'Foo', + 'value_field' => 'slug', + 'selected' => '0', + ) ); + + $this->assertContains( "value='0' selected='selected'", $found ); + + foreach ( $cats as $cat ) { + $_cat = get_term( $cat, 'category' ); + $this->assertNotContains( 'value="' . $_cat->slug . '" selected="selected"', $found ); + } + } +}