| @@ 321-332 (lines=12) @@ | ||
| 318 | $this->assertEquals($page_id, $new_post->post_parent); |
|
| 319 | } |
|
| 320 | ||
| 321 | public function test_create_page_with_invalid_parent() |
|
| 322 | { |
|
| 323 | wp_set_current_user(self::$editor_id); |
|
| 324 | ||
| 325 | $request = new WP_REST_Request('POST', '/wp/v2/pages'); |
|
| 326 | $params = $this->set_post_data( |
|
| 327 | array( |
|
| 328 | 'parent' => -1, |
|
| 329 | ) |
|
| 330 | ); |
|
| 331 | $request->set_body_params($params); |
|
| 332 | $response = $this->server->dispatch($request); |
|
| 333 | ||
| 334 | $this->assertErrorResponse('rest_post_invalid_id', $response, 400); |
|
| 335 | } |
|
| @@ 1214-1225 (lines=12) @@ | ||
| 1211 | /** |
|
| 1212 | * @ticket 38698 |
|
| 1213 | */ |
|
| 1214 | public function test_create_item_with_template_none_available() |
|
| 1215 | { |
|
| 1216 | wp_set_current_user(self::$editor_id); |
|
| 1217 | ||
| 1218 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1219 | $params = $this->set_post_data( |
|
| 1220 | array( |
|
| 1221 | 'template' => 'post-my-test-template.php', |
|
| 1222 | ) |
|
| 1223 | ); |
|
| 1224 | $request->set_body_params($params); |
|
| 1225 | $response = $this->server->dispatch($request); |
|
| 1226 | ||
| 1227 | $this->assertErrorResponse('rest_invalid_param', $response, 400); |
|
| 1228 | } |
|
| @@ 1268-1279 (lines=12) @@ | ||
| 1265 | $this->check_create_post_response($response); |
|
| 1266 | } |
|
| 1267 | ||
| 1268 | public function test_create_post_invalid_id() |
|
| 1269 | { |
|
| 1270 | wp_set_current_user(self::$editor_id); |
|
| 1271 | ||
| 1272 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1273 | $params = $this->set_post_data( |
|
| 1274 | array( |
|
| 1275 | 'id' => '3', |
|
| 1276 | ) |
|
| 1277 | ); |
|
| 1278 | $request->set_body_params($params); |
|
| 1279 | $response = $this->server->dispatch($request); |
|
| 1280 | ||
| 1281 | $this->assertErrorResponse('rest_post_exists', $response, 400); |
|
| 1282 | } |
|
| @@ 1452-1463 (lines=12) @@ | ||
| 1449 | $this->assertErrorResponse('rest_cannot_publish', $response, 403); |
|
| 1450 | } |
|
| 1451 | ||
| 1452 | public function test_create_post_invalid_status() |
|
| 1453 | { |
|
| 1454 | wp_set_current_user(self::$editor_id); |
|
| 1455 | ||
| 1456 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1457 | $params = $this->set_post_data( |
|
| 1458 | array( |
|
| 1459 | 'status' => 'teststatus', |
|
| 1460 | ) |
|
| 1461 | ); |
|
| 1462 | $request->set_body_params($params); |
|
| 1463 | $response = $this->server->dispatch($request); |
|
| 1464 | ||
| 1465 | $this->assertErrorResponse('rest_invalid_param', $response, 400); |
|
| 1466 | } |
|
| @@ 1506-1517 (lines=12) @@ | ||
| 1503 | $this->assertFalse(get_post_format($new_post->ID)); |
|
| 1504 | } |
|
| 1505 | ||
| 1506 | public function test_create_post_with_invalid_format() |
|
| 1507 | { |
|
| 1508 | wp_set_current_user(self::$editor_id); |
|
| 1509 | ||
| 1510 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1511 | $params = $this->set_post_data( |
|
| 1512 | array( |
|
| 1513 | 'format' => 'testformat', |
|
| 1514 | ) |
|
| 1515 | ); |
|
| 1516 | $request->set_body_params($params); |
|
| 1517 | $response = $this->server->dispatch($request); |
|
| 1518 | ||
| 1519 | $this->assertErrorResponse('rest_invalid_param', $response, 400); |
|
| 1520 | } |
|
| @@ 1527-1538 (lines=12) @@ | ||
| 1524 | * |
|
| 1525 | * https://core.trac.wordpress.org/ticket/38610 |
|
| 1526 | */ |
|
| 1527 | public function test_create_post_with_unsupported_format() |
|
| 1528 | { |
|
| 1529 | wp_set_current_user(self::$editor_id); |
|
| 1530 | ||
| 1531 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1532 | $params = $this->set_post_data( |
|
| 1533 | array( |
|
| 1534 | 'format' => 'link', |
|
| 1535 | ) |
|
| 1536 | ); |
|
| 1537 | $request->set_body_params($params); |
|
| 1538 | $response = $this->server->dispatch($request); |
|
| 1539 | ||
| 1540 | $this->assertErrorResponse('rest_invalid_param', $response, 400); |
|
| 1541 | } |
|
| @@ 1582-1593 (lines=12) @@ | ||
| 1579 | $this->assertEquals(0, (int) get_post_thumbnail_id($new_post->ID)); |
|
| 1580 | } |
|
| 1581 | ||
| 1582 | public function test_create_post_invalid_author() |
|
| 1583 | { |
|
| 1584 | wp_set_current_user(self::$editor_id); |
|
| 1585 | ||
| 1586 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1587 | $params = $this->set_post_data( |
|
| 1588 | array( |
|
| 1589 | 'author' => -1, |
|
| 1590 | ) |
|
| 1591 | ); |
|
| 1592 | $request->set_body_params($params); |
|
| 1593 | $response = $this->server->dispatch($request); |
|
| 1594 | ||
| 1595 | $this->assertErrorResponse('rest_invalid_author', $response, 400); |
|
| 1596 | } |
|
| @@ 1614-1626 (lines=13) @@ | ||
| 1611 | $this->assertErrorResponse('rest_cannot_edit_others', $response, 403); |
|
| 1612 | } |
|
| 1613 | ||
| 1614 | public function test_create_post_with_password() |
|
| 1615 | { |
|
| 1616 | wp_set_current_user(self::$editor_id); |
|
| 1617 | ||
| 1618 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1619 | $params = $this->set_post_data( |
|
| 1620 | array( |
|
| 1621 | 'password' => 'testing', |
|
| 1622 | ) |
|
| 1623 | ); |
|
| 1624 | $request->set_body_params($params); |
|
| 1625 | $response = $this->server->dispatch($request); |
|
| 1626 | ||
| 1627 | $data = $response->get_data(); |
|
| 1628 | $this->assertEquals('testing', $data['password']); |
|
| 1629 | } |
|
| @@ 1631-1644 (lines=14) @@ | ||
| 1628 | $this->assertEquals('testing', $data['password']); |
|
| 1629 | } |
|
| 1630 | ||
| 1631 | public function test_create_post_with_falsy_password() |
|
| 1632 | { |
|
| 1633 | wp_set_current_user(self::$editor_id); |
|
| 1634 | ||
| 1635 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1636 | $params = $this->set_post_data( |
|
| 1637 | array( |
|
| 1638 | 'password' => '0', |
|
| 1639 | ) |
|
| 1640 | ); |
|
| 1641 | $request->set_body_params($params); |
|
| 1642 | $response = $this->server->dispatch($request); |
|
| 1643 | ||
| 1644 | $data = $response->get_data(); |
|
| 1645 | ||
| 1646 | $this->assertEquals('0', $data['password']); |
|
| 1647 | } |
|
| @@ 1752-1763 (lines=12) @@ | ||
| 1749 | $this->assertErrorResponse('db_insert_error', $response, 500); |
|
| 1750 | } |
|
| 1751 | ||
| 1752 | public function test_create_post_with_invalid_date() |
|
| 1753 | { |
|
| 1754 | wp_set_current_user(self::$editor_id); |
|
| 1755 | ||
| 1756 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1757 | $params = $this->set_post_data( |
|
| 1758 | array( |
|
| 1759 | 'date' => '2010-60-01T02:00:00Z', |
|
| 1760 | ) |
|
| 1761 | ); |
|
| 1762 | $request->set_body_params($params); |
|
| 1763 | $response = $this->server->dispatch($request); |
|
| 1764 | ||
| 1765 | $this->assertErrorResponse('rest_invalid_param', $response, 400); |
|
| 1766 | } |
|
| @@ 1768-1779 (lines=12) @@ | ||
| 1765 | $this->assertErrorResponse('rest_invalid_param', $response, 400); |
|
| 1766 | } |
|
| 1767 | ||
| 1768 | public function test_create_post_with_invalid_date_gmt() |
|
| 1769 | { |
|
| 1770 | wp_set_current_user(self::$editor_id); |
|
| 1771 | ||
| 1772 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1773 | $params = $this->set_post_data( |
|
| 1774 | array( |
|
| 1775 | 'date_gmt' => '2010-60-01T02:00:00', |
|
| 1776 | ) |
|
| 1777 | ); |
|
| 1778 | $request->set_body_params($params); |
|
| 1779 | $response = $this->server->dispatch($request); |
|
| 1780 | ||
| 1781 | $this->assertErrorResponse('rest_invalid_param', $response, 400); |
|
| 1782 | } |
|
| @@ 1784-1795 (lines=12) @@ | ||
| 1781 | $this->assertErrorResponse('rest_invalid_param', $response, 400); |
|
| 1782 | } |
|
| 1783 | ||
| 1784 | public function test_create_post_with_quotes_in_title() |
|
| 1785 | { |
|
| 1786 | wp_set_current_user(self::$editor_id); |
|
| 1787 | ||
| 1788 | $request = new WP_REST_Request('POST', '/wp/v2/posts'); |
|
| 1789 | $params = $this->set_post_data( |
|
| 1790 | array( |
|
| 1791 | 'title' => "Rob O'Rourke's Diary", |
|
| 1792 | ) |
|
| 1793 | ); |
|
| 1794 | $request->set_body_params($params); |
|
| 1795 | $response = $this->server->dispatch($request); |
|
| 1796 | $new_data = $response->get_data(); |
|
| 1797 | $this->assertEquals("Rob O'Rourke's Diary", $new_data['title']['raw']); |
|
| 1798 | } |
|
| @@ 2390-2401 (lines=12) @@ | ||
| 2387 | $this->assertErrorResponse('rest_invalid_field', $response, 400); |
|
| 2388 | } |
|
| 2389 | ||
| 2390 | public function test_update_post_with_quotes_in_title() |
|
| 2391 | { |
|
| 2392 | wp_set_current_user(self::$editor_id); |
|
| 2393 | ||
| 2394 | $request = new WP_REST_Request('PUT', sprintf('/wp/v2/posts/%d', self::$post_id)); |
|
| 2395 | $params = $this->set_post_data( |
|
| 2396 | array( |
|
| 2397 | 'title' => "Rob O'Rourke's Diary", |
|
| 2398 | ) |
|
| 2399 | ); |
|
| 2400 | $request->set_body_params($params); |
|
| 2401 | $response = $this->server->dispatch($request); |
|
| 2402 | $new_data = $response->get_data(); |
|
| 2403 | $this->assertEquals("Rob O'Rourke's Diary", $new_data['title']['raw']); |
|
| 2404 | } |
|
| @@ 72-79 (lines=8) @@ | ||
| 69 | $this->check_taxonomies_for_type_response('post', $response); |
|
| 70 | } |
|
| 71 | ||
| 72 | public function test_get_taxonomies_for_invalid_type() |
|
| 73 | { |
|
| 74 | $request = new WP_REST_Request('GET', '/wp/v2/taxonomies'); |
|
| 75 | $request->set_param('type', 'wingding'); |
|
| 76 | $response = $this->server->dispatch($request); |
|
| 77 | $this->assertEquals(200, $response->get_status()); |
|
| 78 | $data = $response->get_data(); |
|
| 79 | $this->assertEquals('{}', json_encode($data)); |
|
| 80 | } |
|
| 81 | ||
| 82 | public function test_get_item() |
|