Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/12/2021 02:09:02 PM (3 years ago)
Author:
imath
Message:

Support date queries for Members, Groups and Sites

According to components, date queries can be restricted to a limited list of loop types:

  • For Members, the $type parameter in bp_has_members() needs to be either active, newest, random or online.
  • For Groups, the $type parameter in bp_has_groups() needs to be either active or newest.
  • For sites, the $type parameter in bp_has_blogs() needs to be either active or newest.

Props r-a-y

Fixes #8488

File:
1 edited

Legend:

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

    r13086 r13184  
    292292    /**
    293293     * @group get
     294     * @group date_query
     295     */
     296    public function test_get_with_date_query_before() {
     297        $u1 = self::factory()->group->create( array(
     298            'last_activity' => date( 'Y-m-d H:i:s', time() ),
     299        ) );
     300        $u2 = self::factory()->group->create( array(
     301            'last_activity' => '2008-03-25 17:13:55',
     302        ) );
     303        $u3 = self::factory()->group->create( array(
     304            'last_activity' => '2010-01-01 12:00',
     305        ) );
     306
     307        // 'date_query' before test
     308        $groups = BP_Groups_Group::get( array(
     309            'type' => 'active',
     310            'date_query' => array( array(
     311                'before' => array(
     312                    'year'  => 2010,
     313                    'month' => 1,
     314                    'day'   => 1,
     315                ),
     316            ) )
     317        ) );
     318
     319        $this->assertEquals( [ $u2 ], wp_list_pluck( $groups['groups'], 'id' ) );
     320    }
     321
     322    /**
     323     * @group get
     324     * @group date_query
     325     */
     326    public function test_get_with_date_query_range() {
     327        $u1 = self::factory()->group->create( array(
     328            'last_activity' => date( 'Y-m-d H:i:s', time() ),
     329        ) );
     330        $u2 = self::factory()->group->create( array(
     331            'last_activity' => '2008-03-25 17:13:55',
     332        ) );
     333        $u3 = self::factory()->group->create( array(
     334            'last_activity' => '2001-01-01 12:00',
     335        ) );
     336
     337        // 'date_query' range test
     338        $groups = BP_Groups_Group::get( array(
     339            'type' => 'active',
     340            'date_query' => array( array(
     341                'after'  => 'January 2nd, 2001',
     342                'before' => array(
     343                    'year'  => 2010,
     344                    'month' => 1,
     345                    'day'   => 1,
     346                ),
     347                'inclusive' => true,
     348            ) )
     349        ) );
     350
     351        $this->assertEquals( [ $u2 ], wp_list_pluck( $groups['groups'], 'id' ) );
     352    }
     353
     354    /**
     355     * @group get
     356     * @group date_query
     357     */
     358    public function test_get_with_date_query_after() {
     359        $u1 = self::factory()->group->create( array(
     360            'last_activity' => date( 'Y-m-d H:i:s', time() ),
     361        ) );
     362        $u2 = self::factory()->group->create( array(
     363            'last_activity' => '2008-03-25 17:13:55',
     364        ) );
     365        $u3 = self::factory()->group->create( array(
     366            'last_activity' => '2001-01-01 12:00',
     367        ) );
     368
     369        // 'date_query' after and relative test
     370        $groups = BP_Groups_Group::get( array(
     371            'type' => 'active',
     372            'date_query' => array( array(
     373                'after' => '1 day ago'
     374            ) )
     375        ) );
     376
     377        $this->assertEquals( [ $u1 ], wp_list_pluck( $groups['groups'], 'id' ) );
     378    }
     379
     380    /**
     381     * @group get
    294382     */
    295383    public function test_get_normal_search() {
Note: See TracChangeset for help on using the changeset viewer.