diff --git src/bp-xprofile/classes/class-bp-xprofile-query.php src/bp-xprofile/classes/class-bp-xprofile-query.php
index 1807d15..1874827 100644
|
|
|
class BP_XProfile_Query { |
| 515 | 515 | $compatible_compares = array( '=', 'IN', 'BETWEEN', 'LIKE', 'REGEXP', 'RLIKE', '>', '>=', '<', '<=' ); |
| 516 | 516 | |
| 517 | 517 | // Clauses joined by AND with "negative" operators share a join only if they also share a key. |
| 518 | | } elseif ( isset( $sibling['field_id'] ) && isset( $clause['field_id'] ) && $sibling['field_id'] === $clause['field_id'] ) { |
| | 518 | } elseif ( isset( $sibling['field'] ) && isset( $clause['field'] ) && $sibling['field'] === $clause['field'] ) { |
| 519 | 519 | $compatible_compares = array( '!=', 'NOT IN', 'NOT LIKE' ); |
| 520 | 520 | } |
| 521 | 521 | |
diff --git tests/phpunit/testcases/xprofile/class-bp-xprofile-query.php tests/phpunit/testcases/xprofile/class-bp-xprofile-query.php
index 3bbd120..71a5cea 100644
|
|
|
class BP_Tests_BP_XProfile_Query extends BP_UnitTestCase { |
| 472 | 472 | $this->assertEqualSets( $expected, array_keys( $q->results ) ); |
| 473 | 473 | } |
| 474 | 474 | |
| | 475 | /** |
| | 476 | * @ticket BP7202 |
| | 477 | */ |
| | 478 | public function test_relation_and_with_compare_not_in() { |
| | 479 | $this->create_fields( 1 ); |
| | 480 | $this->create_users( 4 ); |
| | 481 | |
| | 482 | xprofile_set_field_data( $this->fields[0], $this->users[0], 'boo' ); |
| | 483 | xprofile_set_field_data( $this->fields[0], $this->users[3], 'far' ); |
| | 484 | xprofile_set_field_data( $this->fields[0], $this->users[1], 'foo' ); |
| | 485 | xprofile_set_field_data( $this->fields[0], $this->users[2], 'bar' ); |
| | 486 | |
| | 487 | $q = new BP_User_Query( array( |
| | 488 | 'xprofile_query' => array( |
| | 489 | 'relation' => 'AND', |
| | 490 | array( |
| | 491 | 'field' => $this->fields[0], |
| | 492 | 'compare' => 'NOT IN', |
| | 493 | 'value' => array( 'foo', 'bar' ) |
| | 494 | ), |
| | 495 | array( |
| | 496 | 'field' => $this->fields[0], |
| | 497 | 'compare' => '!=', |
| | 498 | 'value' => 'far', |
| | 499 | ), |
| | 500 | ), |
| | 501 | ) ); |
| | 502 | |
| | 503 | $expected = array( $this->users[0] ); |
| | 504 | $this->assertEqualSets( $expected, array_keys( $q->results ) ); |
| | 505 | } |
| | 506 | |
| 475 | 507 | public function test_relation_or_with_compare_not_exists() { |
| 476 | 508 | $this->create_fields( 2 ); |
| 477 | 509 | $this->create_users( 4 ); |
| … |
… |
class BP_Tests_BP_XProfile_Query extends BP_UnitTestCase { |
| 567 | 599 | $this->assertEqualSets( $expected, array_keys( $q->results ) ); |
| 568 | 600 | } |
| 569 | 601 | |
| | 602 | /** |
| | 603 | * @group BP7202 |
| | 604 | */ |
| | 605 | public function test_find_compatible_table_alias_should_match_negative_siblings_joined_with_relation_and() { |
| | 606 | $this->create_fields( 1 ); |
| | 607 | |
| | 608 | $q = new BP_XProfile_Query( array( |
| | 609 | 'relation' => 'AND', |
| | 610 | array( |
| | 611 | 'field' => $this->fields[0], |
| | 612 | 'compare' => '!=', |
| | 613 | 'value' => 'foo', |
| | 614 | ), |
| | 615 | array( |
| | 616 | 'field' => $this->fields[0], |
| | 617 | 'compare' => 'NOT IN', |
| | 618 | 'value' => array( 'bar', 'baz' ), |
| | 619 | ) |
| | 620 | ) ); |
| | 621 | |
| | 622 | $sql = $q->get_sql( buddypress()->profile->table_name_data, 'user_id' ); |
| | 623 | |
| | 624 | $this->assertSame( 1, substr_count( $sql['join'], 'INNER JOIN' ) ); |
| | 625 | } |
| | 626 | |
| 570 | 627 | /** Helpers **********************************************************/ |
| 571 | 628 | |
| 572 | 629 | protected function create_fields( $count ) { |