- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/category/wpDropdownCategories.php
r37465 r42343 10 10 public function test_wp_dropdown_categories_value_field_should_default_to_term_id() { 11 11 // Create a test category. 12 $cat_id = self::factory()->category->create( array( 13 'name' => 'Test Category', 14 'slug' => 'test_category', 15 ) ); 16 17 // Get the default functionality of wp_dropdown_categories(). 18 $dropdown_default = wp_dropdown_categories( array( 19 'echo' => 0, 20 'hide_empty' => 0, 21 ) ); 12 $cat_id = self::factory()->category->create( 13 array( 14 'name' => 'Test Category', 15 'slug' => 'test_category', 16 ) 17 ); 18 19 // Get the default functionality of wp_dropdown_categories(). 20 $dropdown_default = wp_dropdown_categories( 21 array( 22 'echo' => 0, 23 'hide_empty' => 0, 24 ) 25 ); 22 26 23 27 // Test to see if it returns the default with the category ID. … … 30 34 public function test_wp_dropdown_categories_value_field_term_id() { 31 35 // Create a test category. 32 $cat_id = self::factory()->category->create( array( 33 'name' => 'Test Category', 34 'slug' => 'test_category', 35 ) ); 36 37 // Get the default functionality of wp_dropdown_categories(). 38 $found = wp_dropdown_categories( array( 39 'echo' => 0, 40 'hide_empty' => 0, 41 'value_field' => 'term_id', 42 ) ); 36 $cat_id = self::factory()->category->create( 37 array( 38 'name' => 'Test Category', 39 'slug' => 'test_category', 40 ) 41 ); 42 43 // Get the default functionality of wp_dropdown_categories(). 44 $found = wp_dropdown_categories( 45 array( 46 'echo' => 0, 47 'hide_empty' => 0, 48 'value_field' => 'term_id', 49 ) 50 ); 43 51 44 52 // Test to see if it returns the default with the category ID. … … 51 59 public function test_wp_dropdown_categories_value_field_slug() { 52 60 // Create a test category. 53 $cat_id = self::factory()->category->create( array( 54 'name' => 'Test Category', 55 'slug' => 'test_category', 56 ) ); 57 58 // Get the default functionality of wp_dropdown_categories(). 59 $found = wp_dropdown_categories( array( 60 'echo' => 0, 61 'hide_empty' => 0, 62 'value_field' => 'slug', 63 ) ); 61 $cat_id = self::factory()->category->create( 62 array( 63 'name' => 'Test Category', 64 'slug' => 'test_category', 65 ) 66 ); 67 68 // Get the default functionality of wp_dropdown_categories(). 69 $found = wp_dropdown_categories( 70 array( 71 'echo' => 0, 72 'hide_empty' => 0, 73 'value_field' => 'slug', 74 ) 75 ); 64 76 65 77 // Test to see if it returns the default with the category slug. … … 72 84 public function test_wp_dropdown_categories_value_field_should_fall_back_on_term_id_when_an_invalid_value_is_provided() { 73 85 // Create a test category. 74 $cat_id = self::factory()->category->create( array( 75 'name' => 'Test Category', 76 'slug' => 'test_category', 77 ) ); 78 79 // Get the default functionality of wp_dropdown_categories(). 80 $found = wp_dropdown_categories( array( 81 'echo' => 0, 82 'hide_empty' => 0, 83 'value_field' => 'foo', 84 ) ); 86 $cat_id = self::factory()->category->create( 87 array( 88 'name' => 'Test Category', 89 'slug' => 'test_category', 90 ) 91 ); 92 93 // Get the default functionality of wp_dropdown_categories(). 94 $found = wp_dropdown_categories( 95 array( 96 'echo' => 0, 97 'hide_empty' => 0, 98 'value_field' => 'foo', 99 ) 100 ); 85 101 86 102 // Test to see if it returns the default with the category slug. … … 92 108 */ 93 109 public function test_wp_dropdown_categories_selected_should_respect_custom_value_field() { 94 $c1 = self::factory()->category->create( array( 95 'name' => 'Test Category 1', 96 'slug' => 'test_category_1', 97 ) ); 98 99 $c2 = self::factory()->category->create( array( 100 'name' => 'Test Category 2', 101 'slug' => 'test_category_2', 102 ) ); 103 104 $found = wp_dropdown_categories( array( 105 'echo' => 0, 106 'hide_empty' => 0, 107 'value_field' => 'slug', 108 'selected' => 'test_category_2', 109 ) ); 110 111 $this->assertContains( "value=\"test_category_2\" selected=\"selected\"", $found ); 110 $c1 = self::factory()->category->create( 111 array( 112 'name' => 'Test Category 1', 113 'slug' => 'test_category_1', 114 ) 115 ); 116 117 $c2 = self::factory()->category->create( 118 array( 119 'name' => 'Test Category 2', 120 'slug' => 'test_category_2', 121 ) 122 ); 123 124 $found = wp_dropdown_categories( 125 array( 126 'echo' => 0, 127 'hide_empty' => 0, 128 'value_field' => 'slug', 129 'selected' => 'test_category_2', 130 ) 131 ); 132 133 $this->assertContains( 'value="test_category_2" selected="selected"', $found ); 112 134 } 113 135 … … 118 140 $cats = self::factory()->category->create_many( 3 ); 119 141 120 $found = wp_dropdown_categories( array( 121 'echo' => 0, 122 'hide_empty' => 0, 123 'show_option_all' => 'Foo', 124 'value_field' => 'slug', 125 ) ); 142 $found = wp_dropdown_categories( 143 array( 144 'echo' => 0, 145 'hide_empty' => 0, 146 'show_option_all' => 'Foo', 147 'value_field' => 'slug', 148 ) 149 ); 126 150 127 151 $this->assertContains( "value='0' selected='selected'", $found ); … … 139 163 $cats = self::factory()->category->create_many( 3 ); 140 164 141 $found = wp_dropdown_categories( array( 142 'echo' => 0, 143 'hide_empty' => 0, 144 'show_option_all' => 'Foo', 145 'value_field' => 'slug', 146 'selected' => '0', 147 ) ); 165 $found = wp_dropdown_categories( 166 array( 167 'echo' => 0, 168 'hide_empty' => 0, 169 'show_option_all' => 'Foo', 170 'value_field' => 'slug', 171 'selected' => '0', 172 ) 173 ); 148 174 149 175 $this->assertContains( "value='0' selected='selected'", $found ); … … 160 186 public function test_required_true_should_add_required_attribute() { 161 187 // Create a test category. 162 $cat_id = self::factory()->category->create( array( 163 'name' => 'Test Category', 164 'slug' => 'test_category', 165 ) ); 166 167 $args = array( 188 $cat_id = self::factory()->category->create( 189 array( 190 'name' => 'Test Category', 191 'slug' => 'test_category', 192 ) 193 ); 194 195 $args = array( 168 196 'show_option_none' => __( 'Select one', 'text-domain' ), 169 'option_none_value' => "",197 'option_none_value' => '', 170 198 'required' => true, 171 199 'hide_empty' => 0, … … 183 211 public function test_required_false_should_omit_required_attribute() { 184 212 // Create a test category. 185 $cat_id = self::factory()->category->create( array( 186 'name' => 'Test Category', 187 'slug' => 'test_category', 188 ) ); 189 190 $args = array( 213 $cat_id = self::factory()->category->create( 214 array( 215 'name' => 'Test Category', 216 'slug' => 'test_category', 217 ) 218 ); 219 220 $args = array( 191 221 'show_option_none' => __( 'Select one', 'text-domain' ), 192 'option_none_value' => "",222 'option_none_value' => '', 193 223 'required' => false, 194 224 'hide_empty' => 0, … … 206 236 public function test_required_should_default_to_false() { 207 237 // Create a test category. 208 $cat_id = self::factory()->category->create( array( 209 'name' => 'Test Category', 210 'slug' => 'test_category', 211 ) ); 212 213 $args = array( 238 $cat_id = self::factory()->category->create( 239 array( 240 'name' => 'Test Category', 241 'slug' => 'test_category', 242 ) 243 ); 244 245 $args = array( 214 246 'show_option_none' => __( 'Select one', 'text-domain' ), 215 'option_none_value' => "",247 'option_none_value' => '', 216 248 'hide_empty' => 0, 217 249 'echo' => 0,
Note: See TracChangeset
for help on using the changeset viewer.