| 1469 | |
| 1470 | /** |
| 1471 | * Test that setting void category for CPT associated with 'category' taxonomy has default category. |
| 1472 | * |
| 1473 | * @ticket 43516 |
| 1474 | */ |
| 1475 | function test_set_post_category_cpt_default_category () { |
| 1476 | $term = wp_insert_term( 'Foo', 'category' ); |
| 1477 | |
| 1478 | $post_id = wp_insert_post( array( 'post_title' => 'Foo', 'post_category' => array( $term['term_id'] ) ) ); |
| 1479 | $post = get_post( $post_id ); |
| 1480 | $this->assertInternalType( 'array', $post->post_category ); |
| 1481 | $this->assertEquals( $term['term_id'], $post->post_category[0] ); |
| 1482 | |
| 1483 | // Reset categories. |
| 1484 | wp_set_post_categories( $post_id, array() ); |
| 1485 | $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); |
| 1486 | |
| 1487 | register_post_type( 'cpt', array( 'taxonomies' => array( 'category' ) ) ); |
| 1488 | $post_id = wp_insert_post( array( 'post_title' => 'Foo', 'post_type' => 'cpt', 'post_category' => array( $term['term_id'] ) ) ); |
| 1489 | $post = get_post( $post_id ); |
| 1490 | |
| 1491 | // Reset categories. |
| 1492 | wp_set_post_categories( $post_id, array() ); |
| 1493 | $this->assertInternalType( 'array', $post->post_category ); |
| 1494 | $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); |
| 1495 | } |
| 1496 | |
| 1497 | /** |
| 1498 | * Test that inserting 'post' and CPT associated with 'category' taxonomy has default category. |
| 1499 | * |
| 1500 | * @ticket 43516 |
| 1501 | */ |
| 1502 | function test_insert_post_cpt_has_default_category () { |
| 1503 | $id = wp_insert_post( array( 'post_title' => 'Foo' ) ); |
| 1504 | $post = get_post( $id ); |
| 1505 | $this->assertInternalType( 'array', $post->post_category ); |
| 1506 | $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); |
| 1507 | |
| 1508 | register_post_type( 'cpt', array( 'taxonomies' => array( 'category' ) ) ); |
| 1509 | $id = wp_insert_post( array( 'post_title' => 'Foo', 'post_type' => 'cpt' ) ); |
| 1510 | $post = get_post( $id ); |
| 1511 | $this->assertInternalType( 'array', $post->post_category ); |
| 1512 | $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); |
| 1513 | } |