- Timestamp:
- 07/17/2023 02:20:42 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php
r56051 r56248 846 846 $this->assertSame( 'index', $response->get_data()['slug'], 'Should fallback to `index.html` when ignore_empty is `true`.' ); 847 847 } 848 849 /** 850 * @ticket 57851 851 * 852 * @covers WP_REST_Templates_Controller::prepare_item_for_database 853 */ 854 public function test_prepare_item_for_database() { 855 $endpoint = new WP_REST_Templates_Controller( 'wp_template_part' ); 856 857 $prepare_item_for_database = new ReflectionMethod( $endpoint, 'prepare_item_for_database' ); 858 $prepare_item_for_database->setAccessible( true ); 859 860 $body_params = array( 861 'title' => 'Untitled Template Part', 862 'slug' => 'untitled-template-part', 863 'content' => '', 864 ); 865 866 $request = new WP_REST_Request( 'POST', '/wp/v2/template-parts' ); 867 $request->set_body_params( $body_params ); 868 869 $prepared = $prepare_item_for_database->invoke( $endpoint, $request ); 870 871 $this->assertInstanceOf( 'stdClass', $prepared, 'The item could not be prepared for the database.' ); 872 873 $this->assertObjectHasAttribute( 'post_type', $prepared, 'The "post_type" was not included in the prepared template part.' ); 874 $this->assertObjectHasAttribute( 'post_status', $prepared, 'The "post_status" was not included in the prepared template part.' ); 875 $this->assertObjectHasAttribute( 'tax_input', $prepared, 'The "tax_input" was not included in the prepared template part.' ); 876 $this->assertArrayHasKey( 'wp_theme', $prepared->tax_input, 'The "wp_theme" tax was not included in the prepared template part.' ); 877 $this->assertArrayHasKey( 'wp_template_part_area', $prepared->tax_input, 'The "wp_template_part_area" tax was not included in the prepared template part.' ); 878 $this->assertObjectHasAttribute( 'post_content', $prepared, 'The "post_content" was not included in the prepared template part.' ); 879 $this->assertObjectHasAttribute( 'post_title', $prepared, 'The "post_title" was not included in the prepared template part.' ); 880 881 $this->assertSame( 'wp_template_part', $prepared->post_type, 'The "post_type" in the prepared template part should be "wp_template_part".' ); 882 $this->assertSame( 'publish', $prepared->post_status, 'The post status in the prepared template part should be "publish".' ); 883 $this->assertSame( WP_TEMPLATE_PART_AREA_UNCATEGORIZED, $prepared->tax_input['wp_template_part_area'], 'The area in the prepared template part should be uncategorized.' ); 884 $this->assertSame( 'Untitled Template Part', $prepared->post_title, 'The title was not correct in the prepared template part.' ); 885 886 $this->assertEmpty( $prepared->post_content, 'The content was not correct in the prepared template part.' ); 887 } 848 888 }
Note: See TracChangeset
for help on using the changeset viewer.