- Timestamp:
- 08/12/2018 12:05:39 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r43440 r43567 37 37 self::delete_user( self::$administrator ); 38 38 self::delete_user( self::$subscriber ); 39 } 40 41 public function setUp() { 42 parent::setUp(); 43 44 register_meta( 'term', 'test_single', array( 45 'show_in_rest' => true, 46 'single' => true, 47 'type' => 'string', 48 )); 49 register_meta( 'term', 'test_multi', array( 50 'show_in_rest' => true, 51 'single' => false, 52 'type' => 'string', 53 )); 54 register_term_meta( 'category', 'test_cat_single', array( 55 'show_in_rest' => true, 56 'single' => true, 57 'type' => 'string', 58 )); 59 register_term_meta( 'category', 'test_cat_multi', array( 60 'show_in_rest' => true, 61 'single' => false, 62 'type' => 'string', 63 )); 64 register_term_meta( 'post_tag', 'test_tag_meta', array( 65 'show_in_rest' => true, 66 'single' => true, 67 'type' => 'string', 68 )); 39 69 } 40 70 … … 635 665 } 636 666 667 public function test_get_item_meta() { 668 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 669 $response = rest_get_server()->dispatch( $request ); 670 $data = $response->get_data(); 671 $this->assertArrayHasKey( 'meta', $data ); 672 673 $meta = (array) $data['meta']; 674 $this->assertArrayHasKey( 'test_single', $meta ); 675 $this->assertEquals( $meta['test_single'], '' ); 676 $this->assertArrayHasKey( 'test_multi', $meta ); 677 $this->assertEquals( $meta['test_multi'], array() ); 678 $this->assertArrayHasKey( 'test_cat_single', $meta ); 679 $this->assertEquals( $meta['test_cat_single'], '' ); 680 $this->assertArrayHasKey( 'test_cat_multi', $meta ); 681 $this->assertEquals( $meta['test_cat_multi'], array() ); 682 } 683 684 public function test_get_item_meta_registered_for_different_taxonomy() { 685 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 686 $response = rest_get_server()->dispatch( $request ); 687 $data = $response->get_data(); 688 $this->assertArrayHasKey( 'meta', $data ); 689 $this->assertArrayHasKey( 'meta', $data ); 690 691 $meta = (array) $data['meta']; 692 $this->assertEquals( false, isset( $meta['test_tag_meta'] ) ); 693 } 694 637 695 public function test_get_term_invalid_taxonomy() { 638 696 $request = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy/1' ); … … 783 841 $request->set_param( 'description', 'New Description' ); 784 842 $request->set_param( 'slug', 'new-slug' ); 843 $request->set_param( 'meta', array( 844 'test_single' => 'just meta', 845 'test_cat_single' => 'category-specific meta', 846 'test_tag_meta' => 'tag-specific meta', 847 ) ); 785 848 $response = rest_get_server()->dispatch( $request ); 786 849 $this->assertEquals( 200, $response->get_status() ); … … 789 852 $this->assertEquals( 'New Description', $data['description'] ); 790 853 $this->assertEquals( 'new-slug', $data['slug'] ); 854 $this->assertEquals( 'just meta', $data['meta']['test_single'] ); 855 $this->assertEquals( 'category-specific meta', $data['meta']['test_cat_single'] ); 856 $this->assertFalse( isset( $data['meta']['test_tag_meta'] ) ); 791 857 } 792 858
Note: See TracChangeset
for help on using the changeset viewer.