Changeset 1070 in tests
- Timestamp:
- 10/03/2012 12:21:47 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/tests/post/query.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/post/query.php
r1069 r1070 48 48 $post_ids = wp_list_pluck( $posts, 'ID' ); 49 49 $this->assertEquals( array( $post_id, $post_id2, $post_id3, $post_id4 ), $post_ids ); 50 } 51 52 function test_meta_key_and_query() { 53 $post_id = $this->factory->post->create(); 54 add_post_meta( $post_id, 'foo', rand_str() ); 55 add_post_meta( $post_id, 'foo', rand_str() ); 56 $post_id2 = $this->factory->post->create(); 57 add_post_meta( $post_id2, 'bar', 'val2' ); 58 add_post_meta( $post_id2, 'foo', rand_str() ); 59 $post_id3 = $this->factory->post->create(); 60 add_post_meta( $post_id3, 'baz', rand_str() ); 61 $post_id4 = $this->factory->post->create(); 62 add_post_meta( $post_id4, 'froo', rand_str() ); 63 $post_id5 = $this->factory->post->create(); 64 add_post_meta( $post_id5, 'tango', 'val2' ); 65 $post_id6 = $this->factory->post->create(); 66 add_post_meta( $post_id6, 'bar', 'val1' ); 67 add_post_meta( $post_id6, 'foo', rand_str() ); 68 $post_id7 = $this->factory->post->create(); 69 add_post_meta( $post_id7, 'foo', rand_str() ); 70 add_post_meta( $post_id7, 'froo', rand_str() ); 71 add_post_meta( $post_id7, 'baz', rand_str() ); 72 add_post_meta( $post_id7, 'bar', 'val2' ); 73 74 $query = new WP_Query( array( 75 'meta_query' => array( 76 array( 77 'key' => 'foo' 78 ), 79 array( 80 'key' => 'bar', 81 'value' => 'val2' 82 ), 83 array( 84 'key' => 'baz' 85 ), 86 array( 87 'key' => 'froo' 88 ), 89 'relation' => 'AND', 90 ), 91 ) ); 92 93 $posts = $query->get_posts(); 94 $this->assertEquals( 1, count( $posts ) ); 95 96 $post_ids = wp_list_pluck( $posts, 'ID' ); 97 $this->assertEquals( array( $post_id7 ), $post_ids ); 98 99 $query = new WP_Query( array( 100 'meta_query' => array( 101 array( 102 'key' => 'foo' 103 ), 104 array( 105 'key' => 'bar', 106 ), 107 'relation' => 'AND', 108 ), 109 ) ); 110 111 $posts = $query->get_posts(); 112 $this->assertEquals( 3, count( $posts ) ); 113 114 $post_ids = wp_list_pluck( $posts, 'ID' ); 115 $this->assertEquals( array( $post_id2, $post_id6, $post_id7 ), $post_ids ); 50 116 } 51 117
Note: See TracChangeset
for help on using the changeset viewer.