689 | | $this->assertWPError( $updated ); |
690 | | $this->assertSame( 'duplicate_term_slug', $updated->get_error_code() ); |
| 689 | $this->assertFalse( is_wp_error( $updated ) ); |
| 690 | |
| 691 | $t1_term = get_term( $t1, 'wptests_tax' ); |
| 692 | $t2_term = get_term( $t2, 'wptests_tax_2' ); |
| 693 | $this->assertSame( $t1_term->slug, $t2_term->slug ); |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * @ticket 30780 |
| 698 | */ |
| 699 | public function test_wp_update_term_should_allow_duplicate_names_in_different_taxonomies() { |
| 700 | register_taxonomy( 'wptests_tax', 'post' ); |
| 701 | register_taxonomy( 'wptests_tax_2', 'post' ); |
| 702 | |
| 703 | $t1 = $this->factory->term->create( array( |
| 704 | 'name' => 'Foo', |
| 705 | 'slug' => 'foo', |
| 706 | 'taxonomy' => 'wptests_tax', |
| 707 | ) ); |
| 708 | |
| 709 | $t2 = $this->factory->term->create( array( |
| 710 | 'name' => 'Bar', |
| 711 | 'slug' => 'bar', |
| 712 | 'taxonomy' => 'wptests_tax_2', |
| 713 | ) ); |
| 714 | |
| 715 | $updated = wp_update_term( $t2, 'wptests_tax_2', array( |
| 716 | 'name' => 'Foo', |
| 717 | ) ); |
| 718 | |
| 719 | $this->assertFalse( is_wp_error( $updated ) ); |
| 720 | |
| 721 | $t2_term = get_term( $t2, 'wptests_tax_2' ); |
| 722 | $this->assertSame( 'Foo', $t2_term->name ); |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * @ticket 30780 |
| 727 | */ |
| 728 | public function test_wp_update_term_should_allow_duplicate_names_at_different_levels_of_the_same_taxonomy() { |
| 729 | register_taxonomy( 'wptests_tax', 'post', array( |
| 730 | 'hierarchical' => true, |
| 731 | ) ); |
| 732 | |
| 733 | $t1 = $this->factory->term->create( array( |
| 734 | 'name' => 'Foo', |
| 735 | 'slug' => 'foo', |
| 736 | 'taxonomy' => 'wptests_tax', |
| 737 | ) ); |
| 738 | |
| 739 | $t2 = $this->factory->term->create( array( |
| 740 | 'name' => 'Bar', |
| 741 | 'slug' => 'bar', |
| 742 | 'taxonomy' => 'wptests_tax', |
| 743 | 'parent' => $t1, |
| 744 | ) ); |
| 745 | |
| 746 | $t3 = $this->factory->term->create( array( |
| 747 | 'name' => 'Bar Child', |
| 748 | 'slug' => 'bar-child', |
| 749 | 'taxonomy' => 'wptests_tax', |
| 750 | 'parent' => $t2, |
| 751 | ) ); |
| 752 | |
| 753 | $updated = wp_update_term( $t3, 'wptests_tax', array( |
| 754 | 'name' => 'Bar', |
| 755 | ) ); |
| 756 | |
| 757 | $this->assertFalse( is_wp_error( $updated ) ); |
| 758 | |
| 759 | $t3_term = get_term( $t3, 'wptests_tax' ); |
| 760 | $this->assertSame( 'Bar', $t3_term->name ); |
| 1678 | public function test_wp_update_term_should_assign_new_slug_when_reassigning_parent_as_long_as_there_is_no_other_term_with_the_same_slug() { |
| 1679 | register_taxonomy( 'wptests_tax', 'post', array( |
| 1680 | 'hierarchical' => true, |
| 1681 | ) ); |
| 1682 | register_taxonomy( 'wptests_tax_2', 'post', array( |
| 1683 | 'hierarchical' => true, |
| 1684 | ) ); |
| 1685 | |
| 1686 | $t1 = $this->factory->term->create( array( |
| 1687 | 'taxonomy' => 'wptests_tax', |
| 1688 | 'slug' => 'parent-term', |
| 1689 | ) ); |
| 1690 | |
| 1691 | $t2 = $this->factory->term->create( array( |
| 1692 | 'taxonomy' => 'wptests_tax', |
| 1693 | 'slug' => 'foo', |
| 1694 | ) ); |
| 1695 | |
| 1696 | wp_update_term( $t2, 'wptests_tax', array( |
| 1697 | 'parent' => $t1, |
| 1698 | ) ); |
| 1699 | |
| 1700 | $t2_term = get_term( $t2, 'wptests_tax' ); |
| 1701 | |
| 1702 | $this->assertSame( 'foo', $t2_term->slug ); |
| 1703 | |
| 1704 | _unregister_taxonomy( 'wptests_tax' ); |
| 1705 | } |
| 1706 | |
| 1707 | public function test_wp_update_term_should_not_assign_new_slug_when_reassigning_parent_as_long_as_there_is_no_other_slug_conflict_within_the_taxonomy() { |
| 1708 | register_taxonomy( 'wptests_tax', 'post', array( |
| 1709 | 'hierarchical' => true, |
| 1710 | ) ); |
| 1711 | register_taxonomy( 'wptests_tax_2', 'post', array( |
| 1712 | 'hierarchical' => true, |
| 1713 | ) ); |
| 1714 | |
| 1715 | $t1 = $this->factory->term->create( array( |
| 1716 | 'taxonomy' => 'wptests_tax', |
| 1717 | 'slug' => 'parent-term', |
| 1718 | ) ); |
| 1719 | |
| 1720 | // Same slug but in a different tax. |
| 1721 | $t2 = $this->factory->term->create( array( |
| 1722 | 'taxonomy' => 'wptests_tax_2', |
| 1723 | 'slug' => 'foo', |
| 1724 | ) ); |
| 1725 | |
| 1726 | $t3 = $this->factory->term->create( array( |
| 1727 | 'taxonomy' => 'wptests_tax', |
| 1728 | 'slug' => 'foo', |
| 1729 | ) ); |
| 1730 | |
| 1731 | wp_update_term( $t3, 'wptests_tax', array( |
| 1732 | 'parent' => $t1, |
| 1733 | ) ); |
| 1734 | |
| 1735 | $t3_term = get_term( $t3, 'wptests_tax' ); |
| 1736 | |
| 1737 | $this->assertSame( 'foo', $t3_term->slug ); |
| 1738 | |
| 1739 | _unregister_taxonomy( 'wptests_tax' ); |
| 1740 | } |
| 1741 | |