Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/04/2013 06:13:29 PM (11 years ago)
Author:
boonebgorges
Message:

In test_get_with_display_comments_stream(), don't use bp_activity_new_comment()

The latter function does not accept a recorded_time argument - the current time
is assumed. As a result, on some systems (eg Travis) that run the tests fairly
slowly, the reverse chronological sort order of BP_Activity_Activity::get()
gets messed up, and the test fails. Calling bp_activity_add() directly allows
us to specify the correct recorded_time, fixing the test.

File:
1 edited

Legend:

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

    r7127 r7155  
    162162            'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    163163        ) );
     164
     165        // bp_activity_new_comment() doesn't allow date_recorded
     166        $a3 = bp_activity_add( array(
     167            'action'            => sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_get_loggedin_user_link() ) ,
     168            'content'           => 'Candy is good',
     169            'component'         => buddypress()->activity->id,
     170            'type'              => 'activity_comment',
     171            'user_id'           => bp_loggedin_user_id,
     172            'item_id'           => $a1,
     173            'secondary_item_id' => $a1,
     174            'recorded_time'     => date( 'Y-m-d H:i:s', $now - 50 ),
     175        ) );
     176
     177        $activity = BP_Activity_Activity::get( array(
     178            'display_comments' => 'stream',
     179        ) );
     180        $ids = wp_list_pluck( $activity['activities'], 'id' );
     181        $this->assertEquals( array( $a1, $a3, $a2 ), $ids );
     182    }
     183
     184    /**
     185     * @group get
     186     */
     187    public function test_get_with_display_comments_false() {
     188        $now = time();
     189        $a1 = $this->factory->activity->create( array(
     190            'content' => 'Life Rules',
     191            'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     192        ) );
     193        $a2 = $this->factory->activity->create( array(
     194            'content' => 'Life Drools',
     195            'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     196        ) );
    164197        $a3 = bp_activity_new_comment( array(
    165198            'activity_id' => $a1,
     
    169202
    170203        $activity = BP_Activity_Activity::get( array(
    171             'display_comments' => 'stream',
    172         ) );
    173         $ids = wp_list_pluck( $activity['activities'], 'id' );
    174         $this->assertEquals( array( $a1, $a3, $a2 ), $ids );
    175     }
    176 
    177     /**
    178      * @group get
    179      */
    180     public function test_get_with_display_comments_false() {
    181         $now = time();
    182         $a1 = $this->factory->activity->create( array(
    183             'content' => 'Life Rules',
    184             'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    185         ) );
    186         $a2 = $this->factory->activity->create( array(
    187             'content' => 'Life Drools',
    188             'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    189         ) );
    190         $a3 = bp_activity_new_comment( array(
    191             'activity_id' => $a1,
    192             'content' => 'Candy is good',
    193             'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
    194         ) );
    195 
    196         $activity = BP_Activity_Activity::get( array(
    197204            'display_comments' => false,
    198205        ) );
Note: See TracChangeset for help on using the changeset viewer.