Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/03/2017 07:44:10 PM (9 years ago)
Author:
boonebgorges
Message:

Use static factory method throughout PHPUnit tests.

See #7620.

File:
1 edited

Legend:

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

    r11558 r11737  
    77class BP_Tests_Groups_Functions extends BP_UnitTestCase {
    88        public function test_creating_new_group_as_authenticated_user() {
    9                 $u = $this->factory->user->create();
     9                $u = self::factory()->user->create();
    1010                wp_set_current_user( $u );
    1111
    12                 $this->factory->group->create();
     12                self::factory()->group->create();
    1313        }
    1414
     
    1818         */
    1919        public function test_total_group_count_groups_join_group() {
    20                 $u1 = $this->factory->user->create();
    21                 $u2 = $this->factory->user->create();
    22                 $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     20                $u1 = self::factory()->user->create();
     21                $u2 = self::factory()->user->create();
     22                $g = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    2323
    2424                groups_join_group( $g, $u2 );
     
    3131         */
    3232        public function test_total_group_count_groups_leave_group() {
    33                 $u1 = $this->factory->user->create();
    34                 $u2 = $this->factory->user->create();
    35                 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
    36                 $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     33                $u1 = self::factory()->user->create();
     34                $u2 = self::factory()->user->create();
     35                $g1 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
     36                $g2 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    3737                groups_join_group( $g1, $u2 );
    3838                groups_join_group( $g2, $u2 );
     
    4949         */
    5050        public function test_total_group_count_groups_ban_member() {
    51                 $u1 = $this->factory->user->create();
    52                 $u2 = $this->factory->user->create();
    53                 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
    54                 $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     51                $u1 = self::factory()->user->create();
     52                $u2 = self::factory()->user->create();
     53                $g1 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
     54                $g2 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    5555                groups_join_group( $g1, $u2 );
    5656                groups_join_group( $g2, $u2 );
     
    7070         */
    7171        public function test_total_group_count_groups_unban_member() {
    72                 $u1 = $this->factory->user->create();
    73                 $u2 = $this->factory->user->create();
    74                 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
    75                 $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     72                $u1 = self::factory()->user->create();
     73                $u2 = self::factory()->user->create();
     74                $g1 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
     75                $g2 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    7676                groups_join_group( $g1, $u2 );
    7777                groups_join_group( $g2, $u2 );
     
    9393         */
    9494        public function test_total_group_count_groups_accept_invite() {
    95                 $u1 = $this->factory->user->create();
    96                 $u2 = $this->factory->user->create();
    97                 $g = $this->factory->group->create();
     95                $u1 = self::factory()->user->create();
     96                $u2 = self::factory()->user->create();
     97                $g = self::factory()->group->create();
    9898                groups_invite_user( array(
    9999                        'user_id' => $u1,
     
    112112         */
    113113        public function test_total_group_count_groups_accept_membership_request() {
    114                 $u1 = $this->factory->user->create();
    115                 $u2 = $this->factory->user->create();
     114                $u1 = self::factory()->user->create();
     115                $u2 = self::factory()->user->create();
    116116
    117117                $current_user = bp_loggedin_user_id();
    118118                $this->set_current_user( $u2 );
    119119
    120                 $g = $this->factory->group->create();
     120                $g = self::factory()->group->create();
    121121                groups_send_membership_request( $u1, $g );
    122122
     
    133133         */
    134134        public function test_total_group_count_groups_remove_member() {
    135                 $u1 = $this->factory->user->create();
    136                 $u2 = $this->factory->user->create();
    137                 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
    138                 $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     135                $u1 = self::factory()->user->create();
     136                $u2 = self::factory()->user->create();
     137                $g1 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
     138                $g2 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    139139                groups_join_group( $g1, $u2 );
    140140                groups_join_group( $g2, $u2 );
     
    154154         */
    155155        public function test_total_member_count_groups_join_group() {
    156                 $u1 = $this->factory->user->create();
    157                 $u2 = $this->factory->user->create();
    158                 $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     156                $u1 = self::factory()->user->create();
     157                $u2 = self::factory()->user->create();
     158                $g = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    159159
    160160                groups_join_group( $g, $u2 );
     
    167167         */
    168168        public function test_total_member_count_groups_leave_group() {
    169                 $u1 = $this->factory->user->create();
    170                 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     169                $u1 = self::factory()->user->create();
     170                $g1 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    171171                groups_join_group( $g1, $u1 );
    172172
     
    180180         */
    181181        public function test_total_member_count_groups_ban_member() {
    182                 $u1 = $this->factory->user->create();
    183                 $u2 = $this->factory->user->create();
    184                 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     182                $u1 = self::factory()->user->create();
     183                $u2 = self::factory()->user->create();
     184                $g1 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    185185                groups_join_group( $g1, $u2 );
    186186
     
    199199         */
    200200        public function test_total_member_count_groups_unban_member() {
    201                 $u1 = $this->factory->user->create();
    202                 $u2 = $this->factory->user->create();
    203                 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     201                $u1 = self::factory()->user->create();
     202                $u2 = self::factory()->user->create();
     203                $g1 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    204204                groups_join_group( $g1, $u2 );
    205205
     
    220220         */
    221221        public function test_total_member_count_groups_accept_invite() {
    222                 $u1 = $this->factory->user->create();
    223                 $u2 = $this->factory->user->create();
    224                 $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     222                $u1 = self::factory()->user->create();
     223                $u2 = self::factory()->user->create();
     224                $g = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    225225                groups_invite_user( array(
    226226                        'user_id' => $u1,
     
    239239         */
    240240        public function test_total_member_count_groups_accept_membership_request() {
    241                 $u1 = $this->factory->user->create();
    242                 $u2 = $this->factory->user->create();
    243                 $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     241                $u1 = self::factory()->user->create();
     242                $u2 = self::factory()->user->create();
     243                $g = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    244244
    245245                groups_send_membership_request( $u2, $g );
     
    254254         */
    255255        public function test_total_member_count_groups_remove_member() {
    256                 $u1 = $this->factory->user->create();
    257                 $u2 = $this->factory->user->create();
    258                 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     256                $u1 = self::factory()->user->create();
     257                $u2 = self::factory()->user->create();
     258                $g1 = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    259259                groups_join_group( $g1, $u2 );
    260260
     
    273273         */
    274274        public function test_total_member_count_groups_create_group() {
    275                 $u1 = $this->factory->user->create();
     275                $u1 = self::factory()->user->create();
    276276                $g = groups_create_group( array(
    277277                        'creator_id' => $u1,
     
    291291         */
    292292        public function test_groups_create_group_dont_delete_description_for_existing_group_when_no_description_is_passed() {
    293                 $g = $this->factory->group->create();
     293                $g = self::factory()->group->create();
    294294
    295295                $group_before = groups_get_group( $g );
     
    308308         */
    309309        public function test_groups_update_groupmeta_with_line_breaks() {
    310                 $g = $this->factory->group->create();
     310                $g = self::factory()->group->create();
    311311                $meta_value = 'Foo!
    312312
     
    328328         */
    329329        public function test_groups_update_groupmeta_stripslashes() {
    330                 $g = $this->factory->group->create();
     330                $g = self::factory()->group->create();
    331331                $value = "This string is totally slashin\'!";
    332332                groups_update_groupmeta( $g, 'foo', $value );
     
    339339         */
    340340        public function test_groups_update_groupmeta_new() {
    341                 $g = $this->factory->group->create();
     341                $g = self::factory()->group->create();
    342342                $this->assertSame( '', groups_get_groupmeta( $g, 'foo' ), '"foo" meta should be empty for this group.' );
    343343                $this->assertNotEmpty( groups_update_groupmeta( $g, 'foo', 'bar' ) );
     
    349349         */
    350350        public function test_groups_update_groupmeta_existing() {
    351                 $g = $this->factory->group->create();
     351                $g = self::factory()->group->create();
    352352                groups_update_groupmeta( $g, 'foo', 'bar' );
    353353                $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo' ), '"foo" meta should be set already for this group.' );
     
    360360         */
    361361        public function test_groups_update_groupmeta_existing_same_value() {
    362                 $g = $this->factory->group->create();
     362                $g = self::factory()->group->create();
    363363                groups_update_groupmeta( $g, 'foo', 'bar' );
    364364                $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo' ), '"foo" meta should be set already for this group.' );
     
    372372         */
    373373        public function test_groups_update_groupmeta_prev_value() {
    374                 $g = $this->factory->group->create();
     374                $g = self::factory()->group->create();
    375375                groups_add_groupmeta( $g, 'foo', 'bar' );
    376376
     
    393393         */
    394394        public function test_groups_get_groupmeta_with_illegal_key_characters() {
    395                 $g = $this->factory->group->create();
     395                $g = self::factory()->group->create();
    396396                groups_update_groupmeta( $g, 'foo', 'bar' );
    397397
     
    404404         */
    405405        public function test_groups_get_groupmeta_all_metas() {
    406                 $g = $this->factory->group->create();
     406                $g = self::factory()->group->create();
    407407                groups_update_groupmeta( $g, 'foo', 'bar' );
    408408                groups_update_groupmeta( $g, 'Boone', 'is cool' );
     
    430430         */
    431431        public function test_groups_get_groupmeta_all_metas_empty() {
    432                 $g = $this->factory->group->create();
     432                $g = self::factory()->group->create();
    433433
    434434                // Get rid of any auto-created values
     
    447447         */
    448448        public function test_groups_get_groupmeta_empty() {
    449                 $g = $this->factory->group->create();
     449                $g = self::factory()->group->create();
    450450                $this->assertSame( '', groups_get_groupmeta( $g, 'foo' ) );
    451451        }
     
    456456         */
    457457        public function test_bp_activity_get_meta_single_true() {
    458                 $g = $this->factory->group->create();
     458                $g = self::factory()->group->create();
    459459                groups_add_groupmeta( $g, 'foo', 'bar' );
    460460                groups_add_groupmeta( $g, 'foo', 'baz' );
     
    468468         */
    469469        public function test_bp_activity_get_meta_single_false() {
    470                 $g = $this->factory->group->create();
     470                $g = self::factory()->group->create();
    471471                groups_add_groupmeta( $g, 'foo', 'bar' );
    472472                groups_add_groupmeta( $g, 'foo', 'baz' );
     
    480480         */
    481481        public function test_groups_get_groupmeta_cache_all_on_get() {
    482                 $g = $this->factory->group->create();
     482                $g = self::factory()->group->create();
    483483                groups_add_groupmeta( $g, 'foo', 'bar' );
    484484                groups_add_groupmeta( $g, 'foo1', 'baz' );
     
    505505         */
    506506        public function test_groups_delete_groupmeta_with_illegal_key_characters() {
    507                 $g = $this->factory->group->create();
     507                $g = self::factory()->group->create();
    508508                $this->assertNotEmpty( groups_update_groupmeta( $g, 'foo', 'bar' ), 'Value of "foo" should be set at this point.' );
    509509
     
    520520                global $wpdb;
    521521
    522                 $g = $this->factory->group->create();
     522                $g = self::factory()->group->create();
    523523                $m = groups_get_groupmeta( $g );
    524524                foreach ( $m as $mk => $mv ) {
     
    537537                // With no meta key, don't delete for all items - just delete
    538538                // all for a single item
    539                 $g1 = $this->factory->group->create();
    540                 $g2 = $this->factory->group->create();
     539                $g1 = self::factory()->group->create();
     540                $g2 = self::factory()->group->create();
    541541                groups_add_groupmeta( $g1, 'foo', 'bar' );
    542542                groups_add_groupmeta( $g1, 'foo1', 'bar1' );
     
    557557                // With no meta key, don't delete for all items - just delete
    558558                // all for a single item
    559                 $g1 = $this->factory->group->create();
    560                 $g2 = $this->factory->group->create();
     559                $g1 = self::factory()->group->create();
     560                $g2 = self::factory()->group->create();
    561561                groups_add_groupmeta( $g1, 'foo', 'bar' );
    562562                groups_add_groupmeta( $g1, 'foo1', 'bar1' );
     
    592592         */
    593593        public function test_groups_add_groupmeta_existing_unique() {
    594                 $g = $this->factory->group->create();
     594                $g = self::factory()->group->create();
    595595                groups_add_groupmeta( $g, 'foo', 'bar' );
    596596                $this->assertFalse( groups_add_groupmeta( $g, 'foo', 'baz', true ) );
     
    602602         */
    603603        public function test_groups_add_groupmeta_existing_not_unique() {
    604                 $g = $this->factory->group->create();
     604                $g = self::factory()->group->create();
    605605                groups_add_groupmeta( $g, 'foo', 'bar' );
    606606                $this->assertNotEmpty( groups_add_groupmeta( $g, 'foo', 'baz' ) );
     
    611611         */
    612612        public function test_get_invite_count_for_user() {
    613                 $u1 = $this->factory->user->create();
    614                 $u2 = $this->factory->user->create();
    615                 $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     613                $u1 = self::factory()->user->create();
     614                $u2 = self::factory()->user->create();
     615                $g = self::factory()->group->create( array( 'creator_id' => $u1 ) );
    616616
    617617                // create invitation
     
    640640         */
    641641        public function test_update_orphaned_groups_on_group_delete_top_level() {
    642                 $g1 = $this->factory->group->create();
    643                 $g2 = $this->factory->group->create( array(
     642                $g1 = self::factory()->group->create();
     643                $g2 = self::factory()->group->create( array(
    644644                        'parent_id' => $g1,
    645645                ) );
     
    655655         */
    656656        public function test_update_orphaned_groups_on_group_delete_two_levels() {
    657                 $g1 = $this->factory->group->create();
    658                 $g2 = $this->factory->group->create( array(
     657                $g1 = self::factory()->group->create();
     658                $g2 = self::factory()->group->create( array(
    659659                        'parent_id' => $g1,
    660660                ) );
    661                 $g3 = $this->factory->group->create( array(
     661                $g3 = self::factory()->group->create( array(
    662662                        'parent_id' => $g2,
    663663                ) );
     
    674674         */
    675675        public function test_groups_get_group_accept_integer() {
    676                 $g1 = $this->factory->group->create();
     676                $g1 = self::factory()->group->create();
    677677                $group = groups_get_group( $g1 );
    678678
     
    685685         */
    686686        public function test_groups_get_group_accept_numeric() {
    687                 $g1 = $this->factory->group->create();
     687                $g1 = self::factory()->group->create();
    688688                $group = groups_get_group( (string) $g1 );
    689689
     
    696696         */
    697697        public function test_groups_get_group_accept_array() {
    698                 $g1 = $this->factory->group->create();
     698                $g1 = self::factory()->group->create();
    699699                $group = groups_get_group( array( 'group_id' => $g1 ) );
    700700
     
    707707         */
    708708        public function test_groups_get_group_accept_query_string() {
    709                 $g1 = $this->factory->group->create();
     709                $g1 = self::factory()->group->create();
    710710                $group = groups_get_group( 'group_id=' . $g1 );
    711711
     
    718718         */
    719719        public function test_groups_edit_base_group_details_test_backcompat_arguments() {
    720                 $g1 = $this->factory->group->create();
     720                $g1 = self::factory()->group->create();
    721721                $name = 'Great Scott';
    722722                $description = 'A must-see in time for the holidays!';
     
    742742         */
    743743        public function test_groups_edit_base_group_details_test_new_arguments() {
    744                 $g1 = $this->factory->group->create();
     744                $g1 = self::factory()->group->create();
    745745                $name = 'Great Scott';
    746746                $slug = 'what-about-it';
     
    776776        public function test_groups_edit_base_group_details_avoid_slug_collisions() {
    777777                $slug = 'circe';
    778                 $g1 = $this->factory->group->create( array( 'slug' => $slug ) );
    779                 $g2 = $this->factory->group->create( array( 'slug' => 'loom' ) );
     778                $g1 = self::factory()->group->create( array( 'slug' => $slug ) );
     779                $g2 = self::factory()->group->create( array( 'slug' => 'loom' ) );
    780780
    781781                // Attempt to use a duplicate slug.
     
    795795        public function test_groups_edit_base_group_details_slug_no_change() {
    796796                $slug = 'circe';
    797                 $g1 = $this->factory->group->create( array( 'slug' => $slug ) );
     797                $g1 = self::factory()->group->create( array( 'slug' => $slug ) );
    798798
    799799                // Make sure the slug doesn't get incremented when there's no change.
     
    813813        public function test_groups_edit_base_group_details_slug_null_value() {
    814814                $slug = 'circe';
    815                 $g1 = $this->factory->group->create( array( 'slug' => $slug ) );
     815                $g1 = self::factory()->group->create( array( 'slug' => $slug ) );
    816816
    817817                // Make sure the slug doesn't get changed when null is passed.
     
    831831        public function test_groups_get_id_by_previous_slug() {
    832832                $slug = 'circe';
    833                 $g1 = $this->factory->group->create( array( 'slug' => $slug ) );
    834                 $g2 = $this->factory->group->create( array( 'slug' => 'loom' ) );
     833                $g1 = self::factory()->group->create( array( 'slug' => $slug ) );
     834                $g2 = self::factory()->group->create( array( 'slug' => 'loom' ) );
    835835
    836836                groups_edit_base_group_details( array(
Note: See TracChangeset for help on using the changeset viewer.