Changeset 44965
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r43987 r44965 686 686 687 687 if ( isset( $request['parent'] ) && ! empty( $schema['properties']['parent'] ) ) { 688 $parent_term_id = 0; 689 $parent_term = get_term( (int) $request['parent'], $this->taxonomy ); 690 691 if ( $parent_term ) { 692 $parent_term_id = $parent_term->term_id; 688 $parent_term_id = 0; 689 $requested_parent = (int) $request['parent']; 690 691 if ( $requested_parent ) { 692 $parent_term = get_term( $requested_parent, $this->taxonomy ); 693 694 if ( $parent_term instanceof WP_Term ) { 695 $parent_term_id = $parent_term->term_id; 696 } 693 697 } 694 698 -
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r44510 r44965 860 860 } 861 861 862 public function test_create_item_with_no_parent() { 863 wp_set_current_user( self::$administrator ); 864 $parent = 0; 865 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); 866 $request->set_param( 'name', 'My Awesome Term' ); 867 $request->set_param( 'parent', $parent ); 868 $response = rest_get_server()->dispatch( $request ); 869 $this->assertEquals( 201, $response->get_status() ); 870 $data = $response->get_data(); 871 $this->assertEquals( $parent, $data['parent'] ); 872 } 873 862 874 public function test_update_item() { 863 875 wp_set_current_user( self::$administrator ); … … 928 940 $data = $response->get_data(); 929 941 $this->assertEquals( $parent->term_id, $data['parent'] ); 942 } 943 944 public function test_update_item_remove_parent() { 945 wp_set_current_user( self::$administrator ); 946 947 $old_parent_term = get_term_by( 'id', $this->factory->category->create(), 'category' ); 948 $new_parent_id = 0; 949 950 $term = get_term_by( 951 'id', 952 $this->factory->category->create( 953 [ 954 'parent' => $old_parent_term->term_id, 955 ] 956 ), 957 'category' 958 ); 959 960 $this->assertEquals( $old_parent_term->term_id, $term->parent ); 961 962 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); 963 $request->set_param( 'parent', $new_parent_id ); 964 $response = rest_get_server()->dispatch( $request ); 965 $this->assertEquals( 200, $response->get_status() ); 966 967 $data = $response->get_data(); 968 $this->assertEquals( $new_parent_id, $data['parent'] ); 930 969 } 931 970
Note: See TracChangeset
for help on using the changeset viewer.