Changeset 29799 for trunk/tests/phpunit/tests/post/query.php
- Timestamp:
- 09/30/2014 09:17:38 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/query.php
r29760 r29799 1 1 <?php 2 2 3 /**4 * @group meta5 */6 3 class Tests_Post_Query extends WP_UnitTestCase { 7 4 function setUp() { … … 9 6 } 10 7 11 function test_meta_key_or_query() { 8 /** 9 * @group meta 10 */ 11 public function test_meta_query_no_key() { 12 $p1 = $this->factory->post->create(); 13 $p2 = $this->factory->post->create(); 14 $p3 = $this->factory->post->create(); 15 16 add_post_meta( $p1, 'foo', 'bar' ); 17 add_post_meta( $p2, 'oof', 'bar' ); 18 add_post_meta( $p3, 'oof', 'baz' ); 19 20 $query = new WP_Query( array( 21 'update_post_meta_cache' => false, 22 'update_post_term_cache' => false, 23 'fields' => 'ids', 24 'meta_query' => array( 25 array( 26 'value' => 'bar', 27 ), 28 ), 29 ) ); 30 31 $expected = array( $p1, $p2 ); 32 $this->assertEqualSets( $expected, $query->posts ); 33 } 34 35 /** 36 * @group meta 37 */ 38 public function test_meta_query_no_value() { 39 $p1 = $this->factory->post->create(); 40 $p2 = $this->factory->post->create(); 41 $p3 = $this->factory->post->create(); 42 43 add_post_meta( $p1, 'foo', 'bar' ); 44 add_post_meta( $p2, 'oof', 'bar' ); 45 add_post_meta( $p3, 'oof', 'baz' ); 46 47 $query = new WP_Query( array( 48 'update_post_meta_cache' => false, 49 'update_post_term_cache' => false, 50 'fields' => 'ids', 51 'meta_query' => array( 52 array( 53 'key' => 'oof', 54 ), 55 ), 56 ) ); 57 58 $expected = array( $p2, $p3 ); 59 $this->assertEqualSets( $expected, $query->posts ); 60 } 61 62 /** 63 * @group meta 64 */ 65 public function test_meta_query_single_query_compare_default() { 66 $p1 = $this->factory->post->create(); 67 $p2 = $this->factory->post->create(); 68 69 add_post_meta( $p1, 'foo', 'bar' ); 70 71 $query = new WP_Query( array( 72 'update_post_meta_cache' => false, 73 'update_post_term_cache' => false, 74 'fields' => 'ids', 75 'meta_query' => array( 76 array( 77 'key' => 'foo', 78 'value' => 'bar', 79 ), 80 ), 81 ) ); 82 83 $expected = array( $p1 ); 84 $this->assertEqualSets( $expected, $query->posts ); 85 } 86 87 /** 88 * @group meta 89 */ 90 public function test_meta_query_single_query_compare_equals() { 91 $p1 = $this->factory->post->create(); 92 $p2 = $this->factory->post->create(); 93 94 add_post_meta( $p1, 'foo', 'bar' ); 95 96 $query = new WP_Query( array( 97 'update_post_meta_cache' => false, 98 'update_post_term_cache' => false, 99 'fields' => 'ids', 100 'meta_query' => array( 101 array( 102 'key' => 'foo', 103 'value' => 'bar', 104 'compare' => '=', 105 ), 106 ), 107 ) ); 108 109 $expected = array( $p1 ); 110 $this->assertEqualSets( $expected, $query->posts ); 111 } 112 113 /** 114 * @group meta 115 */ 116 public function test_meta_query_single_query_compare_not_equals() { 117 $p1 = $this->factory->post->create(); 118 $p2 = $this->factory->post->create(); 119 $p3 = $this->factory->post->create(); 120 121 add_post_meta( $p1, 'foo', 'bar' ); 122 add_post_meta( $p2, 'foo', 'baz' ); 123 124 $query = new WP_Query( array( 125 'update_post_meta_cache' => false, 126 'update_post_term_cache' => false, 127 'fields' => 'ids', 128 'meta_query' => array( 129 array( 130 'key' => 'foo', 131 'value' => 'bar', 132 'compare' => '!=', 133 ), 134 ), 135 ) ); 136 137 $expected = array( $p2 ); 138 $this->assertEqualSets( $expected, $query->posts ); 139 } 140 141 /** 142 * @group meta 143 */ 144 public function test_meta_query_single_query_compare_arithmetic_comparisons() { 145 $p1 = $this->factory->post->create(); 146 $p2 = $this->factory->post->create(); 147 $p3 = $this->factory->post->create(); 148 149 add_post_meta( $p1, 'foo', '1' ); 150 add_post_meta( $p2, 'foo', '2' ); 151 add_post_meta( $p3, 'foo', '3' ); 152 153 // < 154 $query = new WP_Query( array( 155 'update_post_meta_cache' => false, 156 'update_post_term_cache' => false, 157 'fields' => 'ids', 158 'meta_query' => array( 159 array( 160 'key' => 'foo', 161 'value' => 2, 162 'compare' => '<', 163 ), 164 ), 165 ) ); 166 167 $expected = array( $p1 ); 168 $this->assertEqualSets( $expected, $query->posts ); 169 170 // <= 171 $query = new WP_Query( array( 172 'update_post_meta_cache' => false, 173 'update_post_term_cache' => false, 174 'fields' => 'ids', 175 'meta_query' => array( 176 array( 177 'key' => 'foo', 178 'value' => 2, 179 'compare' => '<=', 180 ), 181 ), 182 ) ); 183 184 $expected = array( $p1, $p2 ); 185 $this->assertEqualSets( $expected, $query->posts ); 186 187 // >= 188 $query = new WP_Query( array( 189 'update_post_meta_cache' => false, 190 'update_post_term_cache' => false, 191 'fields' => 'ids', 192 'meta_query' => array( 193 array( 194 'key' => 'foo', 195 'value' => 2, 196 'compare' => '>=', 197 ), 198 ), 199 ) ); 200 201 $expected = array( $p2, $p3 ); 202 $this->assertEqualSets( $expected, $query->posts ); 203 204 // > 205 $query = new WP_Query( array( 206 'update_post_meta_cache' => false, 207 'update_post_term_cache' => false, 208 'fields' => 'ids', 209 'meta_query' => array( 210 array( 211 'key' => 'foo', 212 'value' => 2, 213 'compare' => '>', 214 ), 215 ), 216 ) ); 217 218 $expected = array( $p3 ); 219 $this->assertEqualSets( $expected, $query->posts ); 220 } 221 222 /** 223 * @group meta 224 */ 225 public function test_meta_query_single_query_compare_like() { 226 $p1 = $this->factory->post->create(); 227 $p2 = $this->factory->post->create(); 228 229 add_post_meta( $p1, 'foo', 'bar' ); 230 231 $query = new WP_Query( array( 232 'update_post_meta_cache' => false, 233 'update_post_term_cache' => false, 234 'fields' => 'ids', 235 'meta_query' => array( 236 array( 237 'key' => 'foo', 238 'value' => 'ba', 239 'compare' => 'LIKE', 240 ), 241 ), 242 ) ); 243 244 $expected = array( $p1 ); 245 $this->assertEqualSets( $expected, $query->posts ); 246 } 247 248 /** 249 * @group meta 250 */ 251 public function test_meta_query_single_query_compare_not_like() { 252 $p1 = $this->factory->post->create(); 253 $p2 = $this->factory->post->create(); 254 $p3 = $this->factory->post->create(); 255 256 add_post_meta( $p1, 'foo', 'bar' ); 257 add_post_meta( $p2, 'foo', 'rab' ); 258 259 $query = new WP_Query( array( 260 'update_post_meta_cache' => false, 261 'update_post_term_cache' => false, 262 'fields' => 'ids', 263 'meta_query' => array( 264 array( 265 'key' => 'foo', 266 'value' => 'ba', 267 'compare' => 'NOT LIKE', 268 ), 269 ), 270 ) ); 271 272 $expected = array( $p2 ); 273 $this->assertEqualSets( $expected, $query->posts ); 274 } 275 276 /** 277 * @group meta 278 */ 279 public function test_meta_query_single_query_compare_between_not_between() { 280 $p1 = $this->factory->post->create(); 281 $p2 = $this->factory->post->create(); 282 $p3 = $this->factory->post->create(); 283 284 add_post_meta( $p1, 'foo', '1' ); 285 add_post_meta( $p2, 'foo', '10' ); 286 add_post_meta( $p3, 'foo', '100' ); 287 288 $query = new WP_Query( array( 289 'update_post_meta_cache' => false, 290 'update_post_term_cache' => false, 291 'fields' => 'ids', 292 'meta_query' => array( 293 array( 294 'key' => 'foo', 295 'value' => array( 9, 12 ), 296 'compare' => 'BETWEEN', 297 'type' => 'NUMERIC', 298 ), 299 ), 300 ) ); 301 302 $expected = array( $p2 ); 303 $this->assertEqualSets( $expected, $query->posts ); 304 305 $query = new WP_Query( array( 306 'update_post_meta_cache' => false, 307 'update_post_term_cache' => false, 308 'fields' => 'ids', 309 'meta_query' => array( 310 array( 311 'key' => 'foo', 312 'value' => array( 9, 12 ), 313 'compare' => 'NOT BETWEEN', 314 'type' => 'NUMERIC', 315 ), 316 ), 317 ) ); 318 319 $expected = array( $p1, $p3 ); 320 $this->assertEqualSets( $expected, $query->posts ); 321 } 322 323 /** 324 * @group meta 325 */ 326 public function test_meta_query_single_query_compare_regexp_rlike() { 327 $p1 = $this->factory->post->create(); 328 $p2 = $this->factory->post->create(); 329 330 add_post_meta( $p1, 'foo', 'bar' ); 331 add_post_meta( $p2, 'foo', 'baz' ); 332 333 $query = new WP_Query( array( 334 'update_post_meta_cache' => false, 335 'update_post_term_cache' => false, 336 'fields' => 'ids', 337 'meta_query' => array( 338 array( 339 'key' => 'foo', 340 'value' => 'z$', 341 'compare' => 'REGEXP', 342 ), 343 ), 344 ) ); 345 346 $expected = array( $p2 ); 347 $this->assertEqualSets( $expected, $query->posts ); 348 349 // RLIKE is a synonym for REGEXP. 350 $query = new WP_Query( array( 351 'update_post_meta_cache' => false, 352 'update_post_term_cache' => false, 353 'fields' => 'ids', 354 'meta_query' => array( 355 array( 356 'key' => 'foo', 357 'value' => 'z$', 358 'compare' => 'RLIKE', 359 ), 360 ), 361 ) ); 362 363 $expected = array( $p2 ); 364 $this->assertEqualSets( $expected, $query->posts ); 365 } 366 367 /** 368 * @group meta 369 */ 370 public function test_meta_query_single_query_compare_not_regexp() { 371 $p1 = $this->factory->post->create(); 372 $p2 = $this->factory->post->create(); 373 374 add_post_meta( $p1, 'foo', 'bar' ); 375 add_post_meta( $p2, 'foo', 'baz' ); 376 377 $query = new WP_Query( array( 378 'update_post_meta_cache' => false, 379 'update_post_term_cache' => false, 380 'fields' => 'ids', 381 'meta_query' => array( 382 array( 383 'key' => 'foo', 384 'value' => 'z$', 385 'compare' => 'NOT REGEXP', 386 ), 387 ), 388 ) ); 389 390 $expected = array( $p1 ); 391 $this->assertEqualSets( $expected, $query->posts ); 392 } 393 394 /** 395 * @group meta 396 */ 397 public function test_meta_query_relation_default() { 398 $p1 = $this->factory->post->create(); 399 $p2 = $this->factory->post->create(); 400 $p3 = $this->factory->post->create(); 401 402 add_post_meta( $p1, 'foo', 'foo value 1' ); 403 add_post_meta( $p1, 'bar', 'bar value 1' ); 404 add_post_meta( $p2, 'foo', 'foo value 1' ); 405 add_post_meta( $p2, 'bar', 'bar value 2' ); 406 407 $query = new WP_Query( array( 408 'update_post_meta_cache' => false, 409 'update_post_term_cache' => false, 410 'fields' => 'ids', 411 'meta_query' => array( 412 array( 413 'key' => 'foo', 414 'value' => 'foo value 1', 415 ), 416 array( 417 'key' => 'bar', 418 'value' => 'bar value 1', 419 ), 420 ), 421 ) ); 422 423 $expected = array( $p1 ); 424 $this->assertEquals( $expected, $query->posts ); 425 } 426 427 /** 428 * @group meta 429 */ 430 public function test_meta_query_relation_or() { 12 431 $post_id = $this->factory->post->create(); 13 432 add_post_meta( $post_id, 'foo', rand_str() ); … … 25 444 26 445 $query = new WP_Query( array( 446 'update_post_meta_cache' => false, 447 'update_post_term_cache' => false, 448 'fields' => 'ids', 27 449 'meta_query' => array( 28 450 array( … … 43 465 ) ); 44 466 45 $posts = $query->get_posts(); 46 $this->assertEquals( 4, count( $posts ) ); 47 foreach ( $posts as $post ) { 48 $this->assertInstanceOf( 'WP_Post', $post ); 49 $this->assertEquals( 'raw', $post->filter ); 50 } 51 52 $post_ids = wp_list_pluck( $posts, 'ID' ); 53 $this->assertEqualSets( array( $post_id, $post_id2, $post_id3, $post_id4 ), $post_ids ); 54 } 55 56 function test_meta_key_and_query() { 467 $expected = array( $post_id, $post_id2, $post_id3, $post_id4 ); 468 $this->assertEqualSets( $expected, $query->posts ); 469 } 470 471 /** 472 * @group meta 473 */ 474 public function test_meta_query_relation_and() { 57 475 $post_id = $this->factory->post->create(); 58 476 add_post_meta( $post_id, 'foo', rand_str() ); … … 93 511 'relation' => 'AND', 94 512 ), 95 ) ); 96 97 $posts = $query->get_posts(); 98 $this->assertEquals( 1, count( $posts ) ); 99 foreach ( $posts as $post ) { 100 $this->assertInstanceOf( 'WP_Post', $post ); 101 $this->assertEquals( 'raw', $post->filter ); 102 } 103 104 $post_ids = wp_list_pluck( $posts, 'ID' ); 105 $this->assertEquals( array( $post_id7 ), $post_ids ); 513 'update_post_meta_cache' => false, 514 'update_post_term_cache' => false, 515 'fields' => 'ids', 516 ) ); 517 518 $expected = array( $post_id7 ); 519 $this->assertEqualSets( $expected, $query->posts ); 106 520 107 521 $query = new WP_Query( array( … … 115 529 'relation' => 'AND', 116 530 ), 117 ) ); 118 119 $posts = $query->get_posts(); 120 $this->assertEquals( 3, count( $posts ) ); 121 foreach ( $posts as $post ) { 122 $this->assertInstanceOf( 'WP_Post', $post ); 123 $this->assertEquals( 'raw', $post->filter ); 124 } 125 126 $post_ids = wp_list_pluck( $posts, 'ID' ); 127 $this->assertEqualSets( array( $post_id2, $post_id6, $post_id7 ), $post_ids ); 531 'update_post_meta_cache' => false, 532 'update_post_term_cache' => false, 533 'fields' => 'ids', 534 ) ); 535 536 $expected = array( $post_id2, $post_id6, $post_id7 ); 537 $this->assertEqualSets( $expected, $query->posts ); 128 538 } 129 539 130 540 /** 131 541 * @ticket 18158 132 */ 133 function test_meta_key_not_exists() { 542 * @group meta 543 */ 544 public function test_meta_query_compare_not_exists() { 134 545 $post_id = $this->factory->post->create(); 135 546 add_post_meta( $post_id, 'foo', rand_str() ); … … 145 556 $query = new WP_Query( array( 146 557 'meta_query' => array( 147 array(148 'key' => 'foo',149 'compare' => 'NOT EXISTS',150 ),151 ), 152 ) );153 154 $posts = $query->get_posts();155 $this->assertEquals( 3, count( $posts) );156 foreach ( $posts as $post ) { 157 $this->assertInstanceOf( 'WP_Post', $post);158 $this->assertEquals( 'raw', $post->filter);159 } 160 161 $query = new WP_Query(array(162 'meta_query' =>array(163 array(164 'key' => 'foo',165 'compare' => 'NOT EXISTS',166 ),167 array(168 'key' => 'bar',169 'compare' => 'NOT EXISTS',170 ), 171 ),172 ) );173 174 $posts = $query->get_posts();175 $this->assertEquals( 1, count( $posts ) ); 176 foreach ( $posts as $post ) {177 $this->assertInstanceOf( 'WP_Post', $post);178 $this->assertEquals( 'raw', $post->filter ); 179 }180 181 $query = new WP_Query(array(182 'meta_query' => array(183 array(184 'key' => 'foo',185 'compare' => 'NOT EXISTS',186 ),187 array(188 'key' => 'bar',189 'compare' => 'NOT EXISTS',190 ),191 array(192 'key' => 'baz',193 'compare' => 'NOT EXISTS',194 ),195 )196 ) );197 198 $posts = $query->get_posts(); 199 $this->assertEquals( 0, count( $ posts ) );558 array( 559 'key' => 'foo', 560 'compare' => 'NOT EXISTS', 561 ), 562 ), 563 'update_post_meta_cache' => false, 564 'update_post_term_cache' => false, 565 'fields' => 'ids', 566 ) ); 567 568 $expected = array( $post_id2, $post_id3, $post_id4 ); 569 $this->assertEqualSets( $expected, $query->posts ); 570 571 $query = new WP_Query( array( 572 'meta_query' => array( 573 array( 574 'key' => 'foo', 575 'compare' => 'NOT EXISTS', 576 ), 577 array( 578 'key' => 'bar', 579 'compare' => 'NOT EXISTS', 580 ), 581 ), 582 'update_post_meta_cache' => false, 583 'update_post_term_cache' => false, 584 'fields' => 'ids', 585 ) ); 586 587 $expected = array( $post_id4 ); 588 $this->assertEquals( $expected, $query->posts ); 589 590 $query = new WP_Query( array( 591 'meta_query' => array( 592 array( 593 'key' => 'foo', 594 'compare' => 'NOT EXISTS', 595 ), 596 array( 597 'key' => 'bar', 598 'compare' => 'NOT EXISTS', 599 ), 600 array( 601 'key' => 'baz', 602 'compare' => 'NOT EXISTS', 603 ), 604 ), 605 'update_post_meta_cache' => false, 606 'update_post_term_cache' => false, 607 'fields' => 'ids', 608 ) ); 609 610 $this->assertEquals( 0, count( $query->posts ) ); 200 611 } 201 612 202 613 /** 203 614 * @ticket 23033 204 */ 205 function test_meta_query_decimal_results() { 615 * @group meta 616 */ 617 public function test_meta_query_decimal_results() { 206 618 $post_1 = $this->factory->post->create(); 207 619 $post_2 = $this->factory->post->create(); … … 216 628 $query = new WP_Query( array( 217 629 'meta_query' => array( 218 array( 219 'key' => 'decimal_value', 220 'value' => '.300', 221 'compare' => '=', 222 'type' => 'DECIMAL(10,2)' 223 ) 224 ), 225 ) ); 226 $this->assertEqualSets( array( $post_3 ), wp_list_pluck( $query->posts, 'ID' ) ); 227 228 $query = new WP_Query( array( 229 'meta_query' => array( 230 array( 231 'key' => 'decimal_value', 232 'value' => '0.35', 233 'compare' => '>', 234 'type' => 'DECIMAL(10,2)' 235 ) 236 ), 237 ) ); 238 $this->assertEqualSets( array( $post_4 ), wp_list_pluck( $query->posts, 'ID' ) ); 239 240 $query = new WP_Query( array( 241 'meta_query' => array( 242 array( 243 'key' => 'decimal_value', 244 'value' => '0.3', 245 'compare' => '>=', 246 'type' => 'DECIMAL(10,2)' 247 ) 248 ), 249 ) ); 250 $this->assertEqualSets( array( $post_3, $post_4 ), wp_list_pluck( $query->posts, 'ID' ) ); 251 252 $query = new WP_Query( array( 253 'meta_query' => array( 254 array( 255 'key' => 'decimal_value', 256 'value' => '0', 257 'compare' => '<', 258 'type' => 'DECIMAL(10,2)' 259 ) 260 ), 261 ) ); 262 $this->assertEqualSets( array( $post_1 ), wp_list_pluck( $query->posts, 'ID' ) ); 263 264 $query = new WP_Query( array( 265 'meta_query' => array( 266 array( 267 'key' => 'decimal_value', 268 'value' => '0.3', 269 'compare' => '<=', 270 'type' => 'DECIMAL(10,2)' 271 ) 272 ), 273 274 ) ); 275 $this->assertEqualSets( array( $post_1, $post_2, $post_3 ), wp_list_pluck( $query->posts, 'ID' ) ); 276 277 $query = new WP_Query( array( 278 'meta_query' => array( 279 array( 280 'key' => 'decimal_value', 281 'value' => array( 0.23409845, .31 ), 282 'compare' => 'BETWEEN', 283 'type' => 'DECIMAL(10, 10)' 284 ) 285 ), 286 ) ); 287 $this->assertEqualSets( array( $post_3 ), wp_list_pluck( $query->posts, 'ID' ) ); 288 289 $query = new WP_Query( array( 290 'meta_query' => array( 291 array( 292 'key' => 'decimal_value', 293 'value' => array( 0.23409845, .31 ), 294 'compare' => 'NOT BETWEEN', 295 'type' => 'DECIMAL(10,10)' 296 ) 297 ), 298 ) ); 299 $this->assertEqualSets( array( $post_1, $post_2, $post_4 ), wp_list_pluck( $query->posts, 'ID' ) ); 300 301 $query = new WP_Query( array( 302 'meta_query' => array( 303 array( 304 'key' => 'decimal_value', 305 'value' => '.3', 306 'compare' => 'LIKE', 307 'type' => 'DECIMAL(10,2)' 308 ) 309 ), 310 ) ); 311 $this->assertEqualSets( array( $post_1, $post_3 ), wp_list_pluck( $query->posts, 'ID' ) ); 312 313 $query = new WP_Query( array( 314 'meta_query' => array( 315 array( 316 'key' => 'decimal_value', 317 'value' => '.3', 318 'compare' => 'NOT LIKE', 319 'type' => 'DECIMAL(10,2)' 320 ) 321 ), 322 ) ); 323 $this->assertEqualSets( array( $post_2, $post_4 ), wp_list_pluck( $query->posts, 'ID' ) ); 630 array( 631 'key' => 'decimal_value', 632 'value' => '.300', 633 'compare' => '=', 634 'type' => 'DECIMAL(10,2)' 635 ) 636 ), 637 'update_post_meta_cache' => false, 638 'update_post_term_cache' => false, 639 'fields' => 'ids', 640 ) ); 641 $this->assertEqualSets( array( $post_3 ), $query->posts ); 642 643 $query = new WP_Query( array( 644 'meta_query' => array( 645 array( 646 'key' => 'decimal_value', 647 'value' => '0.35', 648 'compare' => '>', 649 'type' => 'DECIMAL(10,2)' 650 ) 651 ), 652 'update_post_meta_cache' => false, 653 'update_post_term_cache' => false, 654 'fields' => 'ids', 655 ) ); 656 $this->assertEqualSets( array( $post_4 ), $query->posts ); 657 658 $query = new WP_Query( array( 659 'meta_query' => array( 660 array( 661 'key' => 'decimal_value', 662 'value' => '0.3', 663 'compare' => '>=', 664 'type' => 'DECIMAL(10,2)' 665 ) 666 ), 667 'update_post_meta_cache' => false, 668 'update_post_term_cache' => false, 669 'fields' => 'ids', 670 ) ); 671 $this->assertEqualSets( array( $post_3, $post_4 ), $query->posts ); 672 673 $query = new WP_Query( array( 674 'meta_query' => array( 675 array( 676 'key' => 'decimal_value', 677 'value' => '0', 678 'compare' => '<', 679 'type' => 'DECIMAL(10,2)' 680 ) 681 ), 682 'update_post_meta_cache' => false, 683 'update_post_term_cache' => false, 684 'fields' => 'ids', 685 ) ); 686 $this->assertEqualSets( array( $post_1 ), $query->posts, 'ID' ); 687 688 $query = new WP_Query( array( 689 'meta_query' => array( 690 array( 691 'key' => 'decimal_value', 692 'value' => '0.3', 693 'compare' => '<=', 694 'type' => 'DECIMAL(10,2)' 695 ) 696 ), 697 'update_post_meta_cache' => false, 698 'update_post_term_cache' => false, 699 'fields' => 'ids', 700 ) ); 701 $this->assertEqualSets( array( $post_1, $post_2, $post_3 ), $query->posts ); 702 703 $query = new WP_Query( array( 704 'meta_query' => array( 705 array( 706 'key' => 'decimal_value', 707 'value' => array( 0.23409845, .31 ), 708 'compare' => 'BETWEEN', 709 'type' => 'DECIMAL(10, 10)' 710 ) 711 ), 712 'update_post_meta_cache' => false, 713 'update_post_term_cache' => false, 714 'fields' => 'ids', 715 ) ); 716 $this->assertEqualSets( array( $post_3 ), $query->posts ); 717 718 $query = new WP_Query( array( 719 'meta_query' => array( 720 array( 721 'key' => 'decimal_value', 722 'value' => array( 0.23409845, .31 ), 723 'compare' => 'NOT BETWEEN', 724 'type' => 'DECIMAL(10,10)' 725 ) 726 ), 727 'update_post_meta_cache' => false, 728 'update_post_term_cache' => false, 729 'fields' => 'ids', 730 ) ); 731 $this->assertEqualSets( array( $post_1, $post_2, $post_4 ), $query->posts ); 732 733 $query = new WP_Query( array( 734 'meta_query' => array( 735 array( 736 'key' => 'decimal_value', 737 'value' => '.3', 738 'compare' => 'LIKE', 739 'type' => 'DECIMAL(10,2)' 740 ) 741 ), 742 'update_post_meta_cache' => false, 743 'update_post_term_cache' => false, 744 'fields' => 'ids', 745 ) ); 746 $this->assertEqualSets( array( $post_1, $post_3 ), $query->posts ); 747 748 $query = new WP_Query( array( 749 'meta_query' => array( 750 array( 751 'key' => 'decimal_value', 752 'value' => '.3', 753 'compare' => 'NOT LIKE', 754 'type' => 'DECIMAL(10,2)' 755 ) 756 ), 757 'update_post_meta_cache' => false, 758 'update_post_term_cache' => false, 759 'fields' => 'ids', 760 ) ); 761 $this->assertEqualSets( array( $post_2, $post_4 ), $query->posts ); 324 762 325 763 $query = new WP_Query( array( … … 327 765 'order' => 'DESC', 328 766 'meta_key' => 'decimal_value', 329 'meta_type' => 'DECIMAL(10, 2)' 330 ) ); 331 $this->assertEqualSets( array( $post_4, $post_3, $post_2, $post_1 ), wp_list_pluck( $query->posts, 'ID' ) ); 332 767 'meta_type' => 'DECIMAL(10, 2)', 768 'update_post_meta_cache' => false, 769 'update_post_term_cache' => false, 770 'fields' => 'ids', 771 ) ); 772 $this->assertEqualSets( array( $post_4, $post_3, $post_2, $post_1 ), $query->posts ); 333 773 } 334 774
Note: See TracChangeset
for help on using the changeset viewer.