Skip to:
Content

BuddyPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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',
Note: See TracChangeset for help on using the changeset viewer.