WordPress.org

Make WordPress Core

Changeset 1067 in tests


Ignore:
Timestamp:
10/02/2012 06:40:30 PM (6 years ago)
Author:
ryan
Message:

Test post meta BETWEEN and NOT BETWEEN.

File:
1 edited

Legend:

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

    r1066 r1067  
    144144    $this->assertEquals( 0 , count( $posts ) );
    145145    }
     146
     147    function test_meta_between_not_between() {
     148    $post_id = $this->factory->post->create();
     149    add_post_meta( $post_id, 'time', 500 );
     150    $post_id2 = $this->factory->post->create();
     151    add_post_meta( $post_id2, 'time', 1001 );
     152    $post_id3 = $this->factory->post->create();
     153    add_post_meta( $post_id3, 'time', 0 );
     154    $post_id4 = $this->factory->post->create();
     155    add_post_meta( $post_id4, 'time', 1 );
     156    $post_id5 = $this->factory->post->create();
     157    add_post_meta( $post_id5, 'time', 1000 );
     158   
     159    $args = array(
     160        'meta_key' => 'time',
     161        'meta_value' => array( 1, 1000 ),
     162        'meta_type' => 'numeric',
     163        'meta_compare' => 'NOT BETWEEN'
     164        );
     165
     166    $query = new WP_Query( $args );
     167    $this->assertEquals( 2, count ( $query->posts ) );
     168    $posts = wp_list_pluck( $query->posts, 'ID' );
     169    $this->assertEquals( array( $post_id2, $post_id3 ), $posts );
     170   
     171    $args = array(
     172        'meta_key' => 'time',
     173        'meta_value' => array( 1, 1000 ),
     174        'meta_type' => 'numeric',
     175        'meta_compare' => 'BETWEEN'
     176        );
     177
     178    $query = new WP_Query( $args );
     179    $this->assertEquals( 3, count ( $query->posts ) );
     180    $posts = wp_list_pluck( $query->posts, 'ID' );
     181    $this->assertEquals( array( $post_id, $post_id4, $post_id5 ), $posts );
     182    }
    146183}
Note: See TracChangeset for help on using the changeset viewer.