Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/05/2016 04:00:00 AM (8 years ago)
Author:
boonebgorges
Message:

In activity queries, use id column for secondary sort.

The default sort order for activity queries is by date_recorded. But this
order can be indeterminate when two items share the same date_recorded. To
prevent indeterminacy, we fall back on the always unique id column.

Fixes #6720.
Props henry.wright, Mamaduka.

File:
1 edited

Legend:

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

    r9819 r10435  
    523523        // clean up!
    524524        $activities_template = $reset_activities_template;
     525    }
     526
     527    /**
     528     * @group scope
     529     * @ticket BP6720
     530     */
     531    public function test_bp_has_activities_scope_friends_should_respect_id_order_when_record_dates_are_same() {
     532        $u1 = $this->factory->user->create();
     533        $u2 = $this->factory->user->create();
     534
     535        friends_add_friend( $u1, $u2, true );
     536
     537        // Friend's very fast status updates.
     538        $a1 = $this->factory->activity->create( array(
     539            'user_id' => $u2,
     540            'type' => 'activity_update',
     541            'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     542        ) );
     543        $a2 = $this->factory->activity->create( array(
     544            'user_id' => $u2,
     545            'type' => 'activity_update',
     546            'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     547        ) );
     548
     549        global $activities_template;
     550        $reset_activities_template = $activities_template;
     551
     552        // Get activities in 'friends' scope
     553        bp_has_activities( array(
     554            'user_id' => $u1,
     555            'scope' => 'friends',
     556        ) );
     557
     558        $found = $activities_template->activities;
     559
     560        // Clean up!
     561        $activities_template = $reset_activities_template;
     562
     563        $this->assertEquals( array( $a2, $a1 ), wp_list_pluck( $found, 'id' ) );
     564    }
     565
     566    /**
     567     * @group scope
     568     * @ticket BP6720
     569     */
     570    public function test_bp_has_activities_scope_groups_should_respect_id_order_when_record_dates_are_same() {
     571        $u1 = $this->factory->user->create();
     572        $u2 = $this->factory->user->create();
     573        $u3 = $this->factory->user->create();
     574
     575        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     576
     577        // Two user join first user's group same time
     578        $a1 = $this->factory->activity->create( array(
     579            'user_id'   => $u2,
     580            'component' => 'groups',
     581            'item_id'   => $g1,
     582            'type'      => 'joined_group',
     583            'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     584        ) );
     585        $a2 = $this->factory->activity->create( array(
     586            'user_id'   => $u3,
     587            'component' => 'groups',
     588            'item_id'   => $g1,
     589            'type'      => 'joined_group',
     590            'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     591        ) );
     592
     593        global $activities_template;
     594        $reset_activities_template = $activities_template;
     595
     596        // Get activities in 'groups' scope
     597        bp_has_activities( array(
     598            'user_id' => $u1,
     599            'scope' => 'groups',
     600        ) );
     601
     602        $found = $activities_template->activities;
     603
     604        // Clean up!
     605        $activities_template = $reset_activities_template;
     606
     607        $this->assertEquals( array( $a2, $a1 ), wp_list_pluck( $found, 'id' ) );
    525608    }
    526609
Note: See TracChangeset for help on using the changeset viewer.