| 1071 | /** |
| 1072 | * @ticket 38877 |
| 1073 | */ |
| 1074 | public function test_create_item_with_template_default() { |
| 1075 | wp_set_current_user( self::$editor_id ); |
| 1076 | add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) ); |
| 1077 | |
| 1078 | update_post_meta( self::$post_id, '_wp_page_template', 'post-my-test-template.php' ); |
| 1079 | |
| 1080 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| 1081 | $params = $this->set_post_data( array( |
| 1082 | 'template' => 'default', |
| 1083 | ) ); |
| 1084 | $request->set_body_params( $params ); |
| 1085 | $response = $this->server->dispatch( $request ); |
| 1086 | |
| 1087 | $data = $response->get_data(); |
| 1088 | $post_template = get_page_template_slug( get_post( $data['id'] ) ); |
| 1089 | |
| 1090 | update_post_meta( self::$post_id, '_wp_page_template', '' ); |
| 1091 | remove_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) ); |
| 1092 | |
| 1093 | $this->assertEquals( '', $data['template'] ); |
| 1094 | $this->assertEquals( '', $post_template ); |
| 1095 | } |
| 1096 | |
| 1097 | /** |
| 1098 | * @ticket 38877 |
| 1099 | */ |
| 1100 | public function test_create_item_with_template_default_none_available() { |
| 1101 | wp_set_current_user( self::$editor_id ); |
| 1102 | |
| 1103 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| 1104 | $params = $this->set_post_data( array( |
| 1105 | 'template' => 'default', |
| 1106 | ) ); |
| 1107 | $request->set_body_params( $params ); |
| 1108 | $response = $this->server->dispatch( $request ); |
| 1109 | |
| 1110 | $data = $response->get_data(); |
| 1111 | $post_template = get_page_template_slug( get_post( $data['id'] ) ); |
| 1112 | |
| 1113 | update_post_meta( self::$post_id, '_wp_page_template', '' ); |
| 1114 | |
| 1115 | $this->assertEquals( '', $data['template'] ); |
| 1116 | $this->assertEquals( '', $post_template ); |
| 1117 | } |
| 1118 | |