diff --git tests/phpunit/tests/rest-api/rest-categories-controller.php tests/phpunit/tests/rest-api/rest-categories-controller.php
index 15f4606..6353ca4 100644
|
|
|
class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas |
| 41 | 41 | public function setUp() { |
| 42 | 42 | parent::setUp(); |
| 43 | 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 | | )); |
| | 44 | register_meta( |
| | 45 | 'term', 'test_single', array( |
| | 46 | 'show_in_rest' => true, |
| | 47 | 'single' => true, |
| | 48 | 'type' => 'string', |
| | 49 | ) |
| | 50 | ); |
| | 51 | register_meta( |
| | 52 | 'term', 'test_multi', array( |
| | 53 | 'show_in_rest' => true, |
| | 54 | 'single' => false, |
| | 55 | 'type' => 'string', |
| | 56 | ) |
| | 57 | ); |
| | 58 | register_term_meta( |
| | 59 | 'category', 'test_cat_single', array( |
| | 60 | 'show_in_rest' => true, |
| | 61 | 'single' => true, |
| | 62 | 'type' => 'string', |
| | 63 | ) |
| | 64 | ); |
| | 65 | register_term_meta( |
| | 66 | 'category', 'test_cat_multi', array( |
| | 67 | 'show_in_rest' => true, |
| | 68 | 'single' => false, |
| | 69 | 'type' => 'string', |
| | 70 | ) |
| | 71 | ); |
| | 72 | register_term_meta( |
| | 73 | 'post_tag', 'test_tag_meta', array( |
| | 74 | 'show_in_rest' => true, |
| | 75 | 'single' => true, |
| | 76 | 'type' => 'string', |
| | 77 | ) |
| | 78 | ); |
| 69 | 79 | } |
| 70 | 80 | |
| 71 | 81 | public function test_register_routes() { |
| … |
… |
class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas |
| 664 | 674 | $this->check_get_taxonomy_term_response( $response ); |
| 665 | 675 | } |
| 666 | 676 | |
| | 677 | /** |
| | 678 | * @ticket 39122 |
| | 679 | */ |
| 667 | 680 | public function test_get_item_meta() { |
| 668 | 681 | $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); |
| 669 | 682 | $response = rest_get_server()->dispatch( $request ); |
| … |
… |
class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas |
| 672 | 685 | |
| 673 | 686 | $meta = (array) $data['meta']; |
| 674 | 687 | $this->assertArrayHasKey( 'test_single', $meta ); |
| 675 | | $this->assertEquals( $meta['test_single'], '' ); |
| | 688 | $this->assertSame( $meta['test_single'], '' ); |
| 676 | 689 | $this->assertArrayHasKey( 'test_multi', $meta ); |
| 677 | | $this->assertEquals( $meta['test_multi'], array() ); |
| | 690 | $this->assertSame( $meta['test_multi'], array() ); |
| 678 | 691 | $this->assertArrayHasKey( 'test_cat_single', $meta ); |
| 679 | | $this->assertEquals( $meta['test_cat_single'], '' ); |
| | 692 | $this->assertSame( $meta['test_cat_single'], '' ); |
| 680 | 693 | $this->assertArrayHasKey( 'test_cat_multi', $meta ); |
| 681 | | $this->assertEquals( $meta['test_cat_multi'], array() ); |
| | 694 | $this->assertSame( $meta['test_cat_multi'], array() ); |
| 682 | 695 | } |
| 683 | 696 | |
| | 697 | /** |
| | 698 | * @ticket 39122 |
| | 699 | */ |
| 684 | 700 | public function test_get_item_meta_registered_for_different_taxonomy() { |
| 685 | 701 | $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); |
| 686 | 702 | $response = rest_get_server()->dispatch( $request ); |
| 687 | | $data = $response->get_data(); |
| 688 | | $this->assertArrayHasKey( 'meta', $data ); |
| | 703 | $data = $response->get_data(); |
| 689 | 704 | $this->assertArrayHasKey( 'meta', $data ); |
| 690 | 705 | |
| 691 | 706 | $meta = (array) $data['meta']; |
| 692 | | $this->assertEquals( false, isset( $meta['test_tag_meta'] ) ); |
| | 707 | $this->assertFalse( isset( $meta['test_tag_meta'] ) ); |
| 693 | 708 | } |
| 694 | 709 | |
| 695 | 710 | public function test_get_term_invalid_taxonomy() { |
| … |
… |
class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas |
| 840 | 855 | $request->set_param( 'name', 'New Name' ); |
| 841 | 856 | $request->set_param( 'description', 'New Description' ); |
| 842 | 857 | $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 | | ) ); |
| | 858 | $request->set_param( |
| | 859 | 'meta', array( |
| | 860 | 'test_single' => 'just meta', |
| | 861 | 'test_cat_single' => 'category-specific meta', |
| | 862 | 'test_tag_meta' => 'tag-specific meta', |
| | 863 | ) |
| | 864 | ); |
| 848 | 865 | $response = rest_get_server()->dispatch( $request ); |
| 849 | 866 | $this->assertEquals( 200, $response->get_status() ); |
| 850 | 867 | $data = $response->get_data(); |
| … |
… |
class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas |
| 968 | 985 | $request->set_param( '_fields', 'id,name' ); |
| 969 | 986 | $term = get_term( 1, 'category' ); |
| 970 | 987 | $response = $endpoint->prepare_item_for_response( $term, $request ); |
| 971 | | $this->assertEquals( array( |
| 972 | | 'id', |
| 973 | | 'name', |
| 974 | | ), array_keys( $response->get_data() ) ); |
| | 988 | $this->assertEquals( array( 'id', 'name' ), array_keys( $response->get_data() ) ); |
| 975 | 989 | } |
| 976 | 990 | |
| 977 | 991 | public function test_prepare_taxonomy_term_child() { |
diff --git tests/phpunit/tests/rest-api/rest-tags-controller.php tests/phpunit/tests/rest-api/rest-tags-controller.php
index 2ec2e6c..766f531 100644
|
|
|
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { |
| 58 | 58 | public function setUp() { |
| 59 | 59 | parent::setUp(); |
| 60 | 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 | | )); |
| | 61 | register_meta( |
| | 62 | 'term', 'test_single', array( |
| | 63 | 'show_in_rest' => true, |
| | 64 | 'single' => true, |
| | 65 | 'type' => 'string', |
| | 66 | ) |
| | 67 | ); |
| | 68 | register_meta( |
| | 69 | 'term', 'test_multi', array( |
| | 70 | 'show_in_rest' => true, |
| | 71 | 'single' => false, |
| | 72 | 'type' => 'string', |
| | 73 | ) |
| | 74 | ); |
| | 75 | register_term_meta( |
| | 76 | 'post_tag', 'test_tag_single', array( |
| | 77 | 'show_in_rest' => true, |
| | 78 | 'single' => true, |
| | 79 | 'type' => 'string', |
| | 80 | ) |
| | 81 | ); |
| | 82 | register_term_meta( |
| | 83 | 'post_tag', 'test_tag_multi', array( |
| | 84 | 'show_in_rest' => true, |
| | 85 | 'single' => false, |
| | 86 | 'type' => 'string', |
| | 87 | ) |
| | 88 | ); |
| | 89 | register_term_meta( |
| | 90 | 'category', 'test_cat_meta', array( |
| | 91 | 'show_in_rest' => true, |
| | 92 | 'single' => true, |
| | 93 | 'type' => 'string', |
| | 94 | ) |
| | 95 | ); |
| 86 | 96 | } |
| 87 | 97 | |
| 88 | 98 | public function test_register_routes() { |
| … |
… |
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { |
| 602 | 612 | $this->check_get_taxonomy_term_response( $response, $id ); |
| 603 | 613 | } |
| 604 | 614 | |
| | 615 | /** |
| | 616 | * @ticket 39122 |
| | 617 | */ |
| 605 | 618 | public function test_get_item_meta() { |
| 606 | 619 | $id = $this->factory->tag->create(); |
| 607 | 620 | $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); |
| 608 | 621 | $response = rest_get_server()->dispatch( $request ); |
| 609 | | $data = $response->get_data(); |
| | 622 | $data = $response->get_data(); |
| 610 | 623 | $this->assertArrayHasKey( 'meta', $data ); |
| 611 | 624 | |
| 612 | 625 | $meta = (array) $data['meta']; |
| 613 | 626 | $this->assertArrayHasKey( 'test_single', $meta ); |
| 614 | | $this->assertEquals( $meta['test_single'], '' ); |
| | 627 | $this->assertSame( $meta['test_single'], '' ); |
| 615 | 628 | $this->assertArrayHasKey( 'test_multi', $meta ); |
| 616 | | $this->assertEquals( $meta['test_multi'], array() ); |
| | 629 | $this->assertSame( $meta['test_multi'], array() ); |
| 617 | 630 | $this->assertArrayHasKey( 'test_tag_single', $meta ); |
| 618 | | $this->assertEquals( $meta['test_tag_single'], '' ); |
| | 631 | $this->assertSame( $meta['test_tag_single'], '' ); |
| 619 | 632 | $this->assertArrayHasKey( 'test_tag_multi', $meta ); |
| 620 | | $this->assertEquals( $meta['test_tag_multi'], array() ); |
| | 633 | $this->assertSame( $meta['test_tag_multi'], array() ); |
| 621 | 634 | } |
| 622 | 635 | |
| | 636 | /** |
| | 637 | * @ticket 39122 |
| | 638 | */ |
| 623 | 639 | public function test_get_item_meta_registered_for_different_taxonomy() { |
| 624 | 640 | $id = $this->factory->tag->create(); |
| 625 | 641 | $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); |
| 626 | 642 | $response = rest_get_server()->dispatch( $request ); |
| 627 | | $data = $response->get_data(); |
| | 643 | $data = $response->get_data(); |
| 628 | 644 | $this->assertArrayHasKey( 'meta', $data ); |
| 629 | 645 | |
| 630 | 646 | $meta = (array) $data['meta']; |
| 631 | | $this->assertEquals( false, isset( $meta['test_cat_meta'] ) ); |
| | 647 | $this->assertFalse( isset( $meta['test_cat_meta'] ) ); |
| 632 | 648 | } |
| 633 | 649 | |
| 634 | 650 | public function test_get_term_invalid_term() { |
| … |
… |
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { |
| 742 | 758 | $request->set_param( 'name', 'New Name' ); |
| 743 | 759 | $request->set_param( 'description', 'New Description' ); |
| 744 | 760 | $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 | | ) ); |
| | 761 | $request->set_param( |
| | 762 | 'meta', array( |
| | 763 | 'test_single' => 'just meta', |
| | 764 | 'test_tag_single' => 'tag-specific meta', |
| | 765 | 'test_cat_meta' => 'category-specific meta', |
| | 766 | ) |
| | 767 | ); |
| 750 | 768 | $response = rest_get_server()->dispatch( $request ); |
| 751 | 769 | $this->assertEquals( 200, $response->get_status() ); |
| 752 | 770 | $data = $response->get_data(); |
| … |
… |
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { |
| 1063 | 1081 | $request->set_param( '_fields', 'id,name' ); |
| 1064 | 1082 | $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); |
| 1065 | 1083 | $response = $endpoint->prepare_item_for_response( $term, $request ); |
| 1066 | | $this->assertEquals( array( |
| 1067 | | 'id', |
| 1068 | | 'name', |
| 1069 | | ), array_keys( $response->get_data() ) ); |
| | 1084 | $this->assertEquals( array( 'id', 'name' ), array_keys( $response->get_data() ) ); |
| 1070 | 1085 | } |
| 1071 | 1086 | |
| 1072 | 1087 | public function test_get_item_schema() { |