| | 168 | |
| | 169 | /** |
| | 170 | * @ticket 15806 |
| | 171 | */ |
| | 172 | public function test_hide_empty_should_exclude_terms_with_only_draft_posts() { |
| | 173 | register_post_type( 'wptests_pt' ); |
| | 174 | register_taxonomy( 'wptests_tax_1', 'wptests_pt' ); |
| | 175 | $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); |
| | 176 | $p = self::factory()->post->create( array( 'post_type' => 'wptests_pt', 'post_status' => 'draft' ) ); |
| | 177 | wp_set_object_terms( $p, $t, 'wptests_tax_1' ); |
| | 178 | |
| | 179 | $q = new WP_Term_Query( array( |
| | 180 | 'hide_empty' => true, |
| | 181 | 'taxonomy' => 'wptests_tax_1', |
| | 182 | ) ); |
| | 183 | |
| | 184 | $this->assertEmpty( $q->terms ); |
| | 185 | } |
| | 186 | |
| | 187 | /** |
| | 188 | * @ticket 15806 |
| | 189 | */ |
| | 190 | public function test_hide_empty_should_exclude_terms_with_posts_that_have_been_unpublished() { |
| | 191 | register_post_type( 'wptests_pt' ); |
| | 192 | register_taxonomy( 'wptests_tax_1', 'wptests_pt' ); |
| | 193 | $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); |
| | 194 | $p = self::factory()->post->create( array( 'post_type' => 'wptests_pt', 'post_status' => 'publish' ) ); |
| | 195 | wp_set_object_terms( $p, $t, 'wptests_tax_1' ); |
| | 196 | |
| | 197 | wp_update_post( array( |
| | 198 | 'ID' => $p, |
| | 199 | 'post_status' => 'draft', |
| | 200 | ) ); |
| | 201 | |
| | 202 | $q = new WP_Term_Query( array( |
| | 203 | 'hide_empty' => true, |
| | 204 | 'taxonomy' => 'wptests_tax_1', |
| | 205 | ) ); |
| | 206 | |
| | 207 | $this->assertEmpty( $q->terms ); |
| | 208 | } |
| | 209 | |
| | 210 | /** |
| | 211 | * @ticket 15806 |
| | 212 | */ |
| | 213 | public function test_hide_empty_should_exclude_terms_with_posts_that_have_been_trash() { |
| | 214 | register_post_type( 'wptests_pt' ); |
| | 215 | register_taxonomy( 'wptests_tax_1', 'wptests_pt' ); |
| | 216 | $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); |
| | 217 | $p = self::factory()->post->create( array( 'post_type' => 'wptests_pt', 'post_status' => 'publish' ) ); |
| | 218 | wp_set_object_terms( $p, $t, 'wptests_tax_1' ); |
| | 219 | |
| | 220 | $q = new WP_Term_Query( array( |
| | 221 | 'hide_empty' => true, |
| | 222 | 'taxonomy' => 'wptests_tax_1', |
| | 223 | ) ); |
| | 224 | |
| | 225 | $this->assertSame( array( $t ), wp_list_pluck( $q->terms, 'term_id' ) ); |
| | 226 | |
| | 227 | wp_trash_post( $p ); |
| | 228 | |
| | 229 | $terms = get_terms( array( |
| | 230 | 'hide_empty' => true, |
| | 231 | 'taxonomy' => 'wptests_tax_1', |
| | 232 | ) ); |
| | 233 | |
| | 234 | $this->assertEmpty( $terms ); |
| | 235 | } |