Changeset 48043 for trunk/tests/phpunit/tests/term.php
- Timestamp:
- 06/14/2020 09:40:10 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term.php
r47341 r48043 157 157 $this->assertEquals( 1, count( $post->post_category ) ); 158 158 $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); 159 159 160 $term1 = wp_insert_term( 'Foo', 'category' ); 160 161 $term2 = wp_insert_term( 'Bar', 'category' ); 161 162 $term3 = wp_insert_term( 'Baz', 'category' ); 163 162 164 wp_set_post_categories( $post_id, array( $term1['term_id'], $term2['term_id'] ) ); 163 165 $this->assertEquals( 2, count( $post->post_category ) ); … … 168 170 169 171 $term4 = wp_insert_term( 'Burrito', 'category' ); 172 170 173 wp_set_post_categories( $post_id, $term4['term_id'] ); 171 174 $this->assertEquals( array( $term4['term_id'] ), $post->post_category ); … … 181 184 $this->assertEquals( 1, count( $post->post_category ) ); 182 185 $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); 186 } 187 188 /** 189 * @ticket 43516 190 */ 191 function test_wp_set_post_categories_sets_default_category_for_custom_post_types() { 192 add_filter( 'default_category_post_types', array( $this, 'filter_default_category_post_types' ) ); 193 194 register_post_type( 'cpt', array( 'taxonomies' => array( 'category' ) ) ); 195 196 $post_id = self::factory()->post->create( array( 'post_type' => 'cpt' ) ); 197 $post = get_post( $post_id ); 198 199 $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); 200 201 $term = wp_insert_term( 'Foo', 'category' ); 202 203 wp_set_post_categories( $post_id, $term['term_id'] ); 204 $this->assertEquals( $term['term_id'], $post->post_category[0] ); 205 206 wp_set_post_categories( $post_id, array() ); 207 $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); 208 209 remove_filter( 'default_category_post_types', array( $this, 'filter_default_category_post_types' ) ); 210 } 211 212 function filter_default_category_post_types( $post_types ) { 213 $post_types[] = 'cpt'; 214 return $post_types; 183 215 } 184 216
Note: See TracChangeset
for help on using the changeset viewer.