Skip to:
Content

BuddyPress.org


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

In automated tests, move user creation to a proper factory method.

BP user creation requires that a couple of extra pieces of data be set up
(last activity, display name, etc). So we previously had a wrapper in
BP_UnitTestCase called create_user() that performed the extra setup.
However, the wrapper made it impossible to use create_user() statically,
because the user_login and user_email iterator was not persistent from call to
call. (The create_user() syntax is also a break with the rest of our unit
tests, which is not ideal.)

This changeset introduces BP_UnitTest_Factory_For_User, which reproduces the
customizations of create_user(), but in a proper factory method. All
instances of create_user() throughout the test suite have also been replaced.

See #6009.

File:
1 edited

Legend:

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

    r9120 r9139  
    132132     */
    133133    public function test_bp_group_has_members_vanilla() {
    134         $u1 = $this->create_user();
    135         $u2 = $this->create_user();
     134        $u1 = $this->factory->user->create();
     135        $u2 = $this->factory->user->create();
    136136        $g  = $this->factory->group->create( array(
    137137            'creator_id' => $u1,
     
    160160     */
    161161    public function test_bp_group_has_members_backpat_retval_format() {
    162         $u1 = $this->create_user();
    163         $u2 = $this->create_user();
     162        $u1 = $this->factory->user->create();
     163        $u2 = $this->factory->user->create();
    164164        $g = $this->factory->group->create( array( 'creator_id' => $u2 ) );
    165165
     
    204204        $users = array();
    205205        for ( $i = 1; $i <= 10; $i++ ) {
    206             $users[ $i ] = $this->create_user();
     206            $users[ $i ] = $this->factory->user->create();
    207207        }
    208208
     
    242242        $users = array();
    243243        for ( $i = 1; $i <= 10; $i++ ) {
    244             $users[ $i ] = $this->create_user();
     244            $users[ $i ] = $this->factory->user->create();
    245245        }
    246246
     
    265265    public function test_bp_group_has_members_with_exclude() {
    266266        $g = $this->factory->group->create();
    267         $u1 = $this->create_user();
    268         $u2 = $this->create_user();
     267        $u1 = $this->factory->user->create();
     268        $u2 = $this->factory->user->create();
    269269
    270270        $this->add_user_to_group( $u1, $g );
     
    286286    public function test_bp_group_has_members_with_exclude_admins_mods_1() {
    287287        $g = $this->factory->group->create();
    288         $u1 = $this->create_user();
    289         $u2 = $this->create_user();
    290         $u3 = $this->create_user();
     288        $u1 = $this->factory->user->create();
     289        $u2 = $this->factory->user->create();
     290        $u3 = $this->factory->user->create();
    291291
    292292        $this->add_user_to_group( $u1, $g );
     
    313313     */
    314314    public function test_bp_group_has_members_with_exclude_admins_mods_0() {
    315         $u1 = $this->create_user();
    316         $u2 = $this->create_user();
    317         $u3 = $this->create_user();
     315        $u1 = $this->factory->user->create();
     316        $u2 = $this->factory->user->create();
     317        $u3 = $this->factory->user->create();
    318318        $g = $this->factory->group->create( array(
    319319            'creator_id' => $u1,
     
    348348    public function test_bp_group_has_members_with_exclude_banned_1() {
    349349        $g = $this->factory->group->create();
    350         $u1 = $this->create_user();
    351         $u2 = $this->create_user();
     350        $u1 = $this->factory->user->create();
     351        $u2 = $this->factory->user->create();
    352352
    353353        $this->add_user_to_group( $u1, $g );
     
    371371     */
    372372    public function test_bp_group_has_members_with_exclude_banned_0() {
    373         $u1 = $this->create_user();
    374         $u2 = $this->create_user();
    375         $u3 = $this->create_user();
     373        $u1 = $this->factory->user->create();
     374        $u2 = $this->factory->user->create();
     375        $u3 = $this->factory->user->create();
    376376
    377377        $g = $this->factory->group->create( array(
     
    409409    public function test_bp_group_has_members_default_order() {
    410410        $now = time();
    411         $u1 = $this->create_user( array(
     411        $u1 = $this->factory->user->create( array(
    412412            'last_activity' => gmdate( 'Y-m-d H:i:s', $now - 60 ),
    413413        ) );
    414         $u2 = $this->create_user( array(
     414        $u2 = $this->factory->user->create( array(
    415415            'last_activity' => gmdate( 'Y-m-d H:i:s', $now - 600 ),
    416416        ) );
    417         $u3 = $this->create_user( array(
     417        $u3 = $this->factory->user->create( array(
    418418            'last_activity' => gmdate( 'Y-m-d H:i:s', $now - 6000 ),
    419419        ) );
     
    448448    public function test_bp_group_has_invites_template_structure() {
    449449        $now = time();
    450         $u1 = $this->create_user( array(
     450        $u1 = $this->factory->user->create( array(
    451451            'last_activity' => gmdate( 'Y-m-d H:i:s', $now - 60 ),
    452452        ) );
    453         $u2 = $this->create_user( array(
     453        $u2 = $this->factory->user->create( array(
    454454            'last_activity' => gmdate( 'Y-m-d H:i:s', $now - 600 ),
    455455        ) );
    456         $u3 = $this->create_user( array(
     456        $u3 = $this->factory->user->create( array(
    457457            'last_activity' => gmdate( 'Y-m-d H:i:s', $now - 6000 ),
    458458        ) );
    459         $u4 = $this->create_user( array(
     459        $u4 = $this->factory->user->create( array(
    460460            'last_activity' => gmdate( 'Y-m-d H:i:s', $now - 60000 ),
    461461        ) );
     
    528528     */
    529529    public function test_bp_group_has_invites_pagination() {
    530         $u1 = $this->create_user( array(
     530        $u1 = $this->factory->user->create( array(
    531531            'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 60 ),
    532532        ) );
     
    539539        $now = time();
    540540        for ( $i = 1; $i < 15; $i++ ) {
    541             $users[ $i ] = $this->create_user( array(
     541            $users[ $i ] = $this->factory->user->create( array(
    542542                'last_activity' => gmdate( 'Y-m-d H:i:s', $now - $i ),
    543543            ) );
     
    572572    public function test_bp_group_has_membership_requests_results() {
    573573        $now = time();
    574         $u1 = $this->create_user( array(
     574        $u1 = $this->factory->user->create( array(
    575575            'last_activity' => gmdate( 'Y-m-d H:i:s', $now - 60 ),
    576576        ) );
     
    583583        $memberships = array();
    584584        for ( $i = 1; $i < 15; $i++ ) {
    585             $users[ $i ] = $this->create_user( array(
     585            $users[ $i ] = $this->factory->user->create( array(
    586586                'last_activity' => gmdate( 'Y-m-d H:i:s', $now - ( 100 - $i ) ),
    587587            ) );
     
    636636     */
    637637    public function test_bp_group_has_membership_requests_format() {
    638         $u1 = $this->create_user( array(
     638        $u1 = $this->factory->user->create( array(
    639639            'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 60 ),
    640640        ) );
     
    646646        $time = time();
    647647
    648         $user = $this->create_user( array(
     648        $user = $this->factory->user->create( array(
    649649            'last_activity' => gmdate( 'Y-m-d H:i:s', $time ),
    650650        ) );
     
    705705    public function test_bp_group_is_user_banned_in_groups_loop() {
    706706        $now = time();
    707         $u1 = $this->create_user( array(
     707        $u1 = $this->factory->user->create( array(
    708708            'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ),
    709709        ) );
    710         $u2 = $this->create_user( array(
     710        $u2 = $this->factory->user->create( array(
    711711            'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ),
    712712        ) );
     
    758758    public function test_bp_group_is_user_banned_not_in_groups_loop() {
    759759        $now = time();
    760         $u1 = $this->create_user( array(
     760        $u1 = $this->factory->user->create( array(
    761761            'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ),
    762762        ) );
    763         $u2 = $this->create_user( array(
     763        $u2 = $this->factory->user->create( array(
    764764            'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ),
    765765        ) );
Note: See TracChangeset for help on using the changeset viewer.