Skip to:
Content

BuddyPress.org

Changeset 9142


Ignore:
Timestamp:
11/14/2014 02:01:30 PM (10 years ago)
Author:
boonebgorges
Message:

Share fixtures across Suggestions tests.

This improves the running time of our automated test suite by almost a minute.

See #6009.

Location:
trunk/tests/phpunit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r9141 r9142  
    431431        return $args;
    432432    }
     433
     434    /**
     435     * Commit a MySQL transaction.
     436     */
     437    public static function commit_transaction() {
     438        global $wpdb;
     439        $wpdb->query( 'COMMIT;' );
     440    }
    433441}
  • trunk/tests/phpunit/testcases/apis/suggestions-nonauth.php

    r8958 r9142  
    77 */
    88class BP_Tests_Suggestions_Non_Authenticated extends BP_UnitTestCase {
    9     protected $group_ids    = array();
    10     protected $group_slugs  = array();
    11     protected $user_ids     = array();
     9    protected static $group_ids    = array();
     10    protected static $group_slugs  = array();
     11    protected static $user_ids     = array();
    1212
    13     public function setUp() {
    14         parent::setUp();
     13    public static function setUpBeforeClass() {
     14        parent::setUpBeforeClass();
    1515
    1616        $users = array(
     
    2929        );
    3030
     31        $factory = new BP_UnitTest_Factory();
     32
    3133        // Create some dummy users.
    32         foreach( $users as $user ) {
    33             $this->user_ids[ $user[0] ] = $this->create_user( array(
     34        foreach( $users as $user_index => $user ) {
     35            $new_user = $factory->user->create( array(
    3436                'display_name' => $user[1],
    3537                'user_login'   => $user[0],
     38                'user_email'   => "test-$user_index@example.com",
    3639            ) );
     40
     41            self::$user_ids[ $user[0] ] = $new_user;
    3742        }
    3843
    39         $this->group_slugs['hidden']  = 'the-maw';
    40         $this->group_slugs['public']  = 'the-great-journey';
    41         $this->group_slugs['private'] = 'tsavo-highway';
     44        self::$group_slugs['hidden']  = 'the-maw';
     45        self::$group_slugs['public']  = 'the-great-journey';
     46        self::$group_slugs['private'] = 'tsavo-highway';
    4247
    4348        // Create dummy groups.
    44         $this->group_ids['hidden'] = $this->factory->group->create( array(
    45             'creator_id' => $this->user_ids['xylo'],
    46             'slug'       => $this->group_slugs['hidden'],
     49        self::$group_ids['hidden'] = $factory->group->create( array(
     50            'creator_id' => self::$user_ids['xylo'],
     51            'slug'       => self::$group_slugs['hidden'],
    4752            'status'     => 'hidden',
    4853        ) );
    49         $this->group_ids['public'] = $this->factory->group->create( array(
    50             'creator_id' => $this->user_ids['xylo'],
    51             'slug'       => $this->group_slugs['public'],
     54        self::$group_ids['public'] = $factory->group->create( array(
     55            'creator_id' => self::$user_ids['xylo'],
     56            'slug'       => self::$group_slugs['public'],
    5257            'status'     => 'public',
    5358        ) );
    54         $this->group_ids['private'] = $this->factory->group->create( array(
    55             'creator_id' => $this->user_ids['xylo'],
    56             'slug'       => $this->group_slugs['private'],
     59        self::$group_ids['private'] = $factory->group->create( array(
     60            'creator_id' => self::$user_ids['xylo'],
     61            'slug'       => self::$group_slugs['private'],
    5762            'status'     => 'private',
    5863        ) );
    5964
    6065        // Add dummy users to dummy hidden groups.
    61         groups_join_group( $this->group_ids['hidden'], $this->user_ids['pig'] );
    62         groups_join_group( $this->group_ids['hidden'], $this->user_ids['alpaca red'] );
     66        groups_join_group( self::$group_ids['hidden'], self::$user_ids['pig'] );
     67        groups_join_group( self::$group_ids['hidden'], self::$user_ids['alpaca red'] );
    6368
    6469        // Add dummy users to dummy public groups.
    65         groups_join_group( $this->group_ids['public'], $this->user_ids['aardvark'] );
    66         groups_join_group( $this->group_ids['public'], $this->user_ids['alpaca red'] );
    67         groups_join_group( $this->group_ids['public'], $this->user_ids['cat'] );
    68         groups_join_group( $this->group_ids['public'], $this->user_ids['smith'] );
     70        groups_join_group( self::$group_ids['public'], self::$user_ids['aardvark'] );
     71        groups_join_group( self::$group_ids['public'], self::$user_ids['alpaca red'] );
     72        groups_join_group( self::$group_ids['public'], self::$user_ids['cat'] );
     73        groups_join_group( self::$group_ids['public'], self::$user_ids['smith'] );
    6974
    7075        // Add dummy users to dummy private groups.
    71         groups_join_group( $this->group_ids['private'], $this->user_ids['cat'] );
    72         groups_join_group( $this->group_ids['private'], $this->user_ids['caterpillar'] );
     76        groups_join_group( self::$group_ids['private'], self::$user_ids['cat'] );
     77        groups_join_group( self::$group_ids['private'], self::$user_ids['caterpillar'] );
     78
     79        self::commit_transaction();
    7380    }
    7481
     82    public static function tearDownAfterClass() {
     83        foreach ( self::$group_ids as $group_id ) {
     84            groups_delete_group( $group_id );
     85        }
     86
     87        foreach ( self::$user_ids as $user_id ) {
     88            if ( is_multisite() ) {
     89                wpmu_delete_user( $user_id );
     90            } else {
     91                wp_delete_user( $user_id );
     92            }
     93        }
     94
     95        self::commit_transaction();
     96    }
    7597
    7698    /**
     
    92114        // only_friends requires authenticated requests
    93115        $suggestions = bp_core_get_suggestions( array(
    94             'group_id'     => $this->group_ids['public'],
     116            'group_id'     => self::$group_ids['public'],
    95117            'only_friends' => true,
    96118            'type'         => 'members',
     
    103125    public function test_suggestions_with_type_groupmembers_hidden() {
    104126        $suggestions = bp_core_get_suggestions( array(
    105             'group_id' => $this->group_ids['hidden'],
     127            'group_id' => self::$group_ids['hidden'],
    106128            'type'     => 'members',
    107129            'term'     => 'pig',
     
    113135    public function test_suggestions_with_type_groupmembers_private() {
    114136        $suggestions = bp_core_get_suggestions( array(
    115             'group_id' => $this->group_ids['private'],
     137            'group_id' => self::$group_ids['private'],
    116138            'type'     => 'members',
    117139            'term'     => 'cat',
     
    123145    public function test_suggestions_with_type_groupmembers_public_and_exclude_group_from_results() {
    124146        $suggestions = bp_core_get_suggestions( array(
    125             'group_id' => $this->group_ids['public'],
     147            'group_id' => self::$group_ids['public'],
    126148            'type'     => 'members',
    127149            'term'     => 'smith',
     
    131153
    132154        $suggestions = bp_core_get_suggestions( array(
    133             'group_id' => -$this->group_ids['public'],
     155            'group_id' => -self::$group_ids['public'],
    134156            'type'     => 'members',
    135157            'term'     => 'smith',
     
    141163    public function test_suggestions_with_type_groupmembers_private_and_exclude_group_from_results() {
    142164        $suggestions = bp_core_get_suggestions( array(
    143             'group_id' => -$this->group_ids['private'],
     165            'group_id' => -self::$group_ids['private'],
    144166            'type'     => 'members',
    145167            'term'     => 'cat',
     
    150172    public function test_suggestions_with_type_groupmembers_hidden_and_exclude_group_from_results() {
    151173        $suggestions = bp_core_get_suggestions( array(
    152             'group_id' => $this->group_ids['hidden'],
     174            'group_id' => self::$group_ids['hidden'],
    153175            'type'     => 'members',
    154176            'term'     => 'pig',
  • trunk/tests/phpunit/testcases/apis/suggestions.php

    r8958 r9142  
    77 */
    88class BP_Tests_Suggestions_Authenticated extends BP_UnitTestCase {
    9     protected $current_user = null;
    10     protected $group_ids    = array();
    11     protected $group_slugs  = array();
    12     protected $old_user_id  = 0;
    13     protected $user_ids     = array();
    14 
    15     public function setUp() {
    16         parent::setUp();
    17 
    18         $this->old_user_id  = get_current_user_id();
    19         $this->current_user = $this->create_user( array(
     9    protected static $current_user = null;
     10    protected static $group_ids    = array();
     11    protected static $group_slugs  = array();
     12    protected static $old_user_id  = 0;
     13    protected static $user_ids     = array();
     14
     15    public static function setUpBeforeClass() {
     16        parent::setUpBeforeClass();
     17
     18        $factory = new BP_UnitTest_Factory();
     19
     20        self::$old_user_id  = get_current_user_id();
     21        self::$current_user = $factory->user->create( array(
    2022            'display_name' => 'Katie Parker',
    2123            'user_login'   => 'katie',
    22         ) );
    23 
    24         $this->set_current_user( $this->current_user );
     24            'user_email'   => 'test-katie@example.com',
     25        ) );
    2526
    2627        $users = array(
     
    4041
    4142        // Create some dummy users.
    42         foreach ( $users as $user ) {
    43             $this->user_ids[ $user[0] ] = $this->create_user( array(
     43        foreach ( $users as $user_index => $user ) {
     44            $new_user = $factory->user->create( array(
    4445                'display_name' => $user[1],
    4546                'user_login'   => $user[0],
     47                'user_email'   => "test-$user_index@example.com",
    4648            ) );
     49
     50            self::$user_ids[ $user[0] ] = $new_user;
    4751        }
    4852
    49         // Create some dummy friendships.
    50         friends_add_friend( $this->current_user, $this->user_ids['aardvark'], true );
    51         friends_add_friend( $this->current_user, $this->user_ids['cat'], true );
    52         friends_add_friend( $this->current_user, $this->user_ids['caterpillar'], true );
    53         friends_add_friend( $this->current_user, $this->user_ids['pig'], true );
    54 
    55         $this->group_slugs['hidden']  = 'the-maw';
    56         $this->group_slugs['public']  = 'the-great-journey';
    57         $this->group_slugs['private'] = 'tsavo-highway';
     53        // Create some dummy friendships (but not the corresponding activity items).
     54        remove_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4 );
     55        friends_add_friend( self::$current_user, self::$user_ids['aardvark'], true );
     56        friends_add_friend( self::$current_user, self::$user_ids['cat'], true );
     57        friends_add_friend( self::$current_user, self::$user_ids['caterpillar'], true );
     58        friends_add_friend( self::$current_user, self::$user_ids['pig'], true );
     59        add_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4 );
     60
     61        self::$group_slugs['hidden']  = 'the-maw';
     62        self::$group_slugs['public']  = 'the-great-journey';
     63        self::$group_slugs['private'] = 'tsavo-highway';
    5864
    5965        // Create dummy groups.
    60         $this->group_ids['hidden'] = $this->factory->group->create( array(
    61             'creator_id' => $this->user_ids['xylo'],
    62             'slug'       => $this->group_slugs['hidden'],
     66        self::$group_ids['hidden'] = $factory->group->create( array(
     67            'creator_id' => self::$user_ids['xylo'],
     68            'slug'       => self::$group_slugs['hidden'],
    6369            'status'     => 'hidden',
    6470        ) );
    65         $this->group_ids['public'] = $this->factory->group->create( array(
    66             'creator_id' => $this->user_ids['xylo'],
    67             'slug'       => $this->group_slugs['public'],
     71        self::$group_ids['public'] = $factory->group->create( array(
     72            'creator_id' => self::$user_ids['xylo'],
     73            'slug'       => self::$group_slugs['public'],
    6874            'status'     => 'public',
    6975        ) );
    70         $this->group_ids['private'] = $this->factory->group->create( array(
    71             'creator_id' => $this->user_ids['xylo'],
    72             'slug'       => $this->group_slugs['private'],
     76        self::$group_ids['private'] = $factory->group->create( array(
     77            'creator_id' => self::$user_ids['xylo'],
     78            'slug'       => self::$group_slugs['private'],
    7379            'status'     => 'private',
    7480        ) );
    7581
    7682        // Add dummy users to dummy hidden groups.
    77         groups_join_group( $this->group_ids['hidden'], $this->user_ids['pig'] );
    78         groups_join_group( $this->group_ids['hidden'], $this->user_ids['alpaca red'] );
     83        groups_join_group( self::$group_ids['hidden'], self::$user_ids['pig'] );
     84        groups_join_group( self::$group_ids['hidden'], self::$user_ids['alpaca red'] );
    7985
    8086        // Add dummy users to dummy public groups.
    81         groups_join_group( $this->group_ids['public'], $this->current_user );
    82         groups_join_group( $this->group_ids['public'], $this->user_ids['aardvark'] );
    83         groups_join_group( $this->group_ids['public'], $this->user_ids['alpaca red'] );
    84         groups_join_group( $this->group_ids['public'], $this->user_ids['cat'] );
    85         groups_join_group( $this->group_ids['public'], $this->user_ids['smith'] );
     87        groups_join_group( self::$group_ids['public'], self::$current_user );
     88        groups_join_group( self::$group_ids['public'], self::$user_ids['aardvark'] );
     89        groups_join_group( self::$group_ids['public'], self::$user_ids['alpaca red'] );
     90        groups_join_group( self::$group_ids['public'], self::$user_ids['cat'] );
     91        groups_join_group( self::$group_ids['public'], self::$user_ids['smith'] );
    8692
    8793        // Add dummy users to dummy private groups.
    88         groups_join_group( $this->group_ids['private'], $this->user_ids['cat'] );
    89         groups_join_group( $this->group_ids['private'], $this->user_ids['caterpillar'] );
     94        groups_join_group( self::$group_ids['private'], self::$user_ids['cat'] );
     95        groups_join_group( self::$group_ids['private'], self::$user_ids['caterpillar'] );
     96
     97        self::commit_transaction();
     98    }
     99
     100    public static function tearDownAfterClass() {
     101        foreach ( self::$group_ids as $group_id ) {
     102            groups_delete_group( $group_id );
     103        }
     104
     105        foreach ( array_merge( self::$user_ids, array( self::$current_user ) ) as $user_id ) {
     106            if ( is_multisite() ) {
     107                wpmu_delete_user( $user_id );
     108            } else {
     109                wp_delete_user( $user_id );
     110            }
     111        }
     112
     113        self::commit_transaction();
     114    }
     115
     116    public function setUp() {
     117        parent::setUp();
     118        $this->set_current_user( self::$current_user );
    90119    }
    91120
    92121    public function tearDown() {
    93122        parent::tearDown();
    94         $this->set_current_user( $this->old_user_id );
    95     }
    96 
     123        $this->set_current_user( self::$old_user_id );
     124    }
    97125
    98126    public function test_suggestions_with_type_members() {
     
    169197    public function test_suggestions_with_type_groupmembers_public() {
    170198        $suggestions = bp_core_get_suggestions( array(
    171             'group_id' => $this->group_ids['public'],
     199            'group_id' => self::$group_ids['public'],
    172200            'type'     => 'members',
    173201            'term'     => 'smith',
     
    181209        $suggestions = bp_core_get_suggestions( array(
    182210            'limit'    => 1,
    183             'group_id' => $this->group_ids['public'],
     211            'group_id' => self::$group_ids['public'],
    184212            'type'     => 'members',
    185213            'term'     => 'smith',
     
    192220    public function test_suggestions_with_type_groupmembers_public_and_only_friends() {
    193221        $suggestions = bp_core_get_suggestions( array(
    194             'group_id'     => $this->group_ids['public'],
     222            'group_id'     => self::$group_ids['public'],
    195223            'only_friends' => true,
    196224            'type'         => 'members',
     
    204232    public function test_suggestions_with_type_groupmembers_public_and_term_as_displayname() {
    205233        $suggestions = bp_core_get_suggestions( array(
    206             'group_id' => $this->group_ids['public'],
     234            'group_id' => self::$group_ids['public'],
    207235            'type'     => 'members',
    208236            'term'     => 'aardvark',
     
    215243    public function test_suggestions_with_type_groupmembers_public_and_term_as_usernicename() {
    216244        $suggestions = bp_core_get_suggestions( array(
    217             'group_id' => $this->group_ids['public'],
     245            'group_id' => self::$group_ids['public'],
    218246            'type'     => 'members',
    219247            'term'     => 'robert',
     
    226254    public function test_suggestions_with_type_groupmembers_public_as_id() {
    227255        $suggestions = bp_core_get_suggestions( array(
    228             'group_id' => $this->group_ids['public'],
     256            'group_id' => self::$group_ids['public'],
    229257            'type'     => 'members',
    230258            'term'     => 'smith',
     
    238266        // current_user isn't a member of the hidden group
    239267        $suggestions = bp_core_get_suggestions( array(
    240             'group_id' => $this->group_ids['hidden'],
     268            'group_id' => self::$group_ids['hidden'],
    241269            'type'     => 'members',
    242270            'term'     => 'pig',
     
    245273
    246274        // "alpaca red" is in the hidden group
    247         $this->set_current_user( $this->user_ids['alpaca red'] );
    248         $suggestions = bp_core_get_suggestions( array(
    249             'group_id' => $this->group_ids['hidden'],
     275        $this->set_current_user( self::$user_ids['alpaca red'] );
     276        $suggestions = bp_core_get_suggestions( array(
     277            'group_id' => self::$group_ids['hidden'],
    250278            'type'     => 'members',
    251279            'term'     => 'pig',
     
    258286        // current_user isn't a member of the private group.
    259287        $suggestions = bp_core_get_suggestions( array(
    260             'group_id' => $this->group_ids['private'],
     288            'group_id' => self::$group_ids['private'],
    261289            'type'     => 'members',
    262290            'term'     => 'cat',
     
    265293
    266294        // "caterpillar" is in the private group
    267         $this->set_current_user( $this->user_ids['caterpillar'] );
    268         $suggestions = bp_core_get_suggestions( array(
    269             'group_id' => $this->group_ids['private'],
     295        $this->set_current_user( self::$user_ids['caterpillar'] );
     296        $suggestions = bp_core_get_suggestions( array(
     297            'group_id' => self::$group_ids['private'],
    270298            'type'     => 'members',
    271299            'term'     => 'cat',
     
    278306    public function test_suggestions_with_type_groupmembers_public_and_exclude_group_from_results() {
    279307        $suggestions = bp_core_get_suggestions( array(
    280             'group_id' => $this->group_ids['public'],
     308            'group_id' => self::$group_ids['public'],
    281309            'type'     => 'members',
    282310            'term'     => 'smith',
     
    286314
    287315        $suggestions = bp_core_get_suggestions( array(
    288             'group_id' => -$this->group_ids['public'],
     316            'group_id' => -self::$group_ids['public'],
    289317            'type'     => 'members',
    290318            'term'     => 'smith',
     
    297325        // current_user isn't a member of the private group.
    298326        $suggestions = bp_core_get_suggestions( array(
    299             'group_id' => -$this->group_ids['private'],
     327            'group_id' => -self::$group_ids['private'],
    300328            'type'     => 'members',
    301329            'term'     => 'cat',
     
    304332
    305333
    306         $this->set_current_user( $this->user_ids['caterpillar'] );
     334        $this->set_current_user( self::$user_ids['caterpillar'] );
    307335
    308336        // "cat" is in the private group, so won't show up here.
    309337        $suggestions = bp_core_get_suggestions( array(
    310             'group_id' => -$this->group_ids['private'],
     338            'group_id' => -self::$group_ids['private'],
    311339            'type'     => 'members',
    312340            'term'     => 'cat',
     
    317345        // "zoo" is not the private group, so will show up here.
    318346        $suggestions = bp_core_get_suggestions( array(
    319             'group_id' => -$this->group_ids['private'],
     347            'group_id' => -self::$group_ids['private'],
    320348            'type'     => 'members',
    321349            'term'     => 'zoo',
     
    328356        // current_user isn't a member of the hidden group.
    329357        $suggestions = bp_core_get_suggestions( array(
    330             'group_id' => $this->group_ids['hidden'],
     358            'group_id' => self::$group_ids['hidden'],
    331359            'type'     => 'members',
    332360            'term'     => 'pig',
     
    335363
    336364
    337         $this->set_current_user( $this->user_ids['alpaca red'] );
     365        $this->set_current_user( self::$user_ids['alpaca red'] );
    338366
    339367        // "alpaca red" is in the hidden group, so won't show up here.
    340368        $suggestions = bp_core_get_suggestions( array(
    341             'group_id' => -$this->group_ids['hidden'],
     369            'group_id' => -self::$group_ids['hidden'],
    342370            'type'     => 'members',
    343371            'term'     => 'alpaca red',
     
    348376        // "zoo" is not the hidden group, so will show up here.
    349377        $suggestions = bp_core_get_suggestions( array(
    350             'group_id' => -$this->group_ids['hidden'],
     378            'group_id' => -self::$group_ids['hidden'],
    351379            'type'     => 'members',
    352380            'term'     => 'zoo',
Note: See TracChangeset for help on using the changeset viewer.