| 1608 | 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() { |
| 1609 | register_taxonomy( 'wptests_tax', 'post', array( |
| 1610 | 'hierarchical' => true, |
| 1611 | ) ); |
| 1612 | register_taxonomy( 'wptests_tax_2', 'post', array( |
| 1613 | 'hierarchical' => true, |
| 1614 | ) ); |
| 1615 | |
| 1616 | $t1 = $this->factory->term->create( array( |
| 1617 | 'taxonomy' => 'wptests_tax', |
| 1618 | 'slug' => 'parent-term', |
| 1619 | ) ); |
| 1620 | |
| 1621 | $t2 = $this->factory->term->create( array( |
| 1622 | 'taxonomy' => 'wptests_tax', |
| 1623 | 'slug' => 'foo', |
| 1624 | ) ); |
| 1625 | |
| 1626 | wp_update_term( $t2, 'wptests_tax', array( |
| 1627 | 'parent' => $t1, |
| 1628 | ) ); |
| 1629 | |
| 1630 | $t2_term = get_term( $t2, 'wptests_tax' ); |
| 1631 | |
| 1632 | $this->assertSame( 'foo', $t2_term->slug ); |
| 1633 | |
| 1634 | _unregister_taxonomy( 'wptests_tax' ); |
| 1635 | } |
| 1636 | |
| 1637 | 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() { |
| 1638 | register_taxonomy( 'wptests_tax', 'post', array( |
| 1639 | 'hierarchical' => true, |
| 1640 | ) ); |
| 1641 | register_taxonomy( 'wptests_tax_2', 'post', array( |
| 1642 | 'hierarchical' => true, |
| 1643 | ) ); |
| 1644 | |
| 1645 | $t1 = $this->factory->term->create( array( |
| 1646 | 'taxonomy' => 'wptests_tax', |
| 1647 | 'slug' => 'parent-term', |
| 1648 | ) ); |
| 1649 | |
| 1650 | // Same slug but in a different tax. |
| 1651 | $t2 = $this->factory->term->create( array( |
| 1652 | 'taxonomy' => 'wptests_tax_2', |
| 1653 | 'slug' => 'foo', |
| 1654 | ) ); |
| 1655 | |
| 1656 | $t3 = $this->factory->term->create( array( |
| 1657 | 'taxonomy' => 'wptests_tax', |
| 1658 | 'slug' => 'foo', |
| 1659 | ) ); |
| 1660 | |
| 1661 | wp_update_term( $t3, 'wptests_tax', array( |
| 1662 | 'parent' => $t1, |
| 1663 | ) ); |
| 1664 | |
| 1665 | $t3_term = get_term( $t3, 'wptests_tax' ); |
| 1666 | |
| 1667 | $this->assertSame( 'foo', $t3_term->slug ); |
| 1668 | |
| 1669 | _unregister_taxonomy( 'wptests_tax' ); |
| 1670 | } |
| 1671 | |