Make WordPress Core

Ticket #42600: 42600.diff

File 42600.diff, 1.8 KB (added by shooper, 7 years ago)

Patch that adds term_id to the response's data array.

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

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

     
    620620
    621621        /**
    622622         * @ticket 41370
     623         * @ticket 42600
    623624         */
    624625        public function test_create_item_term_already_exists() {
    625626                wp_set_current_user( self::$administrator );
     
    627628                $request->set_param( 'name', 'test' );
    628629                $response = $this->server->dispatch( $request );
    629630                $this->assertEquals( 201, $response->get_status() );
     631
     632                $data = $response->get_data();
     633                $term_id = $data['id'];
     634                $this->assertTrue( (int) $term_id > 0 );
     635
    630636                $response = $this->server->dispatch( $request );
    631637                $this->assertEquals( 409, $response->get_status() );
    632638                $data = $response->get_data();
    633639                $this->assertEquals( 'term_exists', $data['code'] );
     640
     641                $data = $response->get_data();
     642                $this->assertEquals( (int) $data['data']['term_id'], $term_id );
     643
    634644        }
    635645
    636646        public function test_create_item_invalid_taxonomy() {