Make WordPress Core

Ticket #29614: 29614.2.diff

File 29614.2.diff, 1.9 KB (added by jesin, 9 years ago)

Includes 29614.diff and adds more assertions

  • tests/phpunit/tests/term.php

     
    702702                $cat_id2 = $this->factory->category->create( array( 'parent' => $cat_id1 ) );
    703703                $this->assertWPError( $cat_id2 );
    704704        }
     705
     706        /**
     707         * @ticket 29614
     708         */
     709        function test_orphan_category_update() {
     710                $parent_cat_id1 = $this->factory->category->create();
     711                $parent_cat_id2 = $this->factory->category->create();
     712
     713                $child_cat_id = $this->factory->category->create( array( 'parent' => $parent_cat_id1 ) );
     714
     715                wp_update_term( $child_cat_id, 'category', array( 'parent' => $parent_cat_id2 ) );
     716
     717                //Test if the parent term has changed
     718                $child_cat_term = get_term( $child_cat_id, 'category' );
     719                $this->assertEquals( $child_cat_term->parent, $parent_cat_id2 );
     720
     721                wp_delete_category( $parent_cat_id2 );
     722                clean_term_cache( $child_cat_id, 'category' );
     723
     724                //Test if the parent is set to 0
     725                $child_cat_term = get_term( $child_cat_id, 'category' );
     726                $this->assertEquals( $child_cat_term->parent, 0 );
     727
     728                //Test for WP_Error when updating to a deleted parent
     729                $cat_id2 = wp_update_term( $child_cat_id, 'category', array( 'parent' => $parent_cat_id2 ) );
     730                $this->assertWPError( $cat_id2 );
     731               
     732        }
    705733}
  • src/wp-includes/taxonomy.php

     
    29472947        if ( '' == trim($name) )
    29482948                return new WP_Error('empty_term_name', __('A name is required for this term'));
    29492949
     2950        if ( $parsed_args['parent'] > 0 && ! term_exists( (int) $parsed_args['parent'] ) ) {
     2951                return new WP_Error( 'missing_parent', __( 'Parent term does not exist.' ) );
     2952        }
     2953
    29502954        $empty_slug = false;
    29512955        if ( empty( $args['slug'] ) ) {
    29522956                $empty_slug = true;