Make WordPress Core

Ticket #29614: 29614.diff

File 29614.diff, 1.3 KB (added by jesin, 9 years ago)

Patch and unit test

  • 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;
  • 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                $cat_id1 = $this->factory->category->create();
     711                $cat_id2 = $this->factory->category->create( array( 'parent' => $cat_id1 ) );
     712
     713                wp_delete_category( $cat_id1 );
     714
     715                $cat_id2 = wp_update_term( $cat_id2, 'category', array( 'parent' => $cat_id1 ) );
     716                $this->assertWPError( $cat_id2 );
     717               
     718        }
    705719}