| | 1606 | /** |
| | 1607 | * @ticket 26798 |
| | 1608 | * |
| | 1609 | * @dataProvider data_wp_insert_post_handle_malformed_post_date |
| | 1610 | * |
| | 1611 | * The purpose of this test is to ensure that invalid dates do not |
| | 1612 | * cause PHP errors when wp_insert_post() is called, and that the |
| | 1613 | * posts are not actually "inserted" (created). |
| | 1614 | */ |
| | 1615 | public function test_wp_insert_post_handle_malformed_post_date( $input, $expected ) { |
| | 1616 | $post = array( |
| | 1617 | 'post_author' => self::$editor_id, |
| | 1618 | 'post_status' => 'publish', |
| | 1619 | 'post_content' => 'content', |
| | 1620 | 'post_title' => 'title', |
| | 1621 | 'post_date' => $input, |
| | 1622 | ); |
| | 1623 | |
| | 1624 | // Inserting the post should fail gracefully. |
| | 1625 | $id = wp_insert_post( $post ); |
| | 1626 | |
| | 1627 | // Check if the result is "0" or not. |
| | 1628 | $result = ! empty( $id ); |
| | 1629 | $this->assertEquals( $result, $expected ); |
| | 1630 | } |
| | 1631 | |
| | 1632 | /** |
| | 1633 | * @ticket 26798 |
| | 1634 | */ |
| | 1635 | public function data_wp_insert_post_handle_malformed_post_date() { |
| | 1636 | return array( |
| | 1637 | array( |
| | 1638 | '2012-01-01', |
| | 1639 | true, |
| | 1640 | ), |
| | 1641 | // 24-hour time format. |
| | 1642 | array( |
| | 1643 | '2012-01-01 13:00:00', |
| | 1644 | true, |
| | 1645 | ), |
| | 1646 | // ISO8601 date with timezone. |
| | 1647 | array( |
| | 1648 | '2016-01-16T00:00:00Z', |
| | 1649 | true, |
| | 1650 | ), |
| | 1651 | // ISO8601 date with timezone offset. |
| | 1652 | array( |
| | 1653 | '2016-01-16T00:00:00+0100', |
| | 1654 | true, |
| | 1655 | ), |
| | 1656 | // RFC3339 Format. |
| | 1657 | array( |
| | 1658 | '1970-01-01T01:00:00+01:00', |
| | 1659 | true, |
| | 1660 | ), |
| | 1661 | // RSS Format |
| | 1662 | array( |
| | 1663 | '1970-01-01T01:00:00+0100', |
| | 1664 | true, |
| | 1665 | ), |
| | 1666 | // Leap year. |
| | 1667 | array( |
| | 1668 | '2012-02-29', |
| | 1669 | true, |
| | 1670 | ), |
| | 1671 | // Strange formats. |
| | 1672 | array( |
| | 1673 | '2012-01-01 0', |
| | 1674 | true, |
| | 1675 | ), |
| | 1676 | array( |
| | 1677 | '2012-01-01 25:00:00', |
| | 1678 | true, |
| | 1679 | ), |
| | 1680 | array( |
| | 1681 | '2012-01-01 00:60:00', |
| | 1682 | true, |
| | 1683 | ), |
| | 1684 | // Failures. |
| | 1685 | array( |
| | 1686 | '2012-08-0z', |
| | 1687 | false, |
| | 1688 | ), |
| | 1689 | array( |
| | 1690 | '2012-08-1', |
| | 1691 | false, |
| | 1692 | ), |
| | 1693 | array( |
| | 1694 | '201-01-08 00:00:00', |
| | 1695 | false, |
| | 1696 | ), |
| | 1697 | array( |
| | 1698 | '201-01-08 00:60:00', |
| | 1699 | false, |
| | 1700 | ), |
| | 1701 | array( |
| | 1702 | '201a-01-08 00:00:00', |
| | 1703 | false, |
| | 1704 | ), |
| | 1705 | array( |
| | 1706 | '2012-1-08 00:00:00', |
| | 1707 | false, |
| | 1708 | ), |
| | 1709 | array( |
| | 1710 | '2012-31-08 00:00:00', |
| | 1711 | false, |
| | 1712 | ), |
| | 1713 | array( |
| | 1714 | '2012-01-8 00:00:00', |
| | 1715 | false, |
| | 1716 | ), |
| | 1717 | array( |
| | 1718 | '2012-01-48 00:00:00', |
| | 1719 | false, |
| | 1720 | ), |
| | 1721 | // Not a leap year. |
| | 1722 | array( |
| | 1723 | '2011-02-29', |
| | 1724 | false, |
| | 1725 | ), |
| | 1726 | ); |
| | 1727 | } |
| | 1728 | |
| | 1765 | /** |
| | 1766 | * @ticket 26798 |
| | 1767 | * |
| | 1768 | * @dataProvider data_wp_resolve_post_date_regex |
| | 1769 | * |
| | 1770 | * Tests the regex inside of wp_resolve_post_date(), with |
| | 1771 | * the emphasis on the date format (not the time). |
| | 1772 | */ |
| | 1773 | public function test_wp_resolve_post_date_regex( $date, $expected ) { |
| | 1774 | $out = wp_resolve_post_date( $date ); |
| | 1775 | $this->assertEquals( $out, $expected ); |
| | 1776 | } |
| | 1777 | |
| | 1778 | /** |
| | 1779 | * @ticket 26798 |
| | 1780 | */ |
| | 1781 | public function data_wp_resolve_post_date_regex() { |
| | 1782 | return array( |
| | 1783 | array( |
| | 1784 | '2012-01-01', |
| | 1785 | '2012-01-01', |
| | 1786 | ), |
| | 1787 | array( |
| | 1788 | '2012-01-01 00:00:00', |
| | 1789 | '2012-01-01 00:00:00', |
| | 1790 | ), |
| | 1791 | // ISO8601 date with timezone. |
| | 1792 | array( |
| | 1793 | '2016-01-16T00:00:00Z', |
| | 1794 | '2016-01-16T00:00:00Z', |
| | 1795 | ), |
| | 1796 | // ISO8601 date with timezone offset. |
| | 1797 | array( |
| | 1798 | '2016-01-16T00:00:00+0100', |
| | 1799 | '2016-01-16T00:00:00+0100', |
| | 1800 | ), |
| | 1801 | // RFC3339 Format. |
| | 1802 | array( |
| | 1803 | '1970-01-01T01:00:00+01:00', |
| | 1804 | '1970-01-01T01:00:00+01:00', |
| | 1805 | ), |
| | 1806 | // RSS Format |
| | 1807 | array( |
| | 1808 | '1970-01-01T01:00:00+0100', |
| | 1809 | '1970-01-01T01:00:00+0100', |
| | 1810 | ), |
| | 1811 | // 24-hour time format. |
| | 1812 | array( |
| | 1813 | '2012-01-01 13:00:00', |
| | 1814 | '2012-01-01 13:00:00', |
| | 1815 | ), |
| | 1816 | array( |
| | 1817 | '2016-01-16T00:0', |
| | 1818 | '2016-01-16T00:0', |
| | 1819 | ), |
| | 1820 | array( |
| | 1821 | '2012-01-01 0', |
| | 1822 | '2012-01-01 0', |
| | 1823 | ), |
| | 1824 | array( |
| | 1825 | '2012-01-01 00:00', |
| | 1826 | '2012-01-01 00:00', |
| | 1827 | ), |
| | 1828 | array( |
| | 1829 | '2012-01-01 25:00:00', |
| | 1830 | '2012-01-01 25:00:00', |
| | 1831 | ), |
| | 1832 | array( |
| | 1833 | '2012-01-01 00:60:00', |
| | 1834 | '2012-01-01 00:60:00', |
| | 1835 | ), |
| | 1836 | array( |
| | 1837 | '2012-01-01 00:00:60', |
| | 1838 | '2012-01-01 00:00:60', |
| | 1839 | ), |
| | 1840 | array( |
| | 1841 | '201-01-08', |
| | 1842 | false, |
| | 1843 | ), |
| | 1844 | array( |
| | 1845 | '201a-01-08', |
| | 1846 | false, |
| | 1847 | ), |
| | 1848 | array( |
| | 1849 | '2012-1-08', |
| | 1850 | false, |
| | 1851 | ), |
| | 1852 | array( |
| | 1853 | '2012-31-08', |
| | 1854 | false, |
| | 1855 | ), |
| | 1856 | array( |
| | 1857 | '2012-01-8', |
| | 1858 | false, |
| | 1859 | ), |
| | 1860 | array( |
| | 1861 | '2012-01-48 00:00:00', |
| | 1862 | false, |
| | 1863 | ), |
| | 1864 | // Leap year. |
| | 1865 | array( |
| | 1866 | '2012-02-29', |
| | 1867 | '2012-02-29', |
| | 1868 | ), |
| | 1869 | array( |
| | 1870 | '2011-02-29', |
| | 1871 | false, |
| | 1872 | ), |
| | 1873 | |
| | 1874 | ); |
| | 1875 | } |
| | 1876 | |