Changeset 42343 for trunk/tests/phpunit/tests/meta/query.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/meta/query.php
r37595 r42343 21 21 public function test_set_relation() { 22 22 23 $query = new WP_Meta_Query( array( array( 'key' => 'abc' ), 'relation' => 'AND' ) ); 23 $query = new WP_Meta_Query( 24 array( 25 array( 'key' => 'abc' ), 26 'relation' => 'AND', 27 ) 28 ); 24 29 25 30 $this->assertEquals( 'AND', $query->relation ); 26 31 27 $query = new WP_Meta_Query( array( array( 'key' => 'abc' ), 'relation' => 'OR' ) ); 32 $query = new WP_Meta_Query( 33 array( 34 array( 'key' => 'abc' ), 35 'relation' => 'OR', 36 ) 37 ); 28 38 29 39 $this->assertEquals( 'OR', $query->relation ); … … 34 44 */ 35 45 public function test_invalid_query_clauses() { 36 $query = new WP_Meta_Query( array( 37 'foo', // empty string 38 5, // int 39 false, // bool 40 array(), 41 ) ); 46 $query = new WP_Meta_Query( 47 array( 48 'foo', // empty string 49 5, // int 50 false, // bool 51 array(), 52 ) 53 ); 42 54 43 55 $this->assertSame( array(), $query->queries ); … … 53 65 global $wpdb; 54 66 55 $query = new WP_Meta_Query( array( 56 array( 'key' => 'abc' ), 57 array( 'key' => 'def' ), 58 'relation' => 'OR' 59 ) ); 67 $query = new WP_Meta_Query( 68 array( 69 array( 'key' => 'abc' ), 70 array( 'key' => 'def' ), 71 'relation' => 'OR', 72 ) 73 ); 60 74 61 75 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID' ); … … 65 79 // also check mixing key and key => value 66 80 67 $query = new WP_Meta_Query( array( 68 array( 'key' => 'abc' ), 69 array( 'key' => 'def' ), 70 array( 'key' => 'ghi', 'value' => 'abc' ), 71 'relation' => 'OR' 72 ) ); 81 $query = new WP_Meta_Query( 82 array( 83 array( 'key' => 'abc' ), 84 array( 'key' => 'def' ), 85 array( 86 'key' => 'ghi', 87 'value' => 'abc', 88 ), 89 'relation' => 'OR', 90 ) 91 ); 73 92 74 93 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID' ); … … 82 101 public function test_parse_query_vars_simple_query_index_0() { 83 102 $qv = array( 84 'meta_query' => array(85 array( 86 'key' => 'foo1',103 'meta_query' => array( 104 array( 105 'key' => 'foo1', 87 106 'compare' => 'baz1', 88 'value' => 'bar1',89 ), 90 ), 91 'meta_key' => 'foo',107 'value' => 'bar1', 108 ), 109 ), 110 'meta_key' => 'foo', 92 111 'meta_compare' => 'bar', 93 'meta_value' => 'baz',112 'meta_value' => 'baz', 94 113 ); 95 114 … … 98 117 99 118 $expected0 = array( 100 'key' => 'foo',119 'key' => 'foo', 101 120 'compare' => 'bar', 102 'value' => 'baz',121 'value' => 'baz', 103 122 ); 104 123 $this->assertEquals( $expected0, $query->queries[0] ); … … 107 126 'relation' => 'OR', 108 127 array( 109 'key' => 'foo1',128 'key' => 'foo1', 110 129 'compare' => 'baz1', 111 'value' => 'bar1',130 'value' => 'bar1', 112 131 ), 113 132 ); … … 120 139 public function test_parse_query_vars_with_no_meta_value() { 121 140 $qv = array( 122 'meta_key' => 'foo',123 'meta_type' => 'bar',141 'meta_key' => 'foo', 142 'meta_type' => 'bar', 124 143 'meta_compare' => '=', 125 144 ); … … 136 155 public function test_parse_query_vars_with_default_meta_compare() { 137 156 $qv = array( 138 'meta_key' => 'foo',139 'meta_type' => 'bar',157 'meta_key' => 'foo', 158 'meta_type' => 'bar', 140 159 'meta_compare' => '=', 141 'meta_value' => '',160 'meta_value' => '', 142 161 ); 143 162 … … 163 182 ), 164 183 ); 165 $query->parse_query_vars( array( 166 'meta_key' => 'abc', 167 ) ); 184 $query->parse_query_vars( 185 array( 186 'meta_key' => 'abc', 187 ) 188 ); 168 189 $this->assertEquals( $expected, $query->queries ); 169 190 … … 172 193 'relation' => 'OR', 173 194 array( 174 'key' => 'abc',195 'key' => 'abc', 175 196 'value' => 'def', 176 197 ), 177 198 ); 178 $query->parse_query_vars( array( 179 'meta_key' => 'abc', 180 'meta_value' => 'def', 181 ) ); 199 $query->parse_query_vars( 200 array( 201 'meta_key' => 'abc', 202 'meta_value' => 'def', 203 ) 204 ); 182 205 $this->assertEquals( $expected, $query->queries ); 183 206 … … 186 209 'relation' => 'OR', 187 210 array( 188 'key' => 'abc',211 'key' => 'abc', 189 212 'compare' => '=>', 190 213 ), 191 214 ); 192 $query->parse_query_vars( array( 193 'meta_key' => 'abc', 194 'meta_compare' => '=>', 195 ) ); 215 $query->parse_query_vars( 216 array( 217 'meta_key' => 'abc', 218 'meta_compare' => '=>', 219 ) 220 ); 196 221 $this->assertEquals( $expected, $query->queries ); 197 222 } … … 235 260 'relation' => 'OR', 236 261 array( 237 'key' => 'foo',262 'key' => 'foo', 238 263 'value' => 'bar', 239 264 ), 240 265 ); 241 266 242 $q = new WP_Meta_Query(); 243 $found = $q->sanitize_query( array( 244 array( 245 'key' => 'foo', 246 'value' => 'bar', 247 ), 248 ) ); 267 $q = new WP_Meta_Query(); 268 $found = $q->sanitize_query( 269 array( 270 array( 271 'key' => 'foo', 272 'value' => 'bar', 273 ), 274 ) 275 ); 249 276 250 277 $this->assertEquals( $expected, $found ); … … 255 282 'relation' => 'AND', 256 283 array( 257 'key' => 'foo',284 'key' => 'foo', 258 285 'value' => 'bar', 259 286 ), 260 287 array( 261 'key' => 'foo2',288 'key' => 'foo2', 262 289 'value' => 'bar2', 263 290 ), 264 291 ); 265 292 266 $q = new WP_Meta_Query(); 267 $found = $q->sanitize_query( array( 268 array( 269 'key' => 'foo', 270 'value' => 'bar', 271 ), 272 array( 273 'key' => 'foo2', 274 'value' => 'bar2', 275 ), 276 ) ); 293 $q = new WP_Meta_Query(); 294 $found = $q->sanitize_query( 295 array( 296 array( 297 'key' => 'foo', 298 'value' => 'bar', 299 ), 300 array( 301 'key' => 'foo2', 302 'value' => 'bar2', 303 ), 304 ) 305 ); 277 306 278 307 $this->assertEquals( $expected, $found ); … … 283 312 'relation' => 'OR', 284 313 array( 285 'key' => 'foo',314 'key' => 'foo', 286 315 'value' => 'bar', 287 316 ), 288 317 array( 289 'key' => 'foo2',318 'key' => 'foo2', 290 319 'value' => 'bar2', 291 320 ), 292 321 ); 293 322 294 $q = new WP_Meta_Query(); 295 $found = $q->sanitize_query( array( 296 'relation' => 'OR', 297 array( 298 'key' => 'foo', 299 'value' => 'bar', 300 ), 301 array( 302 'key' => 'foo2', 303 'value' => 'bar2', 304 ), 305 ) ); 323 $q = new WP_Meta_Query(); 324 $found = $q->sanitize_query( 325 array( 326 'relation' => 'OR', 327 array( 328 'key' => 'foo', 329 'value' => 'bar', 330 ), 331 array( 332 'key' => 'foo2', 333 'value' => 'bar2', 334 ), 335 ) 336 ); 306 337 307 338 $this->assertEquals( $expected, $found ); … … 312 343 'relation' => 'OR', 313 344 array( 314 'key' => 'foo',345 'key' => 'foo', 315 346 'value' => 'bar', 316 347 ), 317 348 array( 318 'key' => 'foo2',349 'key' => 'foo2', 319 350 'value' => 'bar2', 320 351 ), 321 352 ); 322 353 323 $q = new WP_Meta_Query(); 324 $found = $q->sanitize_query( array( 325 'relation' => 'or', 326 array( 327 'key' => 'foo', 328 'value' => 'bar', 329 ), 330 array( 331 'key' => 'foo2', 332 'value' => 'bar2', 333 ), 334 ) ); 354 $q = new WP_Meta_Query(); 355 $found = $q->sanitize_query( 356 array( 357 'relation' => 'or', 358 array( 359 'key' => 'foo', 360 'value' => 'bar', 361 ), 362 array( 363 'key' => 'foo2', 364 'value' => 'bar2', 365 ), 366 ) 367 ); 335 368 336 369 $this->assertEquals( $expected, $found ); … … 341 374 'relation' => 'AND', 342 375 array( 343 'key' => 'foo',376 'key' => 'foo', 344 377 'value' => 'bar', 345 378 ), 346 379 array( 347 'key' => 'foo2',380 'key' => 'foo2', 348 381 'value' => 'bar2', 349 382 ), 350 383 ); 351 384 352 $q = new WP_Meta_Query(); 353 $found = $q->sanitize_query( array( 354 'relation' => 'FOO', 355 array( 356 'key' => 'foo', 357 'value' => 'bar', 358 ), 359 array( 360 'key' => 'foo2', 361 'value' => 'bar2', 362 ), 363 ) ); 385 $q = new WP_Meta_Query(); 386 $found = $q->sanitize_query( 387 array( 388 'relation' => 'FOO', 389 array( 390 'key' => 'foo', 391 'value' => 'bar', 392 ), 393 array( 394 'key' => 'foo2', 395 'value' => 'bar2', 396 ), 397 ) 398 ); 364 399 365 400 $this->assertEquals( $expected, $found ); … … 372 407 'relation' => 'AND', 373 408 array( 374 'key' => 'foo',375 'value' => 'bar', 376 ), 377 array( 378 'key' => 'foo2',409 'key' => 'foo', 410 'value' => 'bar', 411 ), 412 array( 413 'key' => 'foo2', 379 414 'value' => 'bar2', 380 415 ), 381 ) 382 ); 383 384 $q = new WP_Meta_Query(); 385 $found = $q->sanitize_query( array( 386 array( 387 array( 388 'key' => 'foo', 389 'value' => 'bar', 390 ), 391 array( 392 'key' => 'foo2', 393 'value' => 'bar2', 394 ), 395 ), 396 ) ); 416 ), 417 ); 418 419 $q = new WP_Meta_Query(); 420 $found = $q->sanitize_query( 421 array( 422 array( 423 array( 424 'key' => 'foo', 425 'value' => 'bar', 426 ), 427 array( 428 'key' => 'foo2', 429 'value' => 'bar2', 430 ), 431 ), 432 ) 433 ); 397 434 398 435 $this->assertEquals( $expected, $found ); … … 405 442 'relation' => 'AND', 406 443 array( 407 'key' => 'foo',408 'value' => 'bar', 409 ), 410 array( 411 'key' => 'foo2',444 'key' => 'foo', 445 'value' => 'bar', 446 ), 447 array( 448 'key' => 'foo2', 412 449 'value' => 'bar2', 413 450 ), … … 416 453 'relation' => 'AND', 417 454 array( 418 'key' => 'foo3',455 'key' => 'foo3', 419 456 'value' => 'bar3', 420 457 ), 421 458 array( 422 'key' => 'foo4',459 'key' => 'foo4', 423 460 'value' => 'bar4', 424 461 ), … … 426 463 ); 427 464 428 $q = new WP_Meta_Query(); 429 $found = $q->sanitize_query( array( 430 'relation' => 'OR', 431 array( 432 array( 433 'key' => 'foo', 434 'value' => 'bar', 435 ), 436 array( 437 'key' => 'foo2', 438 'value' => 'bar2', 439 ), 440 ), 441 array( 442 array( 443 'key' => 'foo3', 444 'value' => 'bar3', 445 ), 446 array( 447 'key' => 'foo4', 448 'value' => 'bar4', 449 ), 450 ), 451 ) ); 465 $q = new WP_Meta_Query(); 466 $found = $q->sanitize_query( 467 array( 468 'relation' => 'OR', 469 array( 470 array( 471 'key' => 'foo', 472 'value' => 'bar', 473 ), 474 array( 475 'key' => 'foo2', 476 'value' => 'bar2', 477 ), 478 ), 479 array( 480 array( 481 'key' => 'foo3', 482 'value' => 'bar3', 483 ), 484 array( 485 'key' => 'foo4', 486 'value' => 'bar4', 487 ), 488 ), 489 ) 490 ); 452 491 453 492 $this->assertEquals( $expected, $found ); … … 471 510 472 511 $the_complex_query['meta_query'] = array( 473 array( 'key' => 'my_first_key', 'value' => 'my_amazing_value' ), 474 array( 'key' => 'my_second_key', 'compare' => 'NOT EXISTS' ), 475 array( 'key' => 'my_third_key', 'value' => array( ), 'compare' => 'IN' ), 512 array( 513 'key' => 'my_first_key', 514 'value' => 'my_amazing_value', 515 ), 516 array( 517 'key' => 'my_second_key', 518 'compare' => 'NOT EXISTS', 519 ), 520 array( 521 'key' => 'my_third_key', 522 'value' => array(), 523 'compare' => 'IN', 524 ), 476 525 ); 477 526 … … 489 538 global $wpdb; 490 539 491 $query = new WP_Meta_Query( array( 492 array( 'key' => 'abc', 'value' => null, 'compare' => '=' ) 493 ) ); 494 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 540 $query = new WP_Meta_Query( 541 array( 542 array( 543 'key' => 'abc', 544 'value' => null, 545 'compare' => '=', 546 ), 547 ) 548 ); 549 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 495 550 496 551 $this->assertEquals( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value = ''" ) ); … … 504 559 global $wpdb; 505 560 506 $query1 = new WP_Meta_Query( array( 507 'relation' => 'OR', 508 509 // Empty 'compare' 510 array( 511 'key' => 'foo', 512 ), 513 514 // Non-empty 'compare' 515 array( 516 'key' => 'bar', 517 'compare' => '<', 518 ), 519 520 // NOT EXISTS 521 array( 522 'key' => 'baz', 523 'compare' => 'NOT EXISTS', 524 ), 525 526 // Has a value 527 array( 528 'key' => 'barry', 529 'value' => 'foo', 530 ), 531 532 // Has no key 533 array( 534 'value' => 'bar', 535 ), 536 ) ); 561 $query1 = new WP_Meta_Query( 562 array( 563 'relation' => 'OR', 564 565 // Empty 'compare' 566 array( 567 'key' => 'foo', 568 ), 569 570 // Non-empty 'compare' 571 array( 572 'key' => 'bar', 573 'compare' => '<', 574 ), 575 576 // NOT EXISTS 577 array( 578 'key' => 'baz', 579 'compare' => 'NOT EXISTS', 580 ), 581 582 // Has a value 583 array( 584 'key' => 'barry', 585 'value' => 'foo', 586 ), 587 588 // Has no key 589 array( 590 'value' => 'bar', 591 ), 592 ) 593 ); 537 594 538 595 $sql = $query1->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 546 603 547 604 // 'AND' queries don't have key-only queries 548 $query2 = new WP_Meta_Query( array( 549 'relation' => 'AND', 550 551 // Empty 'compare' 552 array( 553 'key' => 'foo', 554 ), 555 556 // Non-empty 'compare' 557 array( 558 'key' => 'bar', 559 'compare' => '<', 560 ), 561 ) ); 605 $query2 = new WP_Meta_Query( 606 array( 607 'relation' => 'AND', 608 609 // Empty 'compare' 610 array( 611 'key' => 'foo', 612 ), 613 614 // Non-empty 'compare' 615 array( 616 'key' => 'bar', 617 'compare' => '<', 618 ), 619 ) 620 ); 562 621 563 622 $sql = $query2->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 574 633 global $wpdb; 575 634 576 $query = new WP_Meta_Query( array( 577 array( 578 'key' => ' foo ', 579 ), 580 array( 581 'key' => ' bar ', 582 'value' => 'value', 583 ), 584 ) ); 635 $query = new WP_Meta_Query( 636 array( 637 array( 638 'key' => ' foo ', 639 ), 640 array( 641 'key' => ' bar ', 642 'value' => 'value', 643 ), 644 ) 645 ); 585 646 586 647 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 593 654 global $wpdb; 594 655 595 $query = new WP_Meta_Query( array( 596 array( 597 'key' => 'foo', 598 'value' => null, 599 ), 600 ) ); 656 $query = new WP_Meta_Query( 657 array( 658 array( 659 'key' => 'foo', 660 'value' => null, 661 ), 662 ) 663 ); 601 664 602 665 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 608 671 global $wpdb; 609 672 610 $query = new WP_Meta_Query( array( 611 array( 612 'key' => 'foo', 613 'value' => 'bar', 614 'compare' => 'regExp', 615 ), 616 ) ); 617 618 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 619 620 $this->assertSame( 1, substr_count( $sql['where'], "REGEXP" ) ); 673 $query = new WP_Meta_Query( 674 array( 675 array( 676 'key' => 'foo', 677 'value' => 'bar', 678 'compare' => 'regExp', 679 ), 680 ) 681 ); 682 683 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 684 685 $this->assertSame( 1, substr_count( $sql['where'], 'REGEXP' ) ); 621 686 } 622 687 … … 624 689 global $wpdb; 625 690 626 $query = new WP_Meta_Query( array( 627 array( 628 'key' => 'foo', 629 'value' => array( 'bar', 'baz' ), 630 ), 631 ) ); 691 $query = new WP_Meta_Query( 692 array( 693 array( 694 'key' => 'foo', 695 'value' => array( 'bar', 'baz' ), 696 ), 697 ) 698 ); 632 699 633 700 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 639 706 global $wpdb; 640 707 641 $query = new WP_Meta_Query( array( 642 array( 643 'key' => 'foo', 644 'value' => 'bar', 645 ), 646 ) ); 708 $query = new WP_Meta_Query( 709 array( 710 array( 711 'key' => 'foo', 712 'value' => 'bar', 713 ), 714 ) 715 ); 647 716 648 717 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 654 723 global $wpdb; 655 724 656 $query = new WP_Meta_Query( array( 657 array( 658 'key' => 'foo', 659 'value' => 'bar', 660 'compare' => 'INVALID COMPARE', 661 ), 662 ) ); 725 $query = new WP_Meta_Query( 726 array( 727 array( 728 'key' => 'foo', 729 'value' => 'bar', 730 'compare' => 'INVALID COMPARE', 731 ), 732 ) 733 ); 663 734 664 735 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 673 744 global $wpdb; 674 745 675 $query = new WP_Meta_Query( array( 676 array( 677 'key' => 'foo', 678 'value' => 'bar', 679 ), 680 array(), 681 ) ); 746 $query = new WP_Meta_Query( 747 array( 748 array( 749 'key' => 'foo', 750 'value' => 'bar', 751 ), 752 array(), 753 ) 754 ); 682 755 683 756 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 684 757 685 758 // There should be no JOIN against an aliased table. 686 $this->assertSame( 0, substr_count( $sql['join'], "AS mt") );759 $this->assertSame( 0, substr_count( $sql['join'], 'AS mt' ) ); 687 760 } 688 761 … … 691 764 692 765 // Single value. 693 $query = new WP_Meta_Query( array( 694 array( 695 'key' => 'foo', 696 'compare' => 'IN', 697 'value' => 'bar', 698 ), 699 ) ); 766 $query = new WP_Meta_Query( 767 array( 768 array( 769 'key' => 'foo', 770 'compare' => 'IN', 771 'value' => 'bar', 772 ), 773 ) 774 ); 700 775 701 776 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 704 779 705 780 // Multiple values, no spaces. 706 $query = new WP_Meta_Query( array( 707 array( 708 'key' => 'foo', 709 'compare' => 'IN', 710 'value' => 'bar,baz', 711 ), 712 ) ); 781 $query = new WP_Meta_Query( 782 array( 783 array( 784 'key' => 'foo', 785 'compare' => 'IN', 786 'value' => 'bar,baz', 787 ), 788 ) 789 ); 713 790 714 791 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 717 794 718 795 // Multiple values, spaces. 719 $query = new WP_Meta_Query( array( 720 array( 721 'key' => 'foo', 722 'compare' => 'IN', 723 'value' => 'bar,baz, barry', 724 ), 725 ) ); 796 $query = new WP_Meta_Query( 797 array( 798 array( 799 'key' => 'foo', 800 'compare' => 'IN', 801 'value' => 'bar,baz, barry', 802 ), 803 ) 804 ); 726 805 727 806 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 733 812 global $wpdb; 734 813 735 $query = new WP_Meta_Query( array( 736 array( 737 'key' => 'foo', 738 'compare' => 'IN', 739 'value' => array( 'bar', 'baz' ), 740 ), 741 ) ); 814 $query = new WP_Meta_Query( 815 array( 816 array( 817 'key' => 'foo', 818 'compare' => 'IN', 819 'value' => array( 'bar', 'baz' ), 820 ), 821 ) 822 ); 742 823 743 824 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 752 833 global $wpdb; 753 834 754 $query = new WP_Meta_Query( array( 755 array( 756 'key' => 'foo', 757 'value' => ' bar ', 758 ), 759 ) ); 835 $query = new WP_Meta_Query( 836 array( 837 array( 838 'key' => 'foo', 839 'value' => ' bar ', 840 ), 841 ) 842 ); 760 843 761 844 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 767 850 global $wpdb; 768 851 769 $query = new WP_Meta_Query( array( 770 'relation' => 'OR', 771 array( 772 'key' => 'exclude', 773 'compare' => 'NOT EXISTS' 774 ), 775 array( 776 'key' => 'exclude', 777 'compare' => '!=', 778 'value' => '1' 779 ), 780 ) ); 852 $query = new WP_Meta_Query( 853 array( 854 'relation' => 'OR', 855 array( 856 'key' => 'exclude', 857 'compare' => 'NOT EXISTS', 858 ), 859 array( 860 'key' => 'exclude', 861 'compare' => '!=', 862 'value' => '1', 863 ), 864 ) 865 ); 781 866 782 867 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 788 873 global $wpdb; 789 874 790 $query = new WP_Meta_Query( array( 791 'relation' => 'OR', 792 array( 793 'key' => 'exclude', 794 'compare' => '' 795 ), 796 array( 797 'key' => 'exclude', 798 'compare' => '!=', 799 'value' => '1' 800 ), 801 ) ); 875 $query = new WP_Meta_Query( 876 array( 877 'relation' => 'OR', 878 array( 879 'key' => 'exclude', 880 'compare' => '', 881 ), 882 array( 883 'key' => 'exclude', 884 'compare' => '!=', 885 'value' => '1', 886 ), 887 ) 888 ); 802 889 803 890 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); … … 812 899 */ 813 900 public function test_has_or_relation_should_return_false() { 814 $q = new WP_Meta_Query( array( 815 'relation' => 'AND', 816 array( 817 'key' => 'foo', 818 'value' => 'bar', 819 ), 901 $q = new WP_Meta_Query( 820 902 array( 821 903 'relation' => 'AND', 822 904 array( 823 'key' => 'foo1', 824 'value' => 'bar', 825 ), 826 array( 827 'key' => 'foo2', 828 'value' => 'bar', 829 ), 830 ), 831 ) ); 905 'key' => 'foo', 906 'value' => 'bar', 907 ), 908 array( 909 'relation' => 'AND', 910 array( 911 'key' => 'foo1', 912 'value' => 'bar', 913 ), 914 array( 915 'key' => 'foo2', 916 'value' => 'bar', 917 ), 918 ), 919 ) 920 ); 832 921 833 922 $this->assertFalse( $q->has_or_relation() ); … … 838 927 */ 839 928 public function test_has_or_relation_should_return_true_for_top_level_or() { 840 $q = new WP_Meta_Query( array( 841 'relation' => 'OR', 842 array( 843 'key' => 'foo', 844 'value' => 'bar', 845 ), 929 $q = new WP_Meta_Query( 930 array( 931 'relation' => 'OR', 932 array( 933 'key' => 'foo', 934 'value' => 'bar', 935 ), 936 array( 937 'relation' => 'AND', 938 array( 939 'key' => 'foo1', 940 'value' => 'bar', 941 ), 942 array( 943 'key' => 'foo2', 944 'value' => 'bar', 945 ), 946 ), 947 ) 948 ); 949 950 $this->assertTrue( $q->has_or_relation() ); 951 } 952 953 /** 954 * @ticket 32592 955 */ 956 public function test_has_or_relation_should_return_true_for_nested_or() { 957 $q = new WP_Meta_Query( 846 958 array( 847 959 'relation' => 'AND', 848 960 array( 849 'key' => 'foo1', 850 'value' => 'bar', 851 ), 852 array( 853 'key' => 'foo2', 854 'value' => 'bar', 855 ), 856 ), 857 ) ); 961 'key' => 'foo', 962 'value' => 'bar', 963 ), 964 array( 965 'relation' => 'OR', 966 array( 967 'key' => 'foo1', 968 'value' => 'bar', 969 ), 970 array( 971 'key' => 'foo2', 972 'value' => 'bar', 973 ), 974 ), 975 ) 976 ); 858 977 859 978 $this->assertTrue( $q->has_or_relation() ); 860 979 } 861 862 /**863 * @ticket 32592864 */865 public function test_has_or_relation_should_return_true_for_nested_or() {866 $q = new WP_Meta_Query( array(867 'relation' => 'AND',868 array(869 'key' => 'foo',870 'value' => 'bar',871 ),872 array(873 'relation' => 'OR',874 array(875 'key' => 'foo1',876 'value' => 'bar',877 ),878 array(879 'key' => 'foo2',880 'value' => 'bar',881 ),882 ),883 ) );884 885 $this->assertTrue( $q->has_or_relation() );886 }887 980 }
Note: See TracChangeset
for help on using the changeset viewer.