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/core/class-bp-user-query.php

    r9051 r9139  
    2424     */
    2525    public function test_bp_user_query_friends() {
    26         $u1 = $this->create_user();
    27         $u2 = $this->create_user();
    28         $u3 = $this->create_user();
     26        $u1 = $this->factory->user->create();
     27        $u2 = $this->factory->user->create();
     28        $u3 = $this->factory->user->create();
    2929        friends_add_friend( $u1, $u2, true );
    3030
     
    4242     */
    4343    public function test_bp_user_query_friends_with_include() {
    44         $u1 = $this->create_user();
    45         $u2 = $this->create_user();
    46         $u3 = $this->create_user();
    47         $u4 = $this->create_user();
     44        $u1 = $this->factory->user->create();
     45        $u2 = $this->factory->user->create();
     46        $u3 = $this->factory->user->create();
     47        $u4 = $this->factory->user->create();
    4848        friends_add_friend( $u1, $u2, true );
    4949        friends_add_friend( $u1, $u3, true );
     
    6363
    6464    public function test_bp_user_query_friends_with_include_but_zero_friends() {
    65         $u1 = $this->create_user();
    66         $u2 = $this->create_user();
    67         $u3 = $this->create_user();
    68         $u4 = $this->create_user();
     65        $u1 = $this->factory->user->create();
     66        $u2 = $this->factory->user->create();
     67        $u3 = $this->factory->user->create();
     68        $u4 = $this->factory->user->create();
    6969
    7070        $q = new BP_User_Query( array(
     
    8282
    8383    public function test_bp_user_query_sort_by_popular() {
    84         $u1 = $this->create_user();
    85         $u2 = $this->create_user();
    86         $u3 = $this->create_user();
    87         $u4 = $this->create_user();
     84        $u1 = $this->factory->user->create();
     85        $u2 = $this->factory->user->create();
     86        $u3 = $this->factory->user->create();
     87        $u4 = $this->factory->user->create();
    8888
    8989        bp_update_user_meta( $u1, bp_get_user_meta_key( 'total_friend_count' ), '5' );
     
    108108    public function test_bp_user_query_type_online() {
    109109        $now = time();
    110         $u1 = $this->create_user( array(
     110        $u1 = $this->factory->user->create( array(
    111111            'last_activity' => date( 'Y-m-d H:i:s', $now ),
    112112        ) );
    113         $u2 = $this->create_user( array(
     113        $u2 = $this->factory->user->create( array(
    114114            'last_activity' => date( 'Y-m-d H:i:s', $now - 60*13 ),
    115115        ) );
    116         $u3 = $this->create_user( array(
     116        $u3 = $this->factory->user->create( array(
    117117            'last_activity' => date( 'Y-m-d H:i:s', $now - 60*16 ),
    118118        ) );
     
    132132    public function test_bp_user_query_type_online_five_minute_interval() {
    133133        $now = time();
    134         $u1 = $this->create_user( array(
     134        $u1 = $this->factory->user->create( array(
    135135            'last_activity' => date( 'Y-m-d H:i:s', $now ),
    136136        ) );
    137         $u2 = $this->create_user( array(
     137        $u2 = $this->factory->user->create( array(
    138138            'last_activity' => date( 'Y-m-d H:i:s', $now - 60*4 ),
    139139        ) );
    140         $u3 = $this->create_user( array(
     140        $u3 = $this->factory->user->create( array(
    141141            'last_activity' => date( 'Y-m-d H:i:s', $now - 60*6 ),
    142142        ) );
     
    156156    public function test_bp_user_query_search_with_apostrophe() {
    157157        // Apostrophe. Search_terms must escaped to mimic POST payload
    158         $user_id = $this->create_user();
     158        $user_id = $this->factory->user->create();
    159159        xprofile_set_field_data( 1, $user_id, "Foo'Bar" );
    160160        $q = new BP_User_Query( array( 'search_terms' => "oo\'Ba", ) );
     
    172172
    173173        // LIKE special character: %
    174         $user_id = $this->create_user();
     174        $user_id = $this->factory->user->create();
    175175        xprofile_set_field_data( 1, $user_id, "Foo%Bar" );
    176176        $q = new BP_User_Query( array( 'search_terms' => "oo%Bar", ) );
     
    189189
    190190        // LIKE special character: _
    191         $user_id = $this->create_user();
     191        $user_id = $this->factory->user->create();
    192192        xprofile_set_field_data( 1, $user_id, "Foo_Bar" );
    193193        $q = new BP_User_Query( array( 'search_terms' => "oo_Bar", ) );
     
    205205
    206206        // LIKE special character: &
    207         $user_id = $this->create_user();
     207        $user_id = $this->factory->user->create();
    208208        xprofile_set_field_data( 1, $user_id, "a&mpersand" );
    209209        $q = new BP_User_Query( array( 'search_terms' => "a&m", ) );
     
    223223     */
    224224    public function test_bp_user_query_search_core_fields() {
    225         $user_id = $this->create_user( array(
     225        $user_id = $this->factory->user->create( array(
    226226            'user_login' => 'foo',
    227227        ) );
     
    239239
    240240    public function test_bp_user_query_search_wildcards() {
    241         $u1 = $this->create_user( array(
     241        $u1 = $this->factory->user->create( array(
    242242            'user_login' => 'xfoo',
    243243        ) );
     
    245245        $q1 = new BP_User_Query( array( 'search_terms' => 'foo', 'search_wildcard' => 'left' ) );
    246246
    247         $u2 = $this->create_user( array(
     247        $u2 = $this->factory->user->create( array(
    248248            'user_login' => 'foox',
    249249        ) );
     
    251251        $q2 = new BP_User_Query( array( 'search_terms' => 'foo', 'search_wildcard' => 'right' ) );
    252252
    253         $u3 = $this->create_user( array(
     253        $u3 = $this->factory->user->create( array(
    254254            'user_login' => 'xfoox',
    255255        ) );
     
    279279        $existing_users = $wpdb->get_col( "SELECT ID FROM {$wpdb->users}" );
    280280
    281         $u1 = $this->create_user();
    282         $u2 = $this->create_user();
     281        $u1 = $this->factory->user->create();
     282        $u2 = $this->factory->user->create();
    283283
    284284        $exclude = array_merge( array( $u1 ), $existing_users );
     
    307307        add_filter( 'bp_disable_profile_sync', '__return_false' );
    308308
    309         $u1 = $this->create_user();
    310         $u2 = $this->create_user();
     309        $u1 = $this->factory->user->create();
     310        $u2 = $this->factory->user->create();
    311311
    312312        global $wpdb;
     
    338338     */
    339339    public function test_bp_user_query_type_alphabetical_spam_xprofileoff() {
    340         $u1 = $this->create_user();
    341         $u2 = $this->create_user();
     340        $u1 = $this->factory->user->create();
     341        $u2 = $this->factory->user->create();
    342342
    343343        // Make sure xprofile and profile sync are off
     
    373373     */
    374374    public function test_bp_user_query_with_user_meta_argument() {
    375         $u1 = $this->create_user();
    376         $u2 = $this->create_user();
     375        $u1 = $this->factory->user->create();
     376        $u2 = $this->factory->user->create();
    377377
    378378        bp_update_user_meta( $u2, 'foo', 'bar' );
     
    395395     */
    396396    public function test_bp_user_query_with_user_meta_argument_no_user() {
    397         $u1 = $this->create_user();
    398         $u2 = $this->create_user();
     397        $u1 = $this->factory->user->create();
     398        $u2 = $this->factory->user->create();
    399399
    400400        $q = new BP_User_Query( array(
Note: See TracChangeset for help on using the changeset viewer.