Make WordPress Core

Changeset 1276 in tests for trunk/tests/meta/query.php


Ignore:
Timestamp:
04/29/2013 09:02:38 AM (11 years ago)
Author:
westi
Message:

Meta Queries: Add a test case to validate that when generating the meta query SQL for an empty value array we don't generate invalid SQL.

See #22096

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/meta/query.php

    r1173 r1276  
    8080        $this->assertEquals( array( array( 'key' => 'abc', 'compare' => '=>' ) ), $query->queries );
    8181    }
     82
     83    /*
     84     * @ticket 22096
     85     */
     86    function test_empty_value_sql() {
     87        global $wpdb;
     88
     89        $query = new WP_Meta_Query();
     90
     91        $the_complex_query['meta_query'] = array(
     92            array( 'key' => 'my_first_key', 'value' => 'my_amazing_value' ),
     93            array( 'key' => 'my_second_key', 'compare' => 'NOT EXISTS' ),
     94            array( 'key' => 'my_third_key', 'value' => array( ), 'compare' => 'IN' ),
     95        );
     96
     97        $query->parse_query_vars( $the_complex_query );
     98
     99        $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
     100
     101        // We should have 2 joins - one for my_first_key and one for my_second_key
     102        $this->assertEquals( 2, substr_count( $sql['join'], 'INNER JOIN' ) );
     103
     104        // The WHERE should check my_third_key against an unaliased table
     105        $this->assertEquals( 1, substr_count( $sql['where'], "wp_postmeta.meta_key = 'my_third_key'" ) );
     106
     107    }
    82108}
Note: See TracChangeset for help on using the changeset viewer.