| 760 | public function test_create_item_with_meta() { |
| 761 | wp_set_current_user( self::$administrator ); |
| 762 | $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); |
| 763 | $request->set_param( 'name', 'My Awesome Term' ); |
| 764 | $request->set_param( 'meta', array( 'test_tag_single' => 'hello' ) ); |
| 765 | $response = rest_get_server()->dispatch( $request ); |
| 766 | $this->assertEquals( 201, $response->get_status() ); |
| 767 | $headers = $response->get_headers(); |
| 768 | $data = $response->get_data(); |
| 769 | $this->assertContains( '/wp/v2/tags/' . $data['id'], $headers['Location'] ); |
| 770 | $this->assertEquals( 'My Awesome Term', $data['name'] ); |
| 771 | $this->assertEquals( 'hello', get_term_meta( $data['id'], 'test_tag_single', true ) ); |
| 772 | } |
| 773 | |
| 774 | public function test_create_item_with_meta_wrong_id() { |
| 775 | wp_set_current_user( self::$administrator ); |
| 776 | $existing_tag_id = $this->factory->tag->create( array( 'name' => 'My Not So Awesome Term' ) ); |
| 777 | $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); |
| 778 | $request->set_param( 'name', 'My Awesome Term' ); |
| 779 | $request->set_param( 'meta', array( 'test_tag_single' => 'hello' ) ); |
| 780 | $request->set_param( 'id', $existing_tag_id ); |
| 781 | $response = rest_get_server()->dispatch( $request ); |
| 782 | $this->assertEquals( 201, $response->get_status() ); |
| 783 | $headers = $response->get_headers(); |
| 784 | $data = $response->get_data(); |
| 785 | $this->assertContains( '/wp/v2/tags/' . $data['id'], $headers['Location'] ); |
| 786 | $this->assertEquals( 'My Awesome Term', $data['name'] ); |
| 787 | $this->assertEquals( '', get_term_meta( $existing_tag_id, 'test_tag_single', true ) ); |
| 788 | $this->assertEquals( 'hello', get_term_meta( $data['id'], 'test_tag_single', true ) ); |
| 789 | } |
| 790 | |