- Timestamp:
- 12/22/2014 03:32:59 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r30982 r30985 3354 3354 3355 3355 // Check for duplicate slug 3356 $ id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ));3357 if ( $ id && ($id != $term_id)) {3356 $duplicate = get_term_by( 'slug', $slug, $taxonomy ); 3357 if ( $duplicate && $duplicate->term_id != $term_id ) { 3358 3358 // If an empty slug was passed or the parent changed, reset the slug to something unique. 3359 3359 // Otherwise, bail. -
trunk/tests/phpunit/tests/term.php
r30585 r30985 641 641 * @ticket 5809 642 642 */ 643 public function test_wp_update_term_ duplicate_slug_same_taxonomy() {643 public function test_wp_update_term_should_not_create_duplicate_slugs_within_the_same_taxonomy() { 644 644 register_taxonomy( 'wptests_tax', 'post' ); 645 645 … … 651 651 652 652 $t2 = $this->factory->term->create( array( 653 'name' => ' Foo',653 'name' => 'Bar', 654 654 'slug' => 'bar', 655 655 'taxonomy' => 'wptests_tax', … … 667 667 * @ticket 5809 668 668 */ 669 public function test_wp_update_term_ duplicate_slug_different_taxonomy() {669 public function test_wp_update_term_should_allow_duplicate_slugs_in_different_taxonomy() { 670 670 register_taxonomy( 'wptests_tax', 'post' ); 671 671 register_taxonomy( 'wptests_tax_2', 'post' ); … … 687 687 ) ); 688 688 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 ); 691 761 } 692 762 … … 1606 1676 } 1607 1677 1678 /** 1679 * @ticket 30780 1680 */ 1681 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() { 1682 register_taxonomy( 'wptests_tax', 'post', array( 1683 'hierarchical' => true, 1684 ) ); 1685 register_taxonomy( 'wptests_tax_2', 'post', array( 1686 'hierarchical' => true, 1687 ) ); 1688 1689 $t1 = $this->factory->term->create( array( 1690 'taxonomy' => 'wptests_tax', 1691 'slug' => 'parent-term', 1692 ) ); 1693 1694 $t2 = $this->factory->term->create( array( 1695 'taxonomy' => 'wptests_tax', 1696 'slug' => 'foo', 1697 ) ); 1698 1699 wp_update_term( $t2, 'wptests_tax', array( 1700 'parent' => $t1, 1701 ) ); 1702 1703 $t2_term = get_term( $t2, 'wptests_tax' ); 1704 1705 $this->assertSame( 'foo', $t2_term->slug ); 1706 1707 _unregister_taxonomy( 'wptests_tax' ); 1708 } 1709 1710 /** 1711 * @ticket 30780 1712 */ 1713 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() { 1714 register_taxonomy( 'wptests_tax', 'post', array( 1715 'hierarchical' => true, 1716 ) ); 1717 register_taxonomy( 'wptests_tax_2', 'post', array( 1718 'hierarchical' => true, 1719 ) ); 1720 1721 $t1 = $this->factory->term->create( array( 1722 'taxonomy' => 'wptests_tax', 1723 'slug' => 'parent-term', 1724 ) ); 1725 1726 // Same slug but in a different tax. 1727 $t2 = $this->factory->term->create( array( 1728 'taxonomy' => 'wptests_tax_2', 1729 'slug' => 'foo', 1730 ) ); 1731 1732 $t3 = $this->factory->term->create( array( 1733 'taxonomy' => 'wptests_tax', 1734 'slug' => 'foo', 1735 ) ); 1736 1737 wp_update_term( $t3, 'wptests_tax', array( 1738 'parent' => $t1, 1739 ) ); 1740 1741 $t3_term = get_term( $t3, 'wptests_tax' ); 1742 1743 $this->assertSame( 'foo', $t3_term->slug ); 1744 1745 _unregister_taxonomy( 'wptests_tax' ); 1746 } 1747 1608 1748 /** Helpers **********************************************************/ 1609 1749
Note: See TracChangeset
for help on using the changeset viewer.