Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/11/2014 03:13:23 PM (12 years ago)
Author:
r-a-y
Message:

Add ability to query activity items by date.

This commit:

  • Introduces the BP_Date_Query class. This class extends WP_Date_Query, which will enable us to easily add support to query various BuddyPress items by date.
  • Adds a new 'date_query' parameter to BP_Activity_Activity::get(). This parameter utilizes the new BP_Date_Query class and is an example of how to use the class in BuddyPress. (Will add support for the Groups component in a later commit.)
  • Adds unit tests.

Due to the dependency on the WP_Date_Query class, this functionality is
only available in WordPress 3.7+.

Fixes #5803.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/activity/class.BP_Activity_Activity.php

    r8499 r8787  
    146146        /**
    147147         * @group get
     148         * @group date_query
     149         */
     150        public function test_get_with_date_query() {
     151                if ( ! class_exists( 'WP_Date_Query' ) ) {
     152                        return;
     153                }
     154
     155                $a1 = $this->factory->activity->create();
     156                $a2 = $this->factory->activity->create( array(
     157                        'recorded_time' => '2001-01-01 12:00'
     158                ) );
     159                $a3 = $this->factory->activity->create( array(
     160                        'recorded_time' => '2005-01-01 12:00'
     161                ) );
     162
     163                // 'date_query' before test
     164                $query = BP_Activity_Activity::get( array(
     165                        'date_query' => array( array(
     166                                'before' => array(
     167                                        'year'  => 2004,
     168                                        'month' => 1,
     169                                        'day'   => 1,
     170                                ),
     171                        ) )
     172                ) );
     173                $this->assertEquals( array( $a2 ), wp_list_pluck( $query['activities'], 'id' ) );
     174
     175                // 'date_query' range test
     176                $query = BP_Activity_Activity::get( array(
     177                        'date_query' => array( array(
     178                                'after'  => 'January 2nd, 2001',
     179                                'before' => array(
     180                                        'year'  => 2013,
     181                                        'month' => 1,
     182                                        'day'   => 1,
     183                                ),
     184                                'inclusive' => true,
     185                        ) )
     186                ) );
     187                $this->assertEquals( array( $a3 ), wp_list_pluck( $query['activities'], 'id' ) );
     188
     189                // 'date_query' after and relative test
     190                $query = BP_Activity_Activity::get( array(
     191                        'date_query' => array( array(
     192                                'after' => '1 day ago'
     193                        ) )
     194                ) );
     195                $this->assertEquals( array( $a1 ), wp_list_pluck( $query['activities'], 'id' ) );
     196        }
     197
     198        /**
     199         * @group get
    148200         */
    149201        public function test_get_with_search_terms() {
Note: See TracChangeset for help on using the changeset viewer.