Changeset 43714
- Timestamp:
- 10/11/2018 06:34:34 AM (6 years ago)
- Location:
- branches/5.0
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0
-
branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r43445 r43714 442 442 $schema = $this->get_item_schema(); 443 443 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { 444 $meta_update = $this->meta->update_value( $request['meta'], (int) $request['id']);444 $meta_update = $this->meta->update_value( $request['meta'], $term->term_id ); 445 445 446 446 if ( is_wp_error( $meta_update ) ) { -
branches/5.0/tests/phpunit/tests/rest-api/rest-tags-controller.php
r43713 r43714 676 676 } 677 677 678 public function test_create_item_with_meta() { 679 wp_set_current_user( self::$administrator ); 680 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 681 $request->set_param( 'name', 'My Awesome Term' ); 682 $request->set_param( 'meta', array( 'test_tag_single' => 'hello' ) ); 683 $response = rest_get_server()->dispatch( $request ); 684 $this->assertEquals( 201, $response->get_status() ); 685 $headers = $response->get_headers(); 686 $data = $response->get_data(); 687 $this->assertContains( '/wp/v2/tags/' . $data['id'], $headers['Location'] ); 688 $this->assertEquals( 'My Awesome Term', $data['name'] ); 689 $this->assertEquals( 'hello', get_term_meta( $data['id'], 'test_tag_single', true ) ); 690 } 691 692 public function test_create_item_with_meta_wrong_id() { 693 wp_set_current_user( self::$administrator ); 694 $existing_tag_id = $this->factory->tag->create( array( 'name' => 'My Not So Awesome Term' ) ); 695 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 696 $request->set_param( 'name', 'My Awesome Term' ); 697 $request->set_param( 'meta', array( 'test_tag_single' => 'hello' ) ); 698 $request->set_param( 'id', $existing_tag_id ); 699 $response = rest_get_server()->dispatch( $request ); 700 $this->assertEquals( 201, $response->get_status() ); 701 $headers = $response->get_headers(); 702 $data = $response->get_data(); 703 $this->assertContains( '/wp/v2/tags/' . $data['id'], $headers['Location'] ); 704 $this->assertEquals( 'My Awesome Term', $data['name'] ); 705 $this->assertEquals( '', get_term_meta( $existing_tag_id, 'test_tag_single', true ) ); 706 $this->assertEquals( 'hello', get_term_meta( $data['id'], 'test_tag_single', true ) ); 707 } 708 678 709 public function test_update_item() { 679 710 wp_set_current_user( self::$administrator );
Note: See TracChangeset
for help on using the changeset viewer.