Skip to:
Content

BuddyPress.org

Changeset 7774


Ignore:
Timestamp:
02/03/2014 03:21:40 AM (12 years ago)
Author:
boonebgorges
Message:

Introduce unit test for BP_Activity_Activity::get_activity_comments()

The main purpose of this test is to check the item formatting, to be used
during some upcoming refactoring of the method.

File:
1 edited

Legend:

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

    r7506 r7774  
    306306        $this->assertEquals( array( $a1 ), $activity );
    307307    }
     308
     309    /**
     310     * @group get_activity_comments
     311     *
     312     * Verify the format of the activity comments array, for internal
     313     * refactoring
     314     */
     315    public function test_get_activity_comments_format() {
     316        $now = time();
     317        $a1 = $this->factory->activity->create( array(
     318            'content' => 'Life Rules',
     319            'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     320        ) );
     321        $a2 = bp_activity_new_comment( array(
     322            'activity_id' => $a1,
     323            'content' => 'Candy is good',
     324            'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     325        ) );
     326        $a3 = bp_activity_new_comment( array(
     327            'activity_id' => $a1,
     328            'content' => 'Bread is good',
     329            'recorded_time' => date( 'Y-m-d H:i:s', $now - 25 ),
     330        ) );
     331
     332        $keys = array( 'id', 'item_id', 'secondary_item_id', 'user_id', 'primary_link', 'component', 'type', 'action', 'content', 'date_recorded', 'hide_sitewide', 'mptt_left', 'mptt_right', 'is_spam' );
     333
     334        $a2_obj = new BP_Activity_Activity( $a2 );
     335
     336        $e2 = new stdClass;
     337
     338        foreach ( $keys as $key ) {
     339            $e2->{$key} = $a2_obj->{$key};
     340        }
     341
     342        $e2_user = new WP_User( $a2_obj->user_id );
     343
     344        $e2->user_email = $e2_user->user_email;
     345        $e2->user_nicename = $e2_user->user_nicename;
     346        $e2->user_login = $e2_user->user_login;
     347        $e2->display_name = $e2_user->display_name;
     348        $e2->user_fullname = bp_core_get_user_displayname( $e2->user_id );
     349        $e2->children = array();
     350
     351        $a3_obj = new BP_Activity_Activity( $a3 );
     352
     353        $e3 = new stdClass;
     354
     355        foreach ( $keys as $key ) {
     356            $e3->{$key} = $a3_obj->{$key};
     357        }
     358
     359        $e3_user = new WP_User( $e3->user_id );
     360
     361        $e3->user_email = $e3_user->user_email;
     362        $e3->user_nicename = $e3_user->user_nicename;
     363        $e3->user_login = $e3_user->user_login;
     364        $e3->display_name = $e3_user->display_name;
     365        $e3->user_fullname = bp_core_get_user_displayname( $e3->user_id );
     366        $e3->children = array();
     367
     368        $expected = array(
     369            $a2 => $e2,
     370            $a3 => $e3,
     371        );
     372
     373        $a1_obj = new BP_Activity_Activity( $a1 );
     374        $comments = BP_Activity_Activity::get_activity_comments( $a1, $a1_obj->mptt_left, $a1_obj->mptt_right, 'ham_only', $a1 );
     375
     376        $this->assertEquals( $expected, $comments );
     377    }
    308378}
Note: See TracChangeset for help on using the changeset viewer.