Make WordPress Core


Ignore:
Timestamp:
11/05/2014 01:41:58 AM (12 years ago)
Author:
boonebgorges
Message:

Do not create shared taxonomy terms.

A "shared" term occurs when two entries in the wp_term_taxonomy table share a
single term_id, and thereby correspond to the same row in wp_terms. This
changeset stops the practice of creating shared terms: each new row in
wp_term_taxonomy will receive its own row in wp_terms. The new strategy
for term creation depends on whether the installation's database schema is up
to date for 4.1:

  • If so, terms are allowed to be created with the same slug as an existing term, as long as they are in different taxonomies and do not share a parent. Thus, a new tag with the slug 'wordpress' can exist alongside a category with the slug 'wordpress'.
  • If not, new terms will be forced to have unique slugs. Thus, on an installation containing a category with the slug 'wordpress', a new tag 'WordPress' will get the slug 'wordpress-2'.

Fixes #21950. See #5809.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term.php

    r30118 r30240  
    227227        }
    228228
     229        /**
     230         * @ticket 5809
     231         */
     232        public function test_wp_insert_term_duplicate_slug_same_taxonomy() {
     233                register_taxonomy( 'wptests_tax', 'post' );
     234                $t = $this->factory->term->create( array(
     235                        'name' => 'Foo',
     236                        'slug' => 'foo',
     237                        'taxonomy' => 'wptests_tax',
     238                ) );
     239
     240                $term = get_term( $t, 'wptests_tax' );
     241
     242                $created = wp_insert_term( 'Foo 2', 'wptests_tax', array(
     243                        'slug' => 'foo',
     244                ) );
     245
     246                $created_term = get_term( $created['term_id'], 'wptests_tax' );
     247                $this->assertSame( 'foo-2', $created_term->slug );
     248
     249                _unregister_taxonomy( 'wptests_tax', 'post' );
     250        }
     251
     252        /**
     253         * @ticket 5809
     254         */
     255        public function test_wp_insert_term_duplicate_slug_different_taxonomy() {
     256                register_taxonomy( 'wptests_tax', 'post' );
     257                register_taxonomy( 'wptests_tax_2', 'post' );
     258                $t = $this->factory->term->create( array(
     259                        'name' => 'Foo',
     260                        'slug' => 'foo',
     261                        'taxonomy' => 'wptests_tax',
     262                ) );
     263
     264                $term = get_term( $t, 'wptests_tax' );
     265
     266                $created = wp_insert_term( 'Foo 2', 'wptests_tax_2', array(
     267                        'slug' => 'foo',
     268                ) );
     269
     270                $this->assertFalse( is_wp_error( $created ) );
     271
     272                $new_term = get_term( $created['term_id'], 'wptests_tax_2' );
     273
     274                $this->assertSame( 'foo', $new_term->slug );
     275
     276                _unregister_taxonomy( 'wptests_tax', 'post' );
     277        }
     278
     279        /**
     280         * @ticket 5809
     281         */
     282        public function test_wp_insert_term_duplicate_slug_different_taxonomy_before_410_schema_change() {
     283
     284                $db_version = get_option( 'db_version' );
     285                update_option( 'db_version', 30055 );
     286
     287                register_taxonomy( 'wptests_tax', 'post' );
     288                register_taxonomy( 'wptests_tax_2', 'post' );
     289                $t = $this->factory->term->create( array(
     290                        'name' => 'Foo',
     291                        'slug' => 'foo',
     292                        'taxonomy' => 'wptests_tax',
     293                ) );
     294
     295                $term = get_term( $t, 'wptests_tax' );
     296
     297                $created = wp_insert_term( 'Foo 2', 'wptests_tax_2', array(
     298                        'slug' => 'foo',
     299                ) );
     300
     301                $this->assertFalse( is_wp_error( $created ) );
     302
     303                $new_term = get_term( $created['term_id'], 'wptests_tax_2' );
     304
     305                /*
     306                 * As of 4.1, we no longer create a shared term, but we also do not
     307                 * allow for duplicate slugs.
     308                 */
     309                $this->assertSame( 'foo-2', $new_term->slug );
     310                $this->assertNotEquals( $new_term->term_id, $term->term_id );
     311
     312                _unregister_taxonomy( 'wptests_tax', 'post' );
     313                update_option( 'db_version', $db_version );
     314        }
     315
    229316        public function test_wp_insert_term_alias_of_no_term_group() {
    230317                register_taxonomy( 'wptests_tax', 'post' );
     
    352439                $this->assertTrue( is_wp_error( $found ) );
    353440                $this->assertEquals( $existing_term, $found->get_error_data() );
     441        }
     442
     443        /**
     444         * @ticket 5809
     445         */
     446        public function test_wp_insert_term_should_not_create_shared_term() {
     447                register_taxonomy( 'wptests_tax', 'post' );
     448                register_taxonomy( 'wptests_tax_2', 'post' );
     449
     450                $t1 = wp_insert_term( 'Foo', 'wptests_tax' );
     451                $t2 = wp_insert_term( 'Foo', 'wptests_tax_2' );
     452
     453                $this->assertNotEquals( $t1['term_id'], $t2['term_id'] );
    354454        }
    355455
Note: See TracChangeset for help on using the changeset viewer.