| | 705 | |
| | 706 | /** |
| | 707 | * @ticket 29614 |
| | 708 | */ |
| | 709 | function test_orphan_category_update() { |
| | 710 | $parent_cat_id1 = $this->factory->category->create(); |
| | 711 | $parent_cat_id2 = $this->factory->category->create(); |
| | 712 | |
| | 713 | $child_cat_id = $this->factory->category->create( array( 'parent' => $parent_cat_id1 ) ); |
| | 714 | |
| | 715 | wp_update_term( $child_cat_id, 'category', array( 'parent' => $parent_cat_id2 ) ); |
| | 716 | |
| | 717 | //Test if the parent term has changed |
| | 718 | $child_cat_term = get_term( $child_cat_id, 'category' ); |
| | 719 | $this->assertEquals( $child_cat_term->parent, $parent_cat_id2 ); |
| | 720 | |
| | 721 | wp_delete_category( $parent_cat_id2 ); |
| | 722 | clean_term_cache( $child_cat_id, 'category' ); |
| | 723 | |
| | 724 | //Test if the parent is set to 0 |
| | 725 | $child_cat_term = get_term( $child_cat_id, 'category' ); |
| | 726 | $this->assertEquals( $child_cat_term->parent, 0 ); |
| | 727 | |
| | 728 | //Test for WP_Error when updating to a deleted parent |
| | 729 | $cat_id2 = wp_update_term( $child_cat_id, 'category', array( 'parent' => $parent_cat_id2 ) ); |
| | 730 | $this->assertWPError( $cat_id2 ); |
| | 731 | |
| | 732 | } |