Ticket #39122: 39122.diff
File 39122.diff, 7.6 KB (added by , 6 years ago) |
---|
-
tests/phpunit/tests/rest-api/rest-categories-controller.php
diff --git tests/phpunit/tests/rest-api/rest-categories-controller.php tests/phpunit/tests/rest-api/rest-categories-controller.php index ac8d02a0ea..15f4606b61 100644
class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas 38 38 self::delete_user( self::$subscriber ); 39 39 } 40 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 )); 69 } 70 41 71 public function test_register_routes() { 42 72 $routes = rest_get_server()->get_routes(); 43 73 $this->assertArrayHasKey( '/wp/v2/categories', $routes ); … … class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas 634 664 $this->check_get_taxonomy_term_response( $response ); 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' ); 639 697 $response = rest_get_server()->dispatch( $request ); … … class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas 782 840 $request->set_param( 'name', 'New Name' ); 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() ); 787 850 $data = $response->get_data(); 788 851 $this->assertEquals( 'New Name', $data['name'] ); 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 793 859 public function test_update_item_invalid_taxonomy() { -
tests/phpunit/tests/rest-api/rest-tags-controller.php
diff --git tests/phpunit/tests/rest-api/rest-tags-controller.php tests/phpunit/tests/rest-api/rest-tags-controller.php index 2b3cd11250..2ec2e6c82d 100644
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 55 55 self::delete_user( self::$subscriber ); 56 56 } 57 57 58 public function setUp() { 59 parent::setUp(); 60 61 register_meta( 'term', 'test_single', array( 62 'show_in_rest' => true, 63 'single' => true, 64 'type' => 'string', 65 )); 66 register_meta( 'term', 'test_multi', array( 67 'show_in_rest' => true, 68 'single' => false, 69 'type' => 'string', 70 )); 71 register_term_meta( 'post_tag', 'test_tag_single', array( 72 'show_in_rest' => true, 73 'single' => true, 74 'type' => 'string', 75 )); 76 register_term_meta( 'post_tag', 'test_tag_multi', array( 77 'show_in_rest' => true, 78 'single' => false, 79 'type' => 'string', 80 )); 81 register_term_meta( 'category', 'test_cat_meta', array( 82 'show_in_rest' => true, 83 'single' => true, 84 'type' => 'string', 85 )); 86 } 87 58 88 public function test_register_routes() { 59 89 $routes = rest_get_server()->get_routes(); 60 90 $this->assertArrayHasKey( '/wp/v2/tags', $routes ); … … class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 572 602 $this->check_get_taxonomy_term_response( $response, $id ); 573 603 } 574 604 605 public function test_get_item_meta() { 606 $id = $this->factory->tag->create(); 607 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 608 $response = rest_get_server()->dispatch( $request ); 609 $data = $response->get_data(); 610 $this->assertArrayHasKey( 'meta', $data ); 611 612 $meta = (array) $data['meta']; 613 $this->assertArrayHasKey( 'test_single', $meta ); 614 $this->assertEquals( $meta['test_single'], '' ); 615 $this->assertArrayHasKey( 'test_multi', $meta ); 616 $this->assertEquals( $meta['test_multi'], array() ); 617 $this->assertArrayHasKey( 'test_tag_single', $meta ); 618 $this->assertEquals( $meta['test_tag_single'], '' ); 619 $this->assertArrayHasKey( 'test_tag_multi', $meta ); 620 $this->assertEquals( $meta['test_tag_multi'], array() ); 621 } 622 623 public function test_get_item_meta_registered_for_different_taxonomy() { 624 $id = $this->factory->tag->create(); 625 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 626 $response = rest_get_server()->dispatch( $request ); 627 $data = $response->get_data(); 628 $this->assertArrayHasKey( 'meta', $data ); 629 630 $meta = (array) $data['meta']; 631 $this->assertEquals( false, isset( $meta['test_cat_meta'] ) ); 632 } 633 575 634 public function test_get_term_invalid_term() { 576 635 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 577 636 $response = rest_get_server()->dispatch( $request ); … … class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 683 742 $request->set_param( 'name', 'New Name' ); 684 743 $request->set_param( 'description', 'New Description' ); 685 744 $request->set_param( 'slug', 'new-slug' ); 745 $request->set_param( 'meta', array( 746 'test_single' => 'just meta', 747 'test_tag_single' => 'tag-specific meta', 748 'test_cat_meta' => 'category-specific meta', 749 ) ); 686 750 $response = rest_get_server()->dispatch( $request ); 687 751 $this->assertEquals( 200, $response->get_status() ); 688 752 $data = $response->get_data(); 689 753 $this->assertEquals( 'New Name', $data['name'] ); 690 754 $this->assertEquals( 'New Description', $data['description'] ); 691 755 $this->assertEquals( 'new-slug', $data['slug'] ); 756 $this->assertEquals( 'just meta', $data['meta']['test_single'] ); 757 $this->assertEquals( 'tag-specific meta', $data['meta']['test_tag_single'] ); 758 $this->assertFalse( isset( $data['meta']['test_cat_meta'] ) ); 692 759 } 693 760 694 761 public function test_update_item_no_change() {