Ticket #42597: 42597.1.diff
| File 42597.1.diff, 1.8 KB (added by , 8 years ago) |
|---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
419 419 if ( $term_id = $term->get_error_data( 'term_exists' ) ) { 420 420 $existing_term = get_term( $term_id, $this->taxonomy ); 421 421 $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 ) ); 423 423 } 424 424 425 425 return $term; -
tests/phpunit/tests/rest-api/rest-categories-controller.php
696 696 */ 697 697 public function test_create_item_term_already_exists() { 698 698 wp_set_current_user( self::$administrator ); 699 $existing_id = $this->factory->category->create( array( 'name' => 'Existing' ) ); 700 699 701 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); 700 $request->set_param( 'name', 'test' ); 702 $request->set_param( 'name', 'Existing' ); 703 701 704 $response = $this->server->dispatch( $request ); 702 $this->assertEquals( 201, $response->get_status() );703 $response = $this->server->dispatch( $request );704 705 $this->assertEquals( 409, $response->get_status() ); 705 706 $data = $response->get_data(); 706 707 $this->assertEquals( 'term_exists', $data['code'] ); 708 $this->assertEquals( $existing_id, (int) $data['data']['term_id'] ); 709 710 wp_delete_term( $existing_id, 'category' ); 707 711 } 708 712 709 713 public function test_create_item_invalid_taxonomy() {