WordPress.org

Make WordPress Core

Ticket #41370: 41370.2.patch

File 41370.2.patch, 1.8 KB (added by shooper, 4 years ago)

Returns HTTP 409. Includes Unit Tests.

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

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    405405                        if ( $term_id = $term->get_error_data( 'term_exists' ) ) {
    406406                                $existing_term = get_term( $term_id, $this->taxonomy );
    407407                                $term->add_data( $existing_term->term_id, 'term_exists' );
     408                                $term->add_data( array( 'status' => 409 ) );
    408409                        }
    409410
    410411                        return $term;
  • tests/phpunit/tests/rest-api/rest-categories-controller.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    602602                $this->assertEquals( 'so-awesome', $data['slug'] );
    603603        }
    604604
     605        /**
     606         * @ticket 41370
     607         */
     608        public function test_create_item_term_already_exists() {
     609                wp_set_current_user( self::$administrator );
     610                $request = new WP_REST_Request( 'POST', '/wp/v2/categories' );
     611                $request->set_param( 'name', 'test' );
     612                $response = $this->server->dispatch( $request );
     613                $this->assertEquals( 201, $response->get_status() );
     614                $response = $this->server->dispatch( $request );
     615                $this->assertEquals( 409, $response->get_status() );
     616                $data = $response->get_data();
     617                $this->assertEquals( 'term_exists', $data['code'] );
     618        }
     619
    605620        public function test_create_item_invalid_taxonomy() {
    606621                wp_set_current_user( self::$administrator );
    607622                $request = new WP_REST_Request( 'POST', '/wp/v2/invalid-taxonomy' );