Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/20/2014 06:32:30 PM (10 years ago)
Author:
boonebgorges
Message:

Simplify logic that transforms WP_Meta_Query SQL for Groups queries

This simplified logic fixes a bug related to the use of the 'compare'
operator in certain cases.

Fixes #5824

Props imath

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/groups/class-bp-groups-group.php

    r8829 r8949  
    137137    /**
    138138     * @group get
     139     * @group group_meta_query
     140     */
     141    public function test_get_with_meta_query_multiple_clauses_relation_or() {
     142        $now = time();
     143        $g1 = $this->factory->group->create( array(
     144            'last_activity' => date( 'Y-m-d H:i:s', $now - 60*60 ),
     145        ) );
     146        $g2 = $this->factory->group->create( array(
     147            'last_activity' => date( 'Y-m-d H:i:s', $now - 60*60*2 ),
     148        ) );
     149        $g3 = $this->factory->group->create( array(
     150            'last_activity' => date( 'Y-m-d H:i:s', $now - 60*60*3 ),
     151        ) );
     152        groups_update_groupmeta( $g1, 'foo', 'bar' );
     153        groups_update_groupmeta( $g2, 'foo', 'baz' );
     154        groups_update_groupmeta( $g3, 'bar', 'barry' );
     155
     156        $groups = BP_Groups_Group::get( array(
     157            'meta_query' => array(
     158                'relation' => 'OR',
     159                array(
     160                    'key' => 'foo',
     161                    'value' => 'bar',
     162                ),
     163                array(
     164                    'key' => 'bar',
     165                    'value' => 'barry',
     166                ),
     167            ),
     168        ) );
     169        $ids = wp_list_pluck( $groups['groups'], 'id' );
     170        $this->assertEquals( array( $g1, $g3 ), $ids );
     171        $this->assertEquals( 2, $groups['total'] );
     172    }
     173
     174    /**
     175     * @group get
     176     * @group group_meta_query
     177     * @ticket BP5824
     178     */
     179    public function test_get_with_meta_query_multiple_keys_with_same_value() {
     180        $now = time();
     181        $g1 = $this->factory->group->create( array(
     182            'last_activity' => date( 'Y-m-d H:i:s', $now - 60*60 ),
     183        ) );
     184        $g2 = $this->factory->group->create( array(
     185            'last_activity' => date( 'Y-m-d H:i:s', $now - 60*60*2 ),
     186        ) );
     187        groups_update_groupmeta( $g1, 'foo', 'bar' );
     188        groups_update_groupmeta( $g2, 'foo2', 'bar' );
     189
     190        $groups = BP_Groups_Group::get( array(
     191            'meta_query' => array(
     192                array(
     193                    'key' => 'foo',
     194                    'value' => 'bar',
     195                    'compare' => '=',
     196                ),
     197            ),
     198        ) );
     199        $ids = wp_list_pluck( $groups['groups'], 'id' );
     200        $this->assertEquals( $ids, array( $g1 ) );
     201        $this->assertEquals( 1, $groups['total'] );
     202    }
     203
     204    /**
     205     * @group get
    139206     */
    140207    public function test_get_normal_search() {
Note: See TracChangeset for help on using the changeset viewer.