Move `wp_dropdown_categories()` tests into their own file.

See #31909.


git-svn-id: https://develop.svn.wordpress.org/trunk@37464 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-05-19 02:22:59 +00:00
parent 20fbd41ebe
commit 510bbfcb9c
2 changed files with 156 additions and 150 deletions

View File

@ -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 );
}
}
}

View File

@ -0,0 +1,156 @@
<?php
/**
* @group taxonomy
* @group category.php
*/
class Tests_Category_WpDropdownCategories extends WP_UnitTestCase {
/**
* @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 );
}
}
}