Changeset 43713
- Timestamp:
- 10/11/2018 06:31:43 AM (6 years ago)
- Location:
- branches/5.0
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0
-
branches/5.0/tests/phpunit/tests/rest-api/rest-categories-controller.php
r43445 r43713 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 … … 576 606 } 577 607 608 public function test_get_item_meta() { 609 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 610 $response = rest_get_server()->dispatch( $request ); 611 $data = $response->get_data(); 612 $this->assertArrayHasKey( 'meta', $data ); 613 614 $meta = (array) $data['meta']; 615 $this->assertArrayHasKey( 'test_single', $meta ); 616 $this->assertEquals( $meta['test_single'], '' ); 617 $this->assertArrayHasKey( 'test_multi', $meta ); 618 $this->assertEquals( $meta['test_multi'], array() ); 619 $this->assertArrayHasKey( 'test_cat_single', $meta ); 620 $this->assertEquals( $meta['test_cat_single'], '' ); 621 $this->assertArrayHasKey( 'test_cat_multi', $meta ); 622 $this->assertEquals( $meta['test_cat_multi'], array() ); 623 } 624 625 public function test_get_item_meta_registered_for_different_taxonomy() { 626 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 627 $response = rest_get_server()->dispatch( $request ); 628 $data = $response->get_data(); 629 $this->assertArrayHasKey( 'meta', $data ); 630 $this->assertArrayHasKey( 'meta', $data ); 631 632 $meta = (array) $data['meta']; 633 $this->assertEquals( false, isset( $meta['test_tag_meta'] ) ); 634 } 635 578 636 public function test_get_term_invalid_taxonomy() { 579 637 $request = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy/1' ); … … 714 772 $request->set_param( 'description', 'New Description' ); 715 773 $request->set_param( 'slug', 'new-slug' ); 716 $response = $this->server->dispatch( $request ); 774 $request->set_param( 'meta', array( 775 'test_single' => 'just meta', 776 'test_cat_single' => 'category-specific meta', 777 'test_tag_meta' => 'tag-specific meta', 778 ) ); 779 $response = rest_get_server()->dispatch( $request ); 717 780 $this->assertEquals( 200, $response->get_status() ); 718 781 $data = $response->get_data(); … … 720 783 $this->assertEquals( 'New Description', $data['description'] ); 721 784 $this->assertEquals( 'new-slug', $data['slug'] ); 785 $this->assertEquals( 'just meta', $data['meta']['test_single'] ); 786 $this->assertEquals( 'category-specific meta', $data['meta']['test_cat_single'] ); 787 $this->assertFalse( isset( $data['meta']['test_tag_meta'] ) ); 722 788 } 723 789 -
branches/5.0/tests/phpunit/tests/rest-api/rest-tags-controller.php
r43445 r43713 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 = $this->server->get_routes(); … … 528 558 } 529 559 560 public function test_get_item_meta() { 561 $id = $this->factory->tag->create(); 562 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 563 $response = rest_get_server()->dispatch( $request ); 564 $data = $response->get_data(); 565 $this->assertArrayHasKey( 'meta', $data ); 566 567 $meta = (array) $data['meta']; 568 $this->assertArrayHasKey( 'test_single', $meta ); 569 $this->assertEquals( $meta['test_single'], '' ); 570 $this->assertArrayHasKey( 'test_multi', $meta ); 571 $this->assertEquals( $meta['test_multi'], array() ); 572 $this->assertArrayHasKey( 'test_tag_single', $meta ); 573 $this->assertEquals( $meta['test_tag_single'], '' ); 574 $this->assertArrayHasKey( 'test_tag_multi', $meta ); 575 $this->assertEquals( $meta['test_tag_multi'], array() ); 576 } 577 578 public function test_get_item_meta_registered_for_different_taxonomy() { 579 $id = $this->factory->tag->create(); 580 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 581 $response = rest_get_server()->dispatch( $request ); 582 $data = $response->get_data(); 583 $this->assertArrayHasKey( 'meta', $data ); 584 585 $meta = (array) $data['meta']; 586 $this->assertEquals( false, isset( $meta['test_cat_meta'] ) ); 587 } 588 530 589 public function test_get_term_invalid_term() { 531 590 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); … … 629 688 $request->set_param( 'description', 'New Description' ); 630 689 $request->set_param( 'slug', 'new-slug' ); 631 $response = $this->server->dispatch( $request ); 690 $request->set_param( 'meta', array( 691 'test_single' => 'just meta', 692 'test_tag_single' => 'tag-specific meta', 693 'test_cat_meta' => 'category-specific meta', 694 ) ); 695 $response = rest_get_server()->dispatch( $request ); 632 696 $this->assertEquals( 200, $response->get_status() ); 633 697 $data = $response->get_data(); … … 635 699 $this->assertEquals( 'New Description', $data['description'] ); 636 700 $this->assertEquals( 'new-slug', $data['slug'] ); 701 $this->assertEquals( 'just meta', $data['meta']['test_single'] ); 702 $this->assertEquals( 'tag-specific meta', $data['meta']['test_tag_single'] ); 703 $this->assertFalse( isset( $data['meta']['test_cat_meta'] ) ); 637 704 } 638 705 -
branches/5.0/tests/qunit/fixtures/wp-api-generated.js
r43681 r43713 4274 4274 "parent": 0, 4275 4275 "meta": { 4276 "meta_key": "" 4276 "test_single": "", 4277 "test_multi": [], 4278 "meta_key": "", 4279 "test_cat_single": "", 4280 "test_cat_multi": [] 4277 4281 }, 4278 4282 "_links": { … … 4318 4322 "parent": 0, 4319 4323 "meta": { 4320 "meta_key": "" 4324 "test_single": "", 4325 "test_multi": [], 4326 "meta_key": "", 4327 "test_cat_single": "", 4328 "test_cat_multi": [] 4321 4329 } 4322 4330 }; … … 4332 4340 "taxonomy": "post_tag", 4333 4341 "meta": { 4334 "meta_key": "meta_value" 4342 "test_single": "", 4343 "test_multi": [], 4344 "meta_key": "meta_value", 4345 "test_tag_meta": "" 4335 4346 }, 4336 4347 "_links": { … … 4375 4386 "taxonomy": "post_tag", 4376 4387 "meta": { 4377 "meta_key": "meta_value" 4388 "test_single": "", 4389 "test_multi": [], 4390 "meta_key": "meta_value", 4391 "test_tag_meta": "" 4378 4392 } 4379 4393 };
Note: See TracChangeset
for help on using the changeset viewer.