WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/09/2014 06:11:17 PM (7 years ago)
Author:
boonebgorges
Message:

Return an error when adding a term to a non-existent parent.

Parallels the logic of wp_insert_term(), introduced in [29196].

Props jesin.
Fixes #29614.

File:
1 edited

Legend:

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

    r29865 r29867  
    632632    }
    633633
     634    /**
     635     * @ticket 29614
     636     */
     637    function test_wp_update_term_parent_does_not_exist() {
     638        register_taxonomy( 'wptests_tax', array(
     639            'hierarchical' => true,
     640        ) );
     641        $fake_term_id = 787878;
     642
     643        $this->assertNull( term_exists( $fake_term_id, 'wptests_tax' ) );
     644
     645        $t = $this->factory->term->create( array(
     646            'taxonomy' => 'wptests_tax',
     647        ) );
     648
     649        $found = wp_update_term( $t, 'wptests_tax', array(
     650            'parent' => $fake_term_id,
     651        ) );
     652
     653        $this->assertWPError( $found );
     654        $this->assertSame( 'missing_parent', $found->get_error_code() );
     655
     656        $term = get_term( $t, 'wptests_tax' );
     657        $this->assertEquals( 0, $term->parent );
     658    }
     659
    634660    public function test_wp_update_term_alias_of_no_term_group() {
    635661        register_taxonomy( 'wptests_tax', 'post' );
Note: See TracChangeset for help on using the changeset viewer.