Ticket #39122: add-term-meta-unit-tests.diff
File add-term-meta-unit-tests.diff, 2.2 KB (added by , 8 years ago) |
---|
-
tests/phpunit/tests/rest-api/rest-categories-controller.php
28 28 self::delete_user( self::$subscriber ); 29 29 } 30 30 31 public function setUp() { 32 parent::setUp(); 33 34 register_meta( 'term', 'test_single', array( 35 'show_in_rest' => true, 36 'single' => true, 37 'type' => 'string', 38 )); 39 register_meta( 'term', 'test_multi', array( 40 'show_in_rest' => true, 41 'single' => false, 42 'type' => 'string', 43 )); 44 } 45 31 46 public function test_register_routes() { 32 47 $routes = $this->server->get_routes(); 33 48 $this->assertArrayHasKey( '/wp/v2/categories', $routes ); … … 549 564 $this->check_get_taxonomy_term_response( $response ); 550 565 } 551 566 567 public function test_get_item_meta() { 568 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 569 $response = $this->server->dispatch( $request ); 570 $data = $response->get_data(); 571 $this->assertArrayHasKey( 'meta', $data ); 572 573 $meta = (array) $data['meta']; 574 $this->assertArrayHasKey( 'test_single', $meta ); 575 $this->assertEquals( $meta['test_single'], '' ); 576 $this->assertArrayHasKey( 'test_multi', $meta ); 577 $this->assertEquals( $meta['test_multi'], array() ); 578 } 579 552 580 public function test_get_term_invalid_taxonomy() { 553 581 $request = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy/1' ); 554 582 $response = $this->server->dispatch( $request ); … … 660 688 $request->set_param( 'name', 'New Name' ); 661 689 $request->set_param( 'description', 'New Description' ); 662 690 $request->set_param( 'slug', 'new-slug' ); 691 $request->set_param( 'meta', array( 'test_single' => 'just meta' ) ); 663 692 $response = $this->server->dispatch( $request ); 664 693 $this->assertEquals( 200, $response->get_status() ); 665 694 $data = $response->get_data(); … … 666 695 $this->assertEquals( 'New Name', $data['name'] ); 667 696 $this->assertEquals( 'New Description', $data['description'] ); 668 697 $this->assertEquals( 'new-slug', $data['slug'] ); 698 $this->assertEquals( 'just meta', $data['meta']['test_single'] ); 669 699 } 670 700 671 701 public function test_update_item_invalid_taxonomy() {