WordPress.org

Make WordPress Core

Ticket #42597: 42597.1.diff

File 42597.1.diff, 1.8 KB (added by rachelbaker, 4 years ago)

Updated patch to reduce overhead in the test_create_item_term_already_exists method

  • src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

     
    419419                        if ( $term_id = $term->get_error_data( 'term_exists' ) ) {
    420420                                $existing_term = get_term( $term_id, $this->taxonomy );
    421421                                $term->add_data( $existing_term->term_id, 'term_exists' );
    422                                 $term->add_data( array( 'status' => 409 ) );
     422                                $term->add_data( array( 'status' => 409, 'term_id' => $term_id ) );
    423423                        }
    424424
    425425                        return $term;
  • tests/phpunit/tests/rest-api/rest-categories-controller.php

     
    696696         */
    697697        public function test_create_item_term_already_exists() {
    698698                wp_set_current_user( self::$administrator );
     699                $existing_id = $this->factory->category->create( array( 'name' => 'Existing' ) );
     700
    699701                $request = new WP_REST_Request( 'POST', '/wp/v2/categories' );
    700                 $request->set_param( 'name', 'test' );
     702                $request->set_param( 'name', 'Existing' );
     703
    701704                $response = $this->server->dispatch( $request );
    702                 $this->assertEquals( 201, $response->get_status() );
    703                 $response = $this->server->dispatch( $request );
    704705                $this->assertEquals( 409, $response->get_status() );
    705706                $data = $response->get_data();
    706707                $this->assertEquals( 'term_exists', $data['code'] );
     708                $this->assertEquals( $existing_id, (int) $data['data']['term_id'] );
     709
     710                wp_delete_term( $existing_id, 'category' );
    707711        }
    708712
    709713        public function test_create_item_invalid_taxonomy() {