| | 1697 | |
| | 1698 | /** |
| | 1699 | * @ticket 36696 |
| | 1700 | */ |
| | 1701 | public function test_cast_value_numeric_big() { |
| | 1702 | $posts = $this->factory->post->create_many( 1 ); |
| | 1703 | |
| | 1704 | // Will trigger (depending on system) MySQL string to float type conversion on quoted numbers. |
| | 1705 | $big_int = 0x20000000000001; // 0x20 0000 0000 0001 (54 bit integer + 1, 9007199254740993). |
| | 1706 | update_post_meta( $posts[0], 'foo', $big_int - 1 ); |
| | 1707 | |
| | 1708 | $q = new WP_Query( array( |
| | 1709 | 'update_post_meta_cache' => false, |
| | 1710 | 'update_term_meta_cache' => false, |
| | 1711 | 'fields' => 'ids', |
| | 1712 | 'meta_query' => array( |
| | 1713 | array( |
| | 1714 | 'key' => 'foo', |
| | 1715 | 'value' => $big_int, |
| | 1716 | 'compare' => '<', |
| | 1717 | 'type' => 'NUMERIC', |
| | 1718 | ), |
| | 1719 | ), |
| | 1720 | ) ); |
| | 1721 | |
| | 1722 | $this->assertEquals( array( $posts[0] ), $q->posts ); |
| | 1723 | } |
| | 1724 | |
| | 1725 | /** |
| | 1726 | * @ticket 36696 |
| | 1727 | */ |
| | 1728 | public function test_cast_value_numeric_max() { |
| | 1729 | $posts = $this->factory->post->create_many( 1 ); |
| | 1730 | |
| | 1731 | $max_int = PHP_INT_MAX; |
| | 1732 | update_post_meta( $posts[0], 'foo', $max_int - 1 ); |
| | 1733 | |
| | 1734 | $q = new WP_Query( array( |
| | 1735 | 'update_post_meta_cache' => false, |
| | 1736 | 'update_term_meta_cache' => false, |
| | 1737 | 'fields' => 'ids', |
| | 1738 | 'meta_query' => array( |
| | 1739 | array( |
| | 1740 | 'key' => 'foo', |
| | 1741 | 'value' => $max_int, |
| | 1742 | 'compare' => '<', |
| | 1743 | 'type' => 'NUMERIC', |
| | 1744 | ), |
| | 1745 | ), |
| | 1746 | ) ); |
| | 1747 | |
| | 1748 | $this->assertEquals( array( $posts[0] ), $q->posts ); |
| | 1749 | } |
| | 1750 | |
| | 1751 | /** |
| | 1752 | * @ticket 36696 |
| | 1753 | */ |
| | 1754 | public function test_cast_value_numeric_ignore_if_like() { |
| | 1755 | $posts = $this->factory->post->create_many( 1 ); |
| | 1756 | |
| | 1757 | update_post_meta( $posts[0], 'foo', 10101 ); |
| | 1758 | |
| | 1759 | $q = new WP_Query( array( |
| | 1760 | 'update_post_meta_cache' => false, |
| | 1761 | 'update_term_meta_cache' => false, |
| | 1762 | 'fields' => 'ids', |
| | 1763 | 'meta_query' => array( |
| | 1764 | array( |
| | 1765 | 'key' => 'foo', |
| | 1766 | 'value' => 101, |
| | 1767 | 'compare' => 'LIKE', |
| | 1768 | 'type' => 'NUMERIC', |
| | 1769 | ), |
| | 1770 | ), |
| | 1771 | ) ); |
| | 1772 | |
| | 1773 | $this->assertEquals( array( $posts[0] ), $q->posts ); |
| | 1774 | } |