Make WordPress Core

Ticket #27272: 27272_test3.diff

File 27272_test3.diff, 3.0 KB (added by gitlost, 9 years ago)

Added back original tests from 27272.2.diff.

  • tests/phpunit/tests/meta/query.php

     
    884884
    885885                $this->assertTrue( $q->has_or_relation() );
    886886        }
     887
     888        /**
     889         * @group 27272
     890         */
     891        function test_cast_both_sides() {
     892                global $wpdb;
     893
     894                $query = new WP_Meta_Query( array(
     895                        array(
     896                                'key'       => 'number_string',
     897                                'value'     => '1000000',
     898                                'compare'   => '<=',
     899                                'type'      => 'NUMERIC',
     900                        ),
     901                ) );
     902
     903                $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
     904                $this->assertNotContains( "CAST({$wpdb->postmeta}.meta_value AS SIGNED) <= '1000000'", $sql['where'] );
     905                $this->assertContains( "CAST({$wpdb->postmeta}.meta_value AS SIGNED) <= 1000000", $sql['where'] );
     906        }
    887907}
  • tests/phpunit/tests/meta.php

     
    254254                ) );
    255255
    256256                $this->assertEquals( array( $post_id2, $post_id1 ), $posts->posts );
     257                $this->assertNotContains( "> '0'", $posts->request );
     258                $this->assertContains( "> 0", $posts->request );
    257259                $this->assertEquals( 2, substr_count( $posts->request, 'CAST(' ) );
    258260        }
    259261
  • tests/phpunit/tests/query/metaQuery.php

     
    16941694
    16951695                $this->assertEqualSets( array( 'foo_key', 'foo_key-1', 'foo_key-2' ), array_keys( $q->meta_query->get_clauses() ) );
    16961696        }
     1697
     1698        /**
     1699         * @ticket 27272
     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 27272
     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        }
    16971750}