| @@ 782-811 (lines=30) @@ | ||
| 779 | $this->assertEquals( array_keys( get_taxonomies() ), $properties['taxonomy']['enum'] ); |
|
| 780 | } |
|
| 781 | ||
| 782 | public function test_get_additional_field_registration() { |
|
| 783 | ||
| 784 | $schema = array( |
|
| 785 | 'type' => 'integer', |
|
| 786 | 'description' => 'Some integer of mine', |
|
| 787 | 'enum' => array( 1, 2, 3, 4 ), |
|
| 788 | 'context' => array( 'view', 'edit' ), |
|
| 789 | ); |
|
| 790 | ||
| 791 | register_rest_field( 'category', 'my_custom_int', array( |
|
| 792 | 'schema' => $schema, |
|
| 793 | 'get_callback' => array( $this, 'additional_field_get_callback' ), |
|
| 794 | ) ); |
|
| 795 | ||
| 796 | $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' ); |
|
| 797 | ||
| 798 | $response = $this->server->dispatch( $request ); |
|
| 799 | $data = $response->get_data(); |
|
| 800 | $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); |
|
| 801 | $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] ); |
|
| 802 | ||
| 803 | $category_id = $this->factory->category->create(); |
|
| 804 | $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $category_id ); |
|
| 805 | ||
| 806 | $response = $this->server->dispatch( $request ); |
|
| 807 | $this->assertArrayHasKey( 'my_custom_int', $response->data ); |
|
| 808 | ||
| 809 | global $wp_rest_additional_fields; |
|
| 810 | $wp_rest_additional_fields = array(); |
|
| 811 | } |
|
| 812 | ||
| 813 | public function additional_field_get_callback( $object, $request ) { |
|
| 814 | return 123; |
|
| @@ 606-635 (lines=30) @@ | ||
| 603 | $this->assertFalse( isset( $properties['parent'] ) ); |
|
| 604 | } |
|
| 605 | ||
| 606 | public function test_get_additional_field_registration() { |
|
| 607 | ||
| 608 | $schema = array( |
|
| 609 | 'type' => 'integer', |
|
| 610 | 'description' => 'Some integer of mine', |
|
| 611 | 'enum' => array( 1, 2, 3, 4 ), |
|
| 612 | 'context' => array( 'view', 'edit' ), |
|
| 613 | ); |
|
| 614 | ||
| 615 | register_rest_field( 'tag', 'my_custom_int', array( |
|
| 616 | 'schema' => $schema, |
|
| 617 | 'get_callback' => array( $this, 'additional_field_get_callback' ), |
|
| 618 | ) ); |
|
| 619 | ||
| 620 | $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); |
|
| 621 | ||
| 622 | $response = $this->server->dispatch( $request ); |
|
| 623 | $data = $response->get_data(); |
|
| 624 | $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); |
|
| 625 | $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] ); |
|
| 626 | ||
| 627 | $tag_id = $this->factory->tag->create(); |
|
| 628 | $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $tag_id ); |
|
| 629 | ||
| 630 | $response = $this->server->dispatch( $request ); |
|
| 631 | $this->assertArrayHasKey( 'my_custom_int', $response->data ); |
|
| 632 | ||
| 633 | global $wp_rest_additional_fields; |
|
| 634 | $wp_rest_additional_fields = array(); |
|
| 635 | } |
|
| 636 | ||
| 637 | public function test_additional_field_update_errors() { |
|
| 638 | $schema = array( |
|