Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/27/2015 03:00:42 AM (9 years ago)
Author:
boonebgorges
Message:

Don't create a current user by default in most unit tests.

The default state of our tests should be as a logged-out user. BP does pretty
different things with different kinds of logged-in users, so individual tests
should decide for themselves what the current user status should be.

Moreover, the creation of fixture users is fairly resource-intensive. Not
creating users when they're not needed makes the test suite run 5-10% faster.

See #6009.

File:
1 edited

Legend:

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

    r9475 r9561  
    44 */
    55class BP_Tests_Activity_Template extends BP_UnitTestCase {
    6     protected $old_current_user = 0;
    7 
    8     public function setUp() {
    9         parent::setUp();
    10 
    11         $this->old_current_user = get_current_user_id();
    12         $this->set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) );
    13     }
    14 
    15     public function tearDown() {
    16         parent::tearDown();
    17         $this->set_current_user( $this->old_current_user );
    18     }
    196
    207    /**
     
    2310    public function test_user_can_delete() {
    2411        $bp = buddypress();
     12        $u = $this->factory->user->create();
     13        $original_user = bp_loggedin_user_id();
     14        $this->set_current_user( $u );
    2515
    2616        $a = $this->factory->activity->create( array(
    2717            'type' => 'activity_update',
     18            'user_id' => $u,
    2819        ) );
    2920
     
    3122        $activity = $this->factory->activity->get_object_by_id( $a );
    3223        $this->assertTrue( bp_activity_user_can_delete( $activity ) );
    33 
    34         // Stash original user
    35         $original_user = get_current_user_id();
    3624
    3725        // Logged-out user can't delete
     
    10795        ) );
    10896
     97        $current_user = bp_loggedin_user_id();
     98        $this->set_current_user( $user_id );
     99
    109100        bp_activity_add_user_favorite( $a1, $user_id );
    110101        bp_activity_add_user_favorite( $a2, $user_id );
     102
     103        $this->set_current_user( $current_user );
    111104
    112105        // groan. It sucks that you have to invoke the global
     
    12241217        add_filter( 'bp_disable_blogforum_comments', '__return_false' );
    12251218
     1219        $u = $this->factory->user->create();
     1220
    12261221        $now = time();
    12271222        $a1 = $this->factory->activity->create( array(
     
    12301225            'type' => 'new_blog_post',
    12311226            'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1227            'user_id' => $u,
    12321228        ) );
    12331229        $a2 = $this->factory->activity->create( array(
     
    12361232            'type' => 'new_blog_comment',
    12371233            'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1234            'user_id' => $u,
    12381235        ) );
    12391236
     
    12441241            'content' => 'Candy is good',
    12451242            'recorded_time' => date( 'Y-m-d H:i:s', $now - 200 ),
     1243            'user_id' => $u,
    12461244        ) );
    12471245
     
    12511249            'type' => 'activity_update',
    12521250            'recorded_time' => date( 'Y-m-d H:i:s', $now - 300 ),
     1251            'user_id' => $u,
    12531252        ) );
    12541253
     
    12591258            'content' => 'Candy is great',
    12601259            'recorded_time' => date( 'Y-m-d H:i:s', $now - 400 ),
     1260            'user_id' => $u,
    12611261        ) );
    12621262        global $activities_template;
Note: See TracChangeset for help on using the changeset viewer.