Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/27/2015 03:00:42 AM (10 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/class.BP_Activity_Activity.php

    r9139 r9561  
    44 */
    55class BP_Tests_Activity_Class 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(
    13             'role' => 'subscriber',
    14         ) ) );
    15     }
    16 
    17     public function tearDown() {
    18         parent::tearDown();
    19         $this->set_current_user( $this->old_current_user );
    20     }
    216
    227    /**
     
    259244     */
    260245    public function test_get_with_display_comments_threaded() {
     246        $u = $this->factory->user->create();
     247
    261248        $now = time();
    262249        $a1 = $this->factory->activity->create( array(
     250            'user_id' => $u,
    263251            'content' => 'Life Rules',
    264252            'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    265253        ) );
    266254        $a2 = $this->factory->activity->create( array(
     255            'user_id' => $u,
    267256            'content' => 'Life Drools',
    268257            'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    269258        ) );
    270259        $a3 = bp_activity_new_comment( array(
     260            'user_id' => $u,
    271261            'activity_id' => $a1,
    272262            'content' => 'Candy is good',
Note: See TracChangeset for help on using the changeset viewer.