| @@ 273-287 (lines=15) @@ | ||
| 270 | ||
| 271 | } |
|
| 272 | ||
| 273 | public function test_create_item_with_template() |
|
| 274 | { |
|
| 275 | wp_set_current_user(self::$editor_id); |
|
| 276 | ||
| 277 | $request = new WP_REST_Request('POST', '/wp/v2/pages'); |
|
| 278 | $params = $this->set_post_data( |
|
| 279 | array( |
|
| 280 | 'template' => 'page-my-test-template.php', |
|
| 281 | ) |
|
| 282 | ); |
|
| 283 | $request->set_body_params($params); |
|
| 284 | $response = $this->server->dispatch($request); |
|
| 285 | ||
| 286 | $data = $response->get_data(); |
|
| 287 | $new_post = get_post($data['id']); |
|
| 288 | $this->assertEquals('page-my-test-template.php', $data['template']); |
|
| 289 | $this->assertEquals('page-my-test-template.php', get_page_template_slug($new_post->ID)); |
|
| 290 | } |
|
| @@ 1468-1482 (lines=15) @@ | ||
| 1465 | $this->assertErrorResponse('rest_invalid_param', $response, 400); |
|
| 1466 | } |
|
| 1467 | ||
| 1468 | public function test_create_post_with_format() |
|
| 1469 | { |
|
| 1470 | wp_set_current_user(self::$editor_id); |
|
| 1471 | ||
| 1472 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1473 | $params = $this->set_post_data( |
|
| 1474 | array( |
|
| 1475 | 'format' => 'gallery', |
|
| 1476 | ) |
|
| 1477 | ); |
|
| 1478 | $request->set_body_params($params); |
|
| 1479 | $response = $this->server->dispatch($request); |
|
| 1480 | ||
| 1481 | $data = $response->get_data(); |
|
| 1482 | $new_post = get_post($data['id']); |
|
| 1483 | $this->assertEquals('gallery', $data['format']); |
|
| 1484 | $this->assertEquals('gallery', get_post_format($new_post->ID)); |
|
| 1485 | } |
|
| @@ 1487-1501 (lines=15) @@ | ||
| 1484 | $this->assertEquals('gallery', get_post_format($new_post->ID)); |
|
| 1485 | } |
|
| 1486 | ||
| 1487 | public function test_create_post_with_standard_format() |
|
| 1488 | { |
|
| 1489 | wp_set_current_user(self::$editor_id); |
|
| 1490 | ||
| 1491 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1492 | $params = $this->set_post_data( |
|
| 1493 | array( |
|
| 1494 | 'format' => 'standard', |
|
| 1495 | ) |
|
| 1496 | ); |
|
| 1497 | $request->set_body_params($params); |
|
| 1498 | $response = $this->server->dispatch($request); |
|
| 1499 | ||
| 1500 | $data = $response->get_data(); |
|
| 1501 | $new_post = get_post($data['id']); |
|
| 1502 | $this->assertEquals('standard', $data['format']); |
|
| 1503 | $this->assertFalse(get_post_format($new_post->ID)); |
|
| 1504 | } |
|
| @@ 2043-2057 (lines=15) @@ | ||
| 2040 | $this->assertErrorResponse('rest_post_invalid_id', $response, 404); |
|
| 2041 | } |
|
| 2042 | ||
| 2043 | public function test_update_post_with_format() |
|
| 2044 | { |
|
| 2045 | wp_set_current_user(self::$editor_id); |
|
| 2046 | ||
| 2047 | $request = new WP_REST_Request('PUT', sprintf('/wp/v2/posts/%d', self::$post_id)); |
|
| 2048 | $params = $this->set_post_data( |
|
| 2049 | array( |
|
| 2050 | 'format' => 'gallery', |
|
| 2051 | ) |
|
| 2052 | ); |
|
| 2053 | $request->set_body_params($params); |
|
| 2054 | $response = $this->server->dispatch($request); |
|
| 2055 | ||
| 2056 | $data = $response->get_data(); |
|
| 2057 | $new_post = get_post($data['id']); |
|
| 2058 | $this->assertEquals('gallery', $data['format']); |
|
| 2059 | $this->assertEquals('gallery', get_post_format($new_post->ID)); |
|
| 2060 | } |
|
| @@ 2062-2076 (lines=15) @@ | ||
| 2059 | $this->assertEquals('gallery', get_post_format($new_post->ID)); |
|
| 2060 | } |
|
| 2061 | ||
| 2062 | public function test_update_post_with_standard_format() |
|
| 2063 | { |
|
| 2064 | wp_set_current_user(self::$editor_id); |
|
| 2065 | ||
| 2066 | $request = new WP_REST_Request('PUT', sprintf('/wp/v2/posts/%d', self::$post_id)); |
|
| 2067 | $params = $this->set_post_data( |
|
| 2068 | array( |
|
| 2069 | 'format' => 'standard', |
|
| 2070 | ) |
|
| 2071 | ); |
|
| 2072 | $request->set_body_params($params); |
|
| 2073 | $response = $this->server->dispatch($request); |
|
| 2074 | ||
| 2075 | $data = $response->get_data(); |
|
| 2076 | $new_post = get_post($data['id']); |
|
| 2077 | $this->assertEquals('standard', $data['format']); |
|
| 2078 | $this->assertFalse(get_post_format($new_post->ID)); |
|
| 2079 | } |
|
| @@ 2179-2193 (lines=15) @@ | ||
| 2176 | $this->assertErrorResponse('rest_invalid_param', $response, 400); |
|
| 2177 | } |
|
| 2178 | ||
| 2179 | public function test_update_post_slug() |
|
| 2180 | { |
|
| 2181 | wp_set_current_user(self::$editor_id); |
|
| 2182 | ||
| 2183 | $request = new WP_REST_Request('PUT', sprintf('/wp/v2/posts/%d', self::$post_id)); |
|
| 2184 | $params = $this->set_post_data( |
|
| 2185 | array( |
|
| 2186 | 'slug' => 'sample-slug', |
|
| 2187 | ) |
|
| 2188 | ); |
|
| 2189 | $request->set_body_params($params); |
|
| 2190 | $response = $this->server->dispatch($request); |
|
| 2191 | ||
| 2192 | $new_data = $response->get_data(); |
|
| 2193 | $this->assertEquals('sample-slug', $new_data['slug']); |
|
| 2194 | $post = get_post($new_data['id']); |
|
| 2195 | $this->assertEquals('sample-slug', $post->post_name); |
|
| 2196 | } |
|
| @@ 2198-2212 (lines=15) @@ | ||
| 2195 | $this->assertEquals('sample-slug', $post->post_name); |
|
| 2196 | } |
|
| 2197 | ||
| 2198 | public function test_update_post_slug_accented_chars() |
|
| 2199 | { |
|
| 2200 | wp_set_current_user(self::$editor_id); |
|
| 2201 | ||
| 2202 | $request = new WP_REST_Request('PUT', sprintf('/wp/v2/posts/%d', self::$post_id)); |
|
| 2203 | $params = $this->set_post_data( |
|
| 2204 | array( |
|
| 2205 | 'slug' => 'tęst-acceńted-chäræcters', |
|
| 2206 | ) |
|
| 2207 | ); |
|
| 2208 | $request->set_body_params($params); |
|
| 2209 | $response = $this->server->dispatch($request); |
|
| 2210 | ||
| 2211 | $new_data = $response->get_data(); |
|
| 2212 | $this->assertEquals('test-accented-charaecters', $new_data['slug']); |
|
| 2213 | $post = get_post($new_data['id']); |
|
| 2214 | $this->assertEquals('test-accented-charaecters', $post->post_name); |
|
| 2215 | } |
|