Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/27/2024 09:11:27 PM (2 years ago)
Author:
espellcaste
Message:

Include the V2 of the BP REST API in BuddyPress core.

We are officially deprecating the V1 of the BP REST API. And bundling the new, default, V2 of the BP REST API inside BuddyPress core. Previously, the V1 was developed as a plugin in a separate repo (​https://github.com/buddypress/BP-REST).

  • One of the main differences between the V1 and V2 is how objects are returned. Single items are no longer returned as an array;
  • We have a new BP_Test_REST_Controller_Testcase for testing the new API endpoints;
  • We changed the names of our controllers to follow our autoloader rules;
  • Removed the BP-REST plugin from wp-env and from our release script;
  • And we added notices for the deprecated V1 API (endpoints and files).

Props imath & I. ;)

Fixes #8200
See #9145
Closes ​https://github.com/buddypress/buddypress/pull/337

File:
1 edited

Legend:

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

    r13980 r14026  
    99         */
    1010        public function test_user_can_delete() {
    11                 $bp = buddypress();
    12                 $u = self::factory()->user->create();
     11                $bp            = buddypress();
     12                $u             = self::factory()->user->create();
    1313                $original_user = bp_loggedin_user_id();
    1414                self::set_current_user( $u );
    1515
    16                 $a = self::factory()->activity->create( array(
    17                         'type' => 'activity_update',
    18                         'user_id' => $u,
    19                 ) );
     16                $a = self::factory()->activity->create(
     17                        array(
     18                                'type'    => 'activity_update',
     19                                'user_id' => $u,
     20                        )
     21                );
    2022
    2123                // User can delete his own items
    … …  
    2830
    2931                // Miscellaneous user can't delete
    30                 $misc_user = self::factory()->user->create( array( 'role' => 'subscriber' ) );
     32                $misc_user = self::factory()->user->create();
    3133                self::set_current_user( $misc_user );
    3234                $this->assertFalse( bp_activity_user_can_delete( $activity ) );
    3335
    3436                // Item admin can delete
    35                 $is_single_item = $bp->is_single_item;
     37                $is_single_item     = $bp->is_single_item;
    3638                $bp->is_single_item = true;
    3739
    38                 $is_item_admin = $bp->is_item_admin;
     40                $is_item_admin     = $bp->is_item_admin;
    3941                $bp->is_item_admin = true;
    4042
    … …  
    4244
    4345                $bp->is_single_item = $is_single_item;
    44                 $bp->is_item_admin = $is_item_admin;
     46                $bp->is_item_admin  = $is_item_admin;
    4547                self::set_current_user( $original_user );
    4648        }
    … …  
    5254                // save the current user and override logged-in user
    5355                $old_user = get_current_user_id();
    54                 $u = self::factory()->user->create();
     56                $u        = self::factory()->user->create();
    5557                self::set_current_user( $u );
    5658
    5759                // create an activity update for the user
    58                 self::factory()->activity->create( array(
    59                         'component' => buddypress()->activity->id,
    60                         'type' => 'activity_update',
    61                         'user_id' => $u,
    62                 ) );
     60                self::factory()->activity->create(
     61                        array(
     62                                'component' => buddypress()->activity->id,
     63                                'type'      => 'activity_update',
     64                                'user_id'   => $u,
     65                        )
     66                );
    6367
    6468                // start the activity loop
    6569                bp_has_activities( array( 'user_id' => $u ) );
    66                 while ( bp_activities() ) : bp_the_activity();
     70                while ( bp_activities() ) :
     71                        bp_the_activity();
    6772                        // assert!
    6873                        $this->assertTrue( bp_activity_user_can_delete() );
    … …  
    8186         */
    8287        public function test_bp_has_activities_favorites_action_filter() {
    83                 $user_id = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    84 
    85                 $now = time();
    86 
    87                 $a1 = self::factory()->activity->create( array(
    88                         'type' => 'activity_update',
    89                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    90                 ) );
    91 
    92                 $a2 = self::factory()->activity->create( array(
    93                         'type' => 'joined_group',
    94                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    95                 ) );
     88                $user_id = self::factory()->user->create();
     89
     90                $now = time();
     91
     92                $a1 = self::factory()->activity->create(
     93                        array(
     94                                'type'          => 'activity_update',
     95                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     96                        )
     97                );
     98
     99                $a2 = self::factory()->activity->create(
     100                        array(
     101                                'type'          => 'joined_group',
     102                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     103                        )
     104                );
    96105
    97106                $current_user = bp_loggedin_user_id();
    … …  
    107116
    108117                // Case 1: no action filter
    109                 bp_has_activities( array(
    110                         'user_id' => $user_id,
    111                         'scope' => 'favorites',
    112                 ) );
     118                bp_has_activities(
     119                        array(
     120                                'user_id' => $user_id,
     121                                'scope'   => 'favorites',
     122                        )
     123                );
    113124
    114125                // The formatting of $activities_template->activities is messed
    … …  
    122133
    123134                // Case 2: action filter
    124                 bp_has_activities( array(
    125                         'user_id' => $user_id,
    126                         'scope' => 'favorites',
    127                         'action' => 'activity_update',
    128                 ) );
     135                bp_has_activities(
     136                        array(
     137                                'user_id' => $user_id,
     138                                'scope'   => 'favorites',
     139                                'action'  => 'activity_update',
     140                        )
     141                );
    129142
    130143                $ids = wp_list_pluck( $activities_template->activities, 'id' );
    … …  
    151164
    152165                // activity item
    153                 $a1 = self::factory()->activity->create( array(
    154                         'user_id'   => $u1,
    155                         'component' => 'activity',
    156                         'type'      => 'activity_update',
    157                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    158                 ) );
     166                $a1 = self::factory()->activity->create(
     167                        array(
     168                                'user_id'       => $u1,
     169                                'component'     => 'activity',
     170                                'type'          => 'activity_update',
     171                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     172                        )
     173                );
    159174
    160175                // misc activity items
    161176
    162                 self::factory()->activity->create( array(
    163                         'user_id'   => $u2,
    164                         'component' => 'activity',
    165                         'type'      => 'activity_update',
    166                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    167                 ) );
    168                 self::factory()->activity->create( array(
    169                         'user_id'   => $u2,
    170                         'component' => 'groups',
    171                         'item_id'   => 324,
    172                         'type'      => 'activity_update',
    173                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    174                 ) );
     177                self::factory()->activity->create(
     178                        array(
     179                                'user_id'       => $u2,
     180                                'component'     => 'activity',
     181                                'type'          => 'activity_update',
     182                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     183                        )
     184                );
     185                self::factory()->activity->create(
     186                        array(
     187                                'user_id'       => $u2,
     188                                'component'     => 'groups',
     189                                'item_id'       => 324,
     190                                'type'          => 'activity_update',
     191                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     192                        )
     193                );
    175194
    176195                global $activities_template;
    … …  
    178197                // grab just-me scope with no user ID
    179198                // user ID should fallback to logged-in user ID
    180                 bp_has_activities( array(
    181                         'user_id' => false,
    182                         'scope' => 'just-me',
    183                 ) );
     199                bp_has_activities(
     200                        array(
     201                                'user_id' => false,
     202                                'scope'   => 'just-me',
     203                        )
     204                );
    184205
    185206                // assert!
    … …  
    204225                // mentioned activity item
    205226                $mention_username = '@' . bp_activity_get_user_mentionname( $u1 );
    206                 $a1 = self::factory()->activity->create( array(
    207                         'user_id' => $u2,
    208                         'type'    => 'activity_update',
    209                         'content' => "{$mention_username} - You rule, dude!",
    210                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    211                 ) );
     227                $a1               = self::factory()->activity->create(
     228                        array(
     229                                'user_id'       => $u2,
     230                                'type'          => 'activity_update',
     231                                'content'       => "{$mention_username} - You rule, dude!",
     232                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     233                        )
     234                );
    212235
    213236                // misc activity items
    214                 self::factory()->activity->create( array(
    215                         'user_id'   => $u1,
    216                         'component' => 'blogs',
    217                         'item_id'   => 1,
    218                         'type'      => 'new_blog_post',
    219                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    220                 ) );
    221                 self::factory()->activity->create( array(
    222                         'user_id'   => $u2,
    223                         'component' => 'activity',
    224                         'type'      => 'activity_update',
    225                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    226                 ) );
    227                 self::factory()->activity->create( array(
    228                         'user_id'   => $u2,
    229                         'component' => 'groups',
    230                         'item_id'   => 324,
    231                         'type'      => 'activity_update',
    232                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    233                 ) );
     237                self::factory()->activity->create(
     238                        array(
     239                                'user_id'       => $u1,
     240                                'component'     => 'blogs',
     241                                'item_id'       => 1,
     242                                'type'          => 'new_blog_post',
     243                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     244                        )
     245                );
     246                self::factory()->activity->create(
     247                        array(
     248                                'user_id'       => $u2,
     249                                'component'     => 'activity',
     250                                'type'          => 'activity_update',
     251                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     252                        )
     253                );
     254                self::factory()->activity->create(
     255                        array(
     256                                'user_id'       => $u2,
     257                                'component'     => 'groups',
     258                                'item_id'       => 324,
     259                                'type'          => 'activity_update',
     260                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     261                        )
     262                );
    234263
    235264                global $activities_template;
    236265
    237266                // grab activities from multiple scopes
    238                 bp_has_activities( array(
    239                         'user_id' => $u1,
    240                         'scope' => 'mentions',
    241                 ) );
     267                bp_has_activities(
     268                        array(
     269                                'user_id' => $u1,
     270                                'scope'   => 'mentions',
     271                        )
     272                );
    242273
    243274                // assert!
    … …  
    264295
    265296                // friend status update
    266                 $a1 = self::factory()->activity->create( array(
    267                         'user_id' => $u2,
    268                         'type' => 'activity_update',
    269                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    270                 ) );
     297                $a1 = self::factory()->activity->create(
     298                        array(
     299                                'user_id'       => $u2,
     300                                'type'          => 'activity_update',
     301                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     302                        )
     303                );
    271304
    272305                // mentioned item by non-friend
    273306                $mention_username = '@' . bp_activity_get_user_mentionname( $u1 );
    274                 $a2 = self::factory()->activity->create( array(
    275                         'user_id'   => $u3,
    276                         'component' => 'activity',
    277                         'type'      => 'activity_update',
    278                         'content'   => "{$mention_username} - Oy!",
    279                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    280                 ) );
     307                $a2               = self::factory()->activity->create(
     308                        array(
     309                                'user_id'       => $u3,
     310                                'component'     => 'activity',
     311                                'type'          => 'activity_update',
     312                                'content'       => "{$mention_username} - Oy!",
     313                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     314                        )
     315                );
    281316
    282317                // misc activity items
    283                 self::factory()->activity->create( array(
    284                         'user_id'   => $u1,
    285                         'component' => 'blogs',
    286                         'item_id'   => 1,
    287                         'type'      => 'new_blog_post',
    288                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    289                 ) );
    290                 self::factory()->activity->create( array(
    291                         'user_id'   => $u3,
    292                         'component' => 'activity',
    293                         'type'      => 'activity_update',
    294                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    295                 ) );
    296                 self::factory()->activity->create( array(
    297                         'user_id'   => $u3,
    298                         'component' => 'groups',
    299                         'item_id'   => 324,
    300                         'type'      => 'activity_update',
    301                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    302                 ) );
     318                self::factory()->activity->create(
     319                        array(
     320                                'user_id'       => $u1,
     321                                'component'     => 'blogs',
     322                                'item_id'       => 1,
     323                                'type'          => 'new_blog_post',
     324                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     325                        )
     326                );
     327                self::factory()->activity->create(
     328                        array(
     329                                'user_id'       => $u3,
     330                                'component'     => 'activity',
     331                                'type'          => 'activity_update',
     332                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     333                        )
     334                );
     335                self::factory()->activity->create(
     336                        array(
     337                                'user_id'       => $u3,
     338                                'component'     => 'groups',
     339                                'item_id'       => 324,
     340                                'type'          => 'activity_update',
     341                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     342                        )
     343                );
    303344
    304345                global $activities_template;
    305346
    306347                // grab activities from multiple scopes
    307                 bp_has_activities( array(
    308                         'user_id' => $u1,
    309                         'scope' => 'mentions,friends',
    310                 ) );
     348                bp_has_activities(
     349                        array(
     350                                'user_id' => $u1,
     351                                'scope'   => 'mentions,friends',
     352                        )
     353                );
    311354
    312355                // assert!
    … …  
    337380
    338381                // friend status update
    339                 $a1 = self::factory()->activity->create( array(
    340                         'user_id' => $u2,
    341                         'type' => 'activity_update',
    342                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    343                 ) );
     382                $a1 = self::factory()->activity->create(
     383                        array(
     384                                'user_id'       => $u2,
     385                                'type'          => 'activity_update',
     386                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     387                        )
     388                );
    344389
    345390                // group activity
    346                 $a2 = self::factory()->activity->create( array(
    347                         'user_id'   => $u3,
    348                         'component' => 'groups',
    349                         'item_id'   => $g1,
    350                         'type'      => 'joined_group',
    351                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    352                 ) );
     391                $a2 = self::factory()->activity->create(
     392                        array(
     393                                'user_id'       => $u3,
     394                                'component'     => 'groups',
     395                                'item_id'       => $g1,
     396                                'type'          => 'joined_group',
     397                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     398                        )
     399                );
    353400
    354401                // misc activity items
    355                 self::factory()->activity->create( array(
    356                         'user_id'   => $u3,
    357                         'component' => 'blogs',
    358                         'item_id'   => 1,
    359                         'type'      => 'new_blog_post',
    360                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    361                 ) );
    362                 self::factory()->activity->create( array(
    363                         'user_id'   => $u3,
    364                         'component' => 'activity',
    365                         'type'      => 'activity_update',
    366                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    367                 ) );
     402                self::factory()->activity->create(
     403                        array(
     404                                'user_id'       => $u3,
     405                                'component'     => 'blogs',
     406                                'item_id'       => 1,
     407                                'type'          => 'new_blog_post',
     408                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     409                        )
     410                );
     411                self::factory()->activity->create(
     412                        array(
     413                                'user_id'       => $u3,
     414                                'component'     => 'activity',
     415                                'type'          => 'activity_update',
     416                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     417                        )
     418                );
    368419
    369420                // Make sure we get a fake group ID.
    370421                global $wpdb, $bp;
    371422                $max_group_id = $wpdb->get_var( "SELECT id FROM {$bp->groups->table_name} ORDER BY id DESC LIMIT 1" );
    372                 self::factory()->activity->create( array(
    373                         'user_id'   => $u3,
    374                         'component' => 'groups',
    375                         'item_id'   => $max_group_id + 1,
    376                         'type'      => 'activity_update',
    377                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    378                 ) );
     423                self::factory()->activity->create(
     424                        array(
     425                                'user_id'       => $u3,
     426                                'component'     => 'groups',
     427                                'item_id'       => $max_group_id + 1,
     428                                'type'          => 'activity_update',
     429                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     430                        )
     431                );
    379432
    380433                global $activities_template;
    381434
    382435                // grab activities from multiple scopes
    383                 bp_has_activities( array(
    384                         'user_id' => $u1,
    385                         'scope' => 'groups,friends',
    386                 ) );
     436                bp_has_activities(
     437                        array(
     438                                'user_id' => $u1,
     439                                'scope'   => 'groups,friends',
     440                        )
     441                );
    387442
    388443                // assert!
    … …  
    404459
    405460                // Create a random activity
    406                 self::factory()->activity->create( array(
    407                         'user_id' => $u1,
    408                         'type' => 'activity_update',
    409                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    410                 ) );
     461                self::factory()->activity->create(
     462                        array(
     463                                'user_id'       => $u1,
     464                                'type'          => 'activity_update',
     465                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     466                        )
     467                );
    411468
    412469                global $activities_template;
    … …  
    414471
    415472                // grab activities from friends scope
    416                 bp_has_activities( array(
    417                         'user_id' => $u1,
    418                         'scope' => 'friends',
    419                 ) );
     473                bp_has_activities(
     474                        array(
     475                                'user_id' => $u1,
     476                                'scope'   => 'friends',
     477                        )
     478                );
    420479
    421480                // assert!
    … …  
    437496
    438497                // Create a random activity
    439                 self::factory()->activity->create( array(
    440                         'user_id' => $u1,
    441                         'type' => 'activity_update',
    442                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    443                 ) );
     498                self::factory()->activity->create(
     499                        array(
     500                                'user_id'       => $u1,
     501                                'type'          => 'activity_update',
     502                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     503                        )
     504                );
    444505
    445506                global $activities_template;
    … …  
    447508
    448509                // grab activities from favorites scope
    449                 bp_has_activities( array(
    450                         'user_id' => $u1,
    451                         'scope' => 'favorites',
    452                 ) );
     510                bp_has_activities(
     511                        array(
     512                                'user_id' => $u1,
     513                                'scope'   => 'favorites',
     514                        )
     515                );
    453516
    454517                // assert!
    … …  
    470533
    471534                // Create a random activity
    472                 self::factory()->activity->create( array(
    473                         'user_id' => $u1,
    474                         'type' => 'activity_update',
    475                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    476                 ) );
     535                self::factory()->activity->create(
     536                        array(
     537                                'user_id'       => $u1,
     538                                'type'          => 'activity_update',
     539                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     540                        )
     541                );
    477542
    478543                global $activities_template;
    … …  
    480545
    481546                // grab activities from groups scope
    482                 bp_has_activities( array(
    483                         'user_id' => $u1,
    484                         'scope' => 'groups',
    485                 ) );
     547                bp_has_activities(
     548                        array(
     549                                'user_id' => $u1,
     550                                'scope'   => 'groups',
     551                        )
     552                );
    486553
    487554                // assert!
    … …  
    503570
    504571                // Create a random activity
    505                 self::factory()->activity->create( array(
    506                         'user_id' => $u1,
    507                         'type' => 'activity_update',
    508                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    509                 ) );
     572                self::factory()->activity->create(
     573                        array(
     574                                'user_id'       => $u1,
     575                                'type'          => 'activity_update',
     576                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     577                        )
     578                );
    510579
    511580                global $activities_template;
    … …  
    513582
    514583                // grab activities from mentions scope
    515                 bp_has_activities( array(
    516                         'user_id' => $u1,
    517                         'scope' => 'mentions',
    518                 ) );
     584                bp_has_activities(
     585                        array(
     586                                'user_id' => $u1,
     587                                'scope'   => 'mentions',
     588                        )
     589                );
    519590
    520591                // assert!
    … …  
    536607
    537608                // Friend's very fast status updates.
    538                 $a1 = self::factory()->activity->create( array(
    539                         'user_id' => $u2,
    540                         'type' => 'activity_update',
    541                         'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
    542                 ) );
    543                 $a2 = self::factory()->activity->create( array(
    544                         'user_id' => $u2,
    545                         'type' => 'activity_update',
    546                         'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
    547                 ) );
     609                $a1 = self::factory()->activity->create(
     610                        array(
     611                                'user_id'       => $u2,
     612                                'type'          => 'activity_update',
     613                                'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     614                        )
     615                );
     616                $a2 = self::factory()->activity->create(
     617                        array(
     618                                'user_id'       => $u2,
     619                                'type'          => 'activity_update',
     620                                'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     621                        )
     622                );
    548623
    549624                global $activities_template;
    … …  
    551626
    552627                // Get activities in 'friends' scope
    553                 bp_has_activities( array(
    554                         'user_id' => $u1,
    555                         'scope' => 'friends',
    556                 ) );
     628                bp_has_activities(
     629                        array(
     630                                'user_id' => $u1,
     631                                'scope'   => 'friends',
     632                        )
     633                );
    557634
    558635                $found = $activities_template->activities;
    … …  
    576653
    577654                // Two user join first user's group same time
    578                 $a1 = self::factory()->activity->create( array(
    579                         'user_id'   => $u2,
    580                         'component' => 'groups',
    581                         'item_id'   => $g1,
    582                         'type'      => 'joined_group',
    583                         'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
    584                 ) );
    585                 $a2 = self::factory()->activity->create( array(
    586                         'user_id'   => $u3,
    587                         'component' => 'groups',
    588                         'item_id'   => $g1,
    589                         'type'      => 'joined_group',
    590                         'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
    591                 ) );
     655                $a1 = self::factory()->activity->create(
     656                        array(
     657                                'user_id'       => $u2,
     658                                'component'     => 'groups',
     659                                'item_id'       => $g1,
     660                                'type'          => 'joined_group',
     661                                'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     662                        )
     663                );
     664                $a2 = self::factory()->activity->create(
     665                        array(
     666                                'user_id'       => $u3,
     667                                'component'     => 'groups',
     668                                'item_id'       => $g1,
     669                                'type'          => 'joined_group',
     670                                'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ),
     671                        )
     672                );
    592673
    593674                global $activities_template;
    … …  
    595676
    596677                // Get activities in 'groups' scope
    597                 bp_has_activities( array(
    598                         'user_id' => $u1,
    599                         'scope' => 'groups',
    600                 ) );
     678                bp_has_activities(
     679                        array(
     680                                'user_id' => $u1,
     681                                'scope'   => 'groups',
     682                        )
     683                );
    601684
    602685                $found = $activities_template->activities;
    … …  
    619702                $now = time();
    620703
    621                 $a1 = self::factory()->activity->create( array(
    622                         'user_id'   => $u3,
    623                         'component' => 'blogs',
    624                         'item_id'   => 1,
    625                         'type'      => 'new_blog_post',
    626                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    627                 ) );
    628                 $a2 = self::factory()->activity->create( array(
    629                         'user_id'   => $u2,
    630                         'component' => 'activity',
    631                         'type'      => 'activity_update',
    632                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    633                 ) );
     704                $a1 = self::factory()->activity->create(
     705                        array(
     706                                'user_id'       => $u3,
     707                                'component'     => 'blogs',
     708                                'item_id'       => 1,
     709                                'type'          => 'new_blog_post',
     710                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     711                        )
     712                );
     713                $a2 = self::factory()->activity->create(
     714                        array(
     715                                'user_id'       => $u2,
     716                                'component'     => 'activity',
     717                                'type'          => 'activity_update',
     718                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     719                        )
     720                );
    634721
    635722                // misc activity items
    636                 self::factory()->activity->create( array(
    637                         'user_id'   => $u3,
    638                         'component' => 'activity',
    639                         'type'      => 'activity_update',
    640                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    641                 ) );
    642                 self::factory()->activity->create( array(
    643                         'user_id'   => $u3,
    644                         'component' => 'groups',
    645                         'item_id'   => 324,
    646                         'type'      => 'activity_update',
    647                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    648                 ) );
    649 
    650                 global $activities_template;
    651 
    652                 bp_has_activities( array(
    653                         'filter_query' => array(
    654                                 'relation' => 'OR',
    655                                 array(
    656                                         'column' => 'component',
    657                                         'value'  => 'blogs',
    658                                 ),
    659                                 array(
    660                                         'relation' => 'AND',
     723                self::factory()->activity->create(
     724                        array(
     725                                'user_id'       => $u3,
     726                                'component'     => 'activity',
     727                                'type'          => 'activity_update',
     728                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     729                        )
     730                );
     731                self::factory()->activity->create(
     732                        array(
     733                                'user_id'       => $u3,
     734                                'component'     => 'groups',
     735                                'item_id'       => 324,
     736                                'type'          => 'activity_update',
     737                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     738                        )
     739                );
     740
     741                global $activities_template;
     742
     743                bp_has_activities(
     744                        array(
     745                                'filter_query' => array(
     746                                        'relation' => 'OR',
    661747                                        array(
    662                                                 'column' => 'type',
    663                                                 'value'  => 'activity_update',
     748                                                'column' => 'component',
     749                                                'value'  => 'blogs',
    664750                                        ),
    665751                                        array(
    666                                                 'column' => 'user_id',
    667                                                 'value'  => $u2,
     752                                                'relation' => 'AND',
     753                                                array(
     754                                                        'column' => 'type',
     755                                                        'value'  => 'activity_update',
     756                                                ),
     757                                                array(
     758                                                        'column' => 'user_id',
     759                                                        'value'  => $u2,
     760                                                ),
    668761                                        ),
    669762                                ),
    670763                        )
    671                 ) );
     764                );
    672765
    673766                // assert!
    … …  
    690783
    691784                // misc activity items
    692                 $a1 = self::factory()->activity->create( array(
    693                         'user_id'   => $u3,
    694                         'component' => 'blogs',
    695                         'item_id'   => 1,
    696                         'type'      => 'new_blog_post',
    697                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    698                 ) );
    699                 $a2 = self::factory()->activity->create( array(
    700                         'user_id'   => $u2,
    701                         'component' => 'activity',
    702                         'type'      => 'activity_update',
    703                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    704                 ) );
    705                 $a3 = self::factory()->activity->create( array(
    706                         'user_id'   => $u3,
    707                         'component' => 'activity',
    708                         'type'      => 'activity_update',
    709                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    710                 ) );
    711                 $a4 = self::factory()->activity->create( array(
    712                         'user_id'   => $u3,
    713                         'component' => 'groups',
    714                         'item_id'   => 324,
    715                         'type'      => 'activity_update',
    716                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    717                 ) );
    718 
    719                 global $activities_template;
    720 
    721                 bp_has_activities( array(
    722                         'filter_query' => array(
    723                                 array(
    724                                         'column'  => 'id',
    725                                         'compare' => 'NOT IN',
    726                                         'value'   => array( $a1, $a4 ),
     785                $a1 = self::factory()->activity->create(
     786                        array(
     787                                'user_id'       => $u3,
     788                                'component'     => 'blogs',
     789                                'item_id'       => 1,
     790                                'type'          => 'new_blog_post',
     791                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     792                        )
     793                );
     794                $a2 = self::factory()->activity->create(
     795                        array(
     796                                'user_id'       => $u2,
     797                                'component'     => 'activity',
     798                                'type'          => 'activity_update',
     799                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     800                        )
     801                );
     802                $a3 = self::factory()->activity->create(
     803                        array(
     804                                'user_id'       => $u3,
     805                                'component'     => 'activity',
     806                                'type'          => 'activity_update',
     807                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     808                        )
     809                );
     810                $a4 = self::factory()->activity->create(
     811                        array(
     812                                'user_id'       => $u3,
     813                                'component'     => 'groups',
     814                                'item_id'       => 324,
     815                                'type'          => 'activity_update',
     816                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     817                        )
     818                );
     819
     820                global $activities_template;
     821
     822                bp_has_activities(
     823                        array(
     824                                'filter_query' => array(
     825                                        array(
     826                                                'column'  => 'id',
     827                                                'compare' => 'NOT IN',
     828                                                'value'   => array( $a1, $a4 ),
     829                                        ),
    727830                                ),
    728831                        )
    729                 ) );
     832                );
    730833
    731834                // assert!
    … …  
    746849
    747850                // misc activity items
    748                 $a1 = self::factory()->activity->create( array(
    749                         'user_id'   => $u1,
    750                         'component' => 'blogs',
    751                         'item_id'   => 1,
    752                         'type'      => 'new_blog_post',
    753                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    754                 ) );
    755                 $a2 = self::factory()->activity->create( array(
    756                         'user_id'   => $u1,
    757                         'component' => 'activity',
    758                         'type'      => 'activity_update',
    759                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    760                 ) );
    761                 $a3 = self::factory()->activity->create( array(
    762                         'user_id'   => $u1,
    763                         'component' => 'activity',
    764                         'type'      => 'activity_update',
    765                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    766                 ) );
    767                 $a4 = self::factory()->activity->create( array(
    768                         'user_id'   => $u1,
    769                         'component' => 'groups',
    770                         'item_id'   => 324,
    771                         'type'      => 'activity_update',
    772                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    773                 ) );
    774 
    775                 global $activities_template;
    776 
    777                 bp_has_activities( array(
    778                         'filter_query' => array(
    779                                 array(
    780                                         'column'  => 'id',
    781                                         'compare' => 'BETWEEN',
    782                                         'value'   => array( $a3, $a4 ),
     851                $a1 = self::factory()->activity->create(
     852                        array(
     853                                'user_id'       => $u1,
     854                                'component'     => 'blogs',
     855                                'item_id'       => 1,
     856                                'type'          => 'new_blog_post',
     857                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     858                        )
     859                );
     860                $a2 = self::factory()->activity->create(
     861                        array(
     862                                'user_id'       => $u1,
     863                                'component'     => 'activity',
     864                                'type'          => 'activity_update',
     865                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     866                        )
     867                );
     868                $a3 = self::factory()->activity->create(
     869                        array(
     870                                'user_id'       => $u1,
     871                                'component'     => 'activity',
     872                                'type'          => 'activity_update',
     873                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     874                        )
     875                );
     876                $a4 = self::factory()->activity->create(
     877                        array(
     878                                'user_id'       => $u1,
     879                                'component'     => 'groups',
     880                                'item_id'       => 324,
     881                                'type'          => 'activity_update',
     882                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     883                        )
     884                );
     885
     886                global $activities_template;
     887
     888                bp_has_activities(
     889                        array(
     890                                'filter_query' => array(
     891                                        array(
     892                                                'column'  => 'id',
     893                                                'compare' => 'BETWEEN',
     894                                                'value'   => array( $a3, $a4 ),
     895                                        ),
    783896                                ),
    784897                        )
    785                 ) );
     898                );
    786899
    787900                // assert!
    … …  
    802915
    803916                // misc activity items
    804                 $a1 = self::factory()->activity->create( array(
    805                         'user_id'   => $u1,
    806                         'component' => 'activity',
    807                         'item_id'   => 1,
    808                         'type'      => 'activity_update',
    809                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    810                 ) );
    811                 $a2 = self::factory()->activity->create( array(
    812                         'user_id'   => $u1,
    813                         'component' => 'activity',
    814                         'item_id'   => 10,
    815                         'type'      => 'activity_update',
    816                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    817                 ) );
    818                 $a3 = self::factory()->activity->create( array(
    819                         'user_id'   => $u1,
    820                         'component' => 'activity',
    821                         'item_id'   => 25,
    822                         'type'      => 'activity_update',
    823                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    824                 ) );
    825                 $a4 = self::factory()->activity->create( array(
    826                         'user_id'   => $u1,
    827                         'component' => 'activity',
    828                         'item_id'   => 100,
    829                         'type'      => 'activity_update',
    830                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    831                 ) );
     917                $a1 = self::factory()->activity->create(
     918                        array(
     919                                'user_id'       => $u1,
     920                                'component'     => 'activity',
     921                                'item_id'       => 1,
     922                                'type'          => 'activity_update',
     923                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     924                        )
     925                );
     926                $a2 = self::factory()->activity->create(
     927                        array(
     928                                'user_id'       => $u1,
     929                                'component'     => 'activity',
     930                                'item_id'       => 10,
     931                                'type'          => 'activity_update',
     932                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     933                        )
     934                );
     935                $a3 = self::factory()->activity->create(
     936                        array(
     937                                'user_id'       => $u1,
     938                                'component'     => 'activity',
     939                                'item_id'       => 25,
     940                                'type'          => 'activity_update',
     941                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     942                        )
     943                );
     944                $a4 = self::factory()->activity->create(
     945                        array(
     946                                'user_id'       => $u1,
     947                                'component'     => 'activity',
     948                                'item_id'       => 100,
     949                                'type'          => 'activity_update',
     950                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     951                        )
     952                );
    832953
    833954                global $activities_template;
    834955
    835956                // greater than
    836                 bp_has_activities( array(
    837                         'filter_query' => array(
    838                                 array(
    839                                         'column'  => 'item_id',
    840                                         'compare' => '>',
    841                                         'value'   => 10,
     957                bp_has_activities(
     958                        array(
     959                                'filter_query' => array(
     960                                        array(
     961                                                'column'  => 'item_id',
     962                                                'compare' => '>',
     963                                                'value'   => 10,
     964                                        ),
    842965                                ),
    843966                        )
    844                 ) );
     967                );
    845968
    846969                // assert!
    … …  
    848971
    849972                // greater or equal than
    850                 bp_has_activities( array(
    851                         'filter_query' => array(
    852                                 array(
    853                                         'column'  => 'item_id',
    854                                         'compare' => '>=',
    855                                         'value'   => 10,
     973                bp_has_activities(
     974                        array(
     975                                'filter_query' => array(
     976                                        array(
     977                                                'column'  => 'item_id',
     978                                                'compare' => '>=',
     979                                                'value'   => 10,
     980                                        ),
    856981                                ),
    857982                        )
    858                 ) );
     983                );
    859984
    860985                // assert!
    … …  
    862987
    863988                // less than
    864                 bp_has_activities( array(
    865                         'filter_query' => array(
    866                                 array(
    867                                         'column'  => 'item_id',
    868                                         'compare' => '<',
    869                                         'value'   => 10,
     989                bp_has_activities(
     990                        array(
     991                                'filter_query' => array(
     992                                        array(
     993                                                'column'  => 'item_id',
     994                                                'compare' => '<',
     995                                                'value'   => 10,
     996                                        ),
    870997                                ),
    871998                        )
    872                 ) );
     999                );
    8731000
    8741001                // assert!
    … …  
    8761003
    8771004                // less or equal than
    878                 bp_has_activities( array(
    879                         'filter_query' => array(
    880                                 array(
    881                                         'column'  => 'item_id',
    882                                         'compare' => '<=',
    883                                         'value'   => 10,
     1005                bp_has_activities(
     1006                        array(
     1007                                'filter_query' => array(
     1008                                        array(
     1009                                                'column'  => 'item_id',
     1010                                                'compare' => '<=',
     1011                                                'value'   => 10,
     1012                                        ),
    8841013                                ),
    8851014                        )
    886                 ) );
     1015                );
    8871016
    8881017                // assert!
    … …  
    8901019
    8911020                // not equal to
    892                 bp_has_activities( array(
    893                         'filter_query' => array(
    894                                 array(
    895                                         'column'  => 'item_id',
    896                                         'compare' => '!=',
    897                                         'value'   => 10,
     1021                bp_has_activities(
     1022                        array(
     1023                                'filter_query' => array(
     1024                                        array(
     1025                                                'column'  => 'item_id',
     1026                                                'compare' => '!=',
     1027                                                'value'   => 10,
     1028                                        ),
    8981029                                ),
    8991030                        )
    900                 ) );
     1031                );
    9011032
    9021033                // assert!
    … …  
    9181049
    9191050                // misc activity items
    920                 $a1 = self::factory()->activity->create( array(
    921                         'user_id'   => $u1,
    922                         'component' => 'blogs',
    923                         'item_id'   => 1,
    924                         'type'      => 'new_blog_post',
    925                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    926                 ) );
    927                 $a2 = self::factory()->activity->create( array(
    928                         'user_id'   => $u1,
    929                         'component' => 'blogs',
    930                         'type'      => 'new_blog_comment',
    931                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    932                 ) );
    933                 $a3 = self::factory()->activity->create( array(
    934                         'user_id'   => $u1,
    935                         'component' => 'activity',
    936                         'type'      => 'activity_update',
    937                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    938                 ) );
    939                 $a4 = self::factory()->activity->create( array(
    940                         'user_id'   => $u1,
    941                         'component' => 'groups',
    942                         'item_id'   => 324,
    943                         'type'      => 'activity_update',
    944                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    945                 ) );
     1051                $a1 = self::factory()->activity->create(
     1052                        array(
     1053                                'user_id'       => $u1,
     1054                                'component'     => 'blogs',
     1055                                'item_id'       => 1,
     1056                                'type'          => 'new_blog_post',
     1057                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1058                        )
     1059                );
     1060                $a2 = self::factory()->activity->create(
     1061                        array(
     1062                                'user_id'       => $u1,
     1063                                'component'     => 'blogs',
     1064                                'type'          => 'new_blog_comment',
     1065                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1066                        )
     1067                );
     1068                $a3 = self::factory()->activity->create(
     1069                        array(
     1070                                'user_id'       => $u1,
     1071                                'component'     => 'activity',
     1072                                'type'          => 'activity_update',
     1073                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1074                        )
     1075                );
     1076                $a4 = self::factory()->activity->create(
     1077                        array(
     1078                                'user_id'       => $u1,
     1079                                'component'     => 'groups',
     1080                                'item_id'       => 324,
     1081                                'type'          => 'activity_update',
     1082                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1083                        )
     1084                );
    9461085
    9471086                global $activities_template;
    9481087
    9491088                // REGEXP
    950                 bp_has_activities( array(
    951                         'filter_query' => array(
    952                                 array(
    953                                         'column'  => 'type',
    954                                         'compare' => 'REGEXP',
    955                                         'value'   => '^new_blog_',
     1089                bp_has_activities(
     1090                        array(
     1091                                'filter_query' => array(
     1092                                        array(
     1093                                                'column'  => 'type',
     1094                                                'compare' => 'REGEXP',
     1095                                                'value'   => '^new_blog_',
     1096                                        ),
    9561097                                ),
    9571098                        )
    958                 ) );
     1099                );
    9591100
    9601101                // assert!
    … …  
    9621103
    9631104                // RLIKE is a synonym for REGEXP
    964                 bp_has_activities( array(
    965                         'filter_query' => array(
    966                                 array(
    967                                         'column'  => 'type',
    968                                         'compare' => 'RLIKE',
    969                                         'value'   => '^new_blog_',
     1105                bp_has_activities(
     1106                        array(
     1107                                'filter_query' => array(
     1108                                        array(
     1109                                                'column'  => 'type',
     1110                                                'compare' => 'RLIKE',
     1111                                                'value'   => '^new_blog_',
     1112                                        ),
    9701113                                ),
    9711114                        )
    972                 ) );
     1115                );
    9731116
    9741117                // assert!
    … …  
    9761119
    9771120                // NOT REGEXP
    978                 bp_has_activities( array(
    979                         'filter_query' => array(
    980                                 array(
    981                                         'column'  => 'type',
    982                                         'compare' => 'NOT REGEXP',
    983                                         'value'   => '^new_blog_',
     1121                bp_has_activities(
     1122                        array(
     1123                                'filter_query' => array(
     1124                                        array(
     1125                                                'column'  => 'type',
     1126                                                'compare' => 'NOT REGEXP',
     1127                                                'value'   => '^new_blog_',
     1128                                        ),
    9841129                                ),
    9851130                        )
    986                 ) );
     1131                );
    9871132
    9881133                // assert!
    … …  
    9991144        public function test_bp_has_activities_private_group_home_scope() {
    10001145                global $activities_template;
    1001                 $bp = buddypress();
    1002                 $reset_current_group = $bp->groups->current_group;
     1146                $bp                   = buddypress();
     1147                $reset_current_group  = $bp->groups->current_group;
    10031148                $reset_current_action = $bp->current_action;
    10041149
    … …  
    10091154                self::set_current_user( $u1 );
    10101155
    1011                 $g = self::factory()->group->create( array(
    1012                         'status' => 'private',
    1013                 ) );
     1156                $g = self::factory()->group->create(
     1157                        array(
     1158                                'status' => 'private',
     1159                        )
     1160                );
    10141161
    10151162                groups_join_group( $g, $u2 );
    10161163                groups_join_group( $g, $u3 );
    10171164
    1018                 $a1 = self::factory()->activity->create( array(
    1019                         'component' => $bp->groups->id,
    1020                         'item_id'   => $g,
    1021                         'type'      => 'activity_update',
    1022                         'user_id'   => $u2,
    1023                         'content'   => 'foo bar',
    1024                 ) );
    1025 
    1026                 $a2 = self::factory()->activity->create( array(
    1027                         'component' => $bp->groups->id,
    1028                         'item_id'   => $g,
    1029                         'type'      => 'activity_update',
    1030                         'user_id'   => $u3,
    1031                         'content'   => 'bar foo',
    1032                 ) );
     1165                $a1 = self::factory()->activity->create(
     1166                        array(
     1167                                'component' => $bp->groups->id,
     1168                                'item_id'   => $g,
     1169                                'type'      => 'activity_update',
     1170                                'user_id'   => $u2,
     1171                                'content'   => 'foo bar',
     1172                        )
     1173                );
     1174
     1175                $a2 = self::factory()->activity->create(
     1176                        array(
     1177                                'component' => $bp->groups->id,
     1178                                'item_id'   => $g,
     1179                                'type'      => 'activity_update',
     1180                                'user_id'   => $u3,
     1181                                'content'   => 'bar foo',
     1182                        )
     1183                );
    10331184
    10341185                $bp->groups->current_group = groups_get_group( $g );
    … …  
    10421193
    10431194                // clean up!
    1044                 $activities_template = null;
     1195                $activities_template       = null;
    10451196                $bp->groups->current_group = $reset_current_group;
    1046                 $bp->current_action = $reset_current_action;
     1197                $bp->current_action        = $reset_current_action;
    10471198        }
    10481199
    … …  
    10531204        public function test_bp_has_activities_hidden_group_home_scope() {
    10541205                global $activities_template;
    1055                 $bp = buddypress();
    1056                 $reset_current_group = $bp->groups->current_group;
     1206                $bp                   = buddypress();
     1207                $reset_current_group  = $bp->groups->current_group;
    10571208                $reset_current_action = $bp->current_action;
    10581209
    … …  
    10631214                self::set_current_user( $u1 );
    10641215
    1065                 $g = self::factory()->group->create( array(
    1066                         'status' => 'hidden',
    1067                 ) );
     1216                $g = self::factory()->group->create(
     1217                        array(
     1218                                'status' => 'hidden',
     1219                        )
     1220                );
    10681221
    10691222                groups_join_group( $g, $u2 );
    10701223                groups_join_group( $g, $u3 );
    10711224
    1072                 $a1 = self::factory()->activity->create( array(
    1073                         'component' => $bp->groups->id,
    1074                         'item_id'   => $g,
    1075                         'type'      => 'activity_update',
    1076                         'user_id'   => $u2,
    1077                         'content'   => 'foo bar',
    1078                 ) );
    1079 
    1080                 $a2 = self::factory()->activity->create( array(
    1081                         'component' => $bp->groups->id,
    1082                         'item_id'   => $g,
    1083                         'type'      => 'activity_update',
    1084                         'user_id'   => $u3,
    1085                         'content'   => 'bar foo',
    1086                 ) );
     1225                $a1 = self::factory()->activity->create(
     1226                        array(
     1227                                'component' => $bp->groups->id,
     1228                                'item_id'   => $g,
     1229                                'type'      => 'activity_update',
     1230                                'user_id'   => $u2,
     1231                                'content'   => 'foo bar',
     1232                        )
     1233                );
     1234
     1235                $a2 = self::factory()->activity->create(
     1236                        array(
     1237                                'component' => $bp->groups->id,
     1238                                'item_id'   => $g,
     1239                                'type'      => 'activity_update',
     1240                                'user_id'   => $u3,
     1241                                'content'   => 'bar foo',
     1242                        )
     1243                );
    10871244
    10881245                $bp->groups->current_group = groups_get_group( $g );
    … …  
    10961253
    10971254                // clean up!
    1098                 $activities_template = null;
     1255                $activities_template       = null;
    10991256                $bp->groups->current_group = $reset_current_group;
    1100                 $bp->current_action = $reset_current_action;
     1257                $bp->current_action        = $reset_current_action;
    11011258        }
    11021259
    … …  
    11101267
    11111268                global $activities_template;
    1112                 bp_has_activities( array(
    1113                         'meta_query' => array(
    1114                                 array(
    1115                                         'key' => 'foo',
    1116                                         'value' => 'bar',
     1269                bp_has_activities(
     1270                        array(
     1271                                'meta_query' => array(
     1272                                        array(
     1273                                                'key'   => 'foo',
     1274                                                'value' => 'bar',
     1275                                        ),
    11171276                                ),
    1118                         ),
    1119                 ) );
     1277                        )
     1278                );
    11201279
    11211280                $ids = wp_list_pluck( $activities_template->activities, 'id' );
    … …  
    11291288        public function test_bp_has_activities_with_display_comments_false() {
    11301289                $now = time();
    1131                 $a1 = self::factory()->activity->create( array(
    1132                         'content' => 'Life Rules',
    1133                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1134                 ) );
    1135                 $a2 = self::factory()->activity->create( array(
    1136                         'content' => 'Life Drools',
    1137                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1138                 ) );
    1139                 $a3 = bp_activity_new_comment( array(
    1140                         'activity_id' => $a1,
    1141                         'content' => 'Candy is good',
    1142                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
    1143                 ) );
    1144 
    1145                 global $activities_template;
    1146                 bp_has_activities( array(
    1147                         'display_comments' => false,
    1148                 ) );
     1290                $a1  = self::factory()->activity->create(
     1291                        array(
     1292                                'content'       => 'Life Rules',
     1293                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1294                        )
     1295                );
     1296                $a2  = self::factory()->activity->create(
     1297                        array(
     1298                                'content'       => 'Life Drools',
     1299                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1300                        )
     1301                );
     1302                $a3  = bp_activity_new_comment(
     1303                        array(
     1304                                'activity_id'   => $a1,
     1305                                'content'       => 'Candy is good',
     1306                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     1307                        )
     1308                );
     1309
     1310                global $activities_template;
     1311                bp_has_activities(
     1312                        array(
     1313                                'display_comments' => false,
     1314                        )
     1315                );
    11491316                $ids = wp_list_pluck( $activities_template->activities, 'id' );
    11501317
    11511318                $this->assertEquals( array( $a1, $a2 ), wp_parse_id_list( $ids ) );
    1152 
    11531319        }
    11541320
    … …  
    11591325        public function test_bp_has_activities_with_display_comments_0() {
    11601326                $now = time();
    1161                 $a1 = self::factory()->activity->create( array(
    1162                         'content' => 'Life Rules',
    1163                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1164                 ) );
    1165                 $a2 = self::factory()->activity->create( array(
    1166                         'content' => 'Life Drools',
    1167                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1168                 ) );
    1169                 $a3 = bp_activity_new_comment( array(
    1170                         'activity_id' => $a1,
    1171                         'content' => 'Candy is good',
    1172                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
    1173                 ) );
    1174 
    1175                 global $activities_template;
    1176                 bp_has_activities( array(
    1177                         'display_comments' => 0,
    1178                 ) );
     1327                $a1  = self::factory()->activity->create(
     1328                        array(
     1329                                'content'       => 'Life Rules',
     1330                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1331                        )
     1332                );
     1333                $a2  = self::factory()->activity->create(
     1334                        array(
     1335                                'content'       => 'Life Drools',
     1336                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1337                        )
     1338                );
     1339                $a3  = bp_activity_new_comment(
     1340                        array(
     1341                                'activity_id'   => $a1,
     1342                                'content'       => 'Candy is good',
     1343                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     1344                        )
     1345                );
     1346
     1347                global $activities_template;
     1348                bp_has_activities(
     1349                        array(
     1350                                'display_comments' => 0,
     1351                        )
     1352                );
    11791353                $ids = wp_list_pluck( $activities_template->activities, 'id' );
    11801354
    11811355                $this->assertEquals( array( $a1, $a2 ), wp_parse_id_list( $ids ) );
    1182 
    11831356        }
    11841357
    … …  
    11891362        public function test_bp_has_activities_with_display_comments_0_querystring() {
    11901363                $now = time();
    1191                 $a1 = self::factory()->activity->create( array(
    1192                         'content' => 'Life Rules',
    1193                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1194                 ) );
    1195                 $a2 = self::factory()->activity->create( array(
    1196                         'content' => 'Life Drools',
    1197                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1198                 ) );
    1199                 $a3 = bp_activity_new_comment( array(
    1200                         'activity_id' => $a1,
    1201                         'content' => 'Candy is good',
    1202                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
    1203                 ) );
     1364                $a1  = self::factory()->activity->create(
     1365                        array(
     1366                                'content'       => 'Life Rules',
     1367                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1368                        )
     1369                );
     1370                $a2  = self::factory()->activity->create(
     1371                        array(
     1372                                'content'       => 'Life Drools',
     1373                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1374                        )
     1375                );
     1376                $a3  = bp_activity_new_comment(
     1377                        array(
     1378                                'activity_id'   => $a1,
     1379                                'content'       => 'Candy is good',
     1380                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     1381                        )
     1382                );
    12041383
    12051384                global $activities_template;
    … …  
    12081387
    12091388                $this->assertEquals( array( $a1, $a2 ), $ids );
    1210 
    12111389        }
    12121390
    … …  
    12171395        public function test_bp_has_activities_with_display_comments_none_querystring() {
    12181396                $now = time();
    1219                 $a1 = self::factory()->activity->create( array(
    1220                         'content' => 'Life Rules',
    1221                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1222                 ) );
    1223                 $a2 = self::factory()->activity->create( array(
    1224                         'content' => 'Life Drools',
    1225                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1226                 ) );
    1227                 $a3 = bp_activity_new_comment( array(
    1228                         'activity_id' => $a1,
    1229                         'content' => 'Candy is good',
    1230                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
    1231                 ) );
     1397                $a1  = self::factory()->activity->create(
     1398                        array(
     1399                                'content'       => 'Life Rules',
     1400                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1401                        )
     1402                );
     1403                $a2  = self::factory()->activity->create(
     1404                        array(
     1405                                'content'       => 'Life Drools',
     1406                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1407                        )
     1408                );
     1409                $a3  = bp_activity_new_comment(
     1410                        array(
     1411                                'activity_id'   => $a1,
     1412                                'content'       => 'Candy is good',
     1413                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     1414                        )
     1415                );
    12321416
    12331417                global $activities_template;
    … …  
    12361420
    12371421                $this->assertEquals( array( $a1, $a2 ), $ids );
    1238 
    12391422        }
    12401423
    … …  
    12451428        public function test_bp_has_activities_with_update_meta_cache_false() {
    12461429                $now = time();
    1247                 $a1 = self::factory()->activity->create( array(
    1248                         'content' => 'Life Rules',
    1249                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1250                 ) );
    1251                 $a2 = self::factory()->activity->create( array(
    1252                         'content' => 'Life Drools',
    1253                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1254                 ) );
     1430                $a1  = self::factory()->activity->create(
     1431                        array(
     1432                                'content'       => 'Life Rules',
     1433                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1434                        )
     1435                );
     1436                $a2  = self::factory()->activity->create(
     1437                        array(
     1438                                'content'       => 'Life Drools',
     1439                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1440                        )
     1441                );
    12551442
    12561443                bp_activity_add_meta( $a1, 'foo', 'bar' );
    … …  
    12581445
    12591446                // prime
    1260                 bp_has_activities( array(
    1261                         'update_meta_cache' => false,
    1262                 ) );
     1447                bp_has_activities(
     1448                        array(
     1449                                'update_meta_cache' => false,
     1450                        )
     1451                );
    12631452
    12641453                $this->assertFalse( wp_cache_get( $a1, 'activity_meta' ) );
    … …  
    12721461        public function test_bp_has_activities_with_update_meta_cache_true() {
    12731462                $now = time();
    1274                 $a1 = self::factory()->activity->create( array(
    1275                         'content' => 'Life Rules',
    1276                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1277                 ) );
    1278                 $a2 = self::factory()->activity->create( array(
    1279                         'content' => 'Life Drools',
    1280                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1281                 ) );
     1463                $a1  = self::factory()->activity->create(
     1464                        array(
     1465                                'content'       => 'Life Rules',
     1466                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1467                        )
     1468                );
     1469                $a2  = self::factory()->activity->create(
     1470                        array(
     1471                                'content'       => 'Life Drools',
     1472                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1473                        )
     1474                );
    12821475
    12831476                bp_activity_add_meta( $a1, 'foo', 'bar' );
    … …  
    12851478
    12861479                // prime
    1287                 bp_has_activities( array(
    1288                         'update_meta_cache' => true,
    1289                 ) );
     1480                bp_has_activities(
     1481                        array(
     1482                                'update_meta_cache' => true,
     1483                        )
     1484                );
    12901485
    12911486                $this->assertNotEmpty( wp_cache_get( $a1, 'activity_meta' ) );
    … …  
    13031498
    13041499                $now = time();
    1305                 $a1 = self::factory()->activity->create( array(
    1306                         'content' => 'Life Rules',
    1307                         'component' => 'blogs',
    1308                         'type' => 'new_blog_post',
    1309                         'recorded_time' => date( 'Y-m-d H:i:s', $now ),
    1310                         'user_id' => $u,
    1311                 ) );
    1312                 $a2 = self::factory()->activity->create( array(
    1313                         'content' => 'Life Drools',
    1314                         'component' => 'blogs',
    1315                         'type' => 'new_blog_comment',
    1316                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
    1317                         'user_id' => $u,
    1318                 ) );
     1500                $a1  = self::factory()->activity->create(
     1501                        array(
     1502                                'content'       => 'Life Rules',
     1503                                'component'     => 'blogs',
     1504                                'type'          => 'new_blog_post',
     1505                                'recorded_time' => date( 'Y-m-d H:i:s', $now ),
     1506                                'user_id'       => $u,
     1507                        )
     1508                );
     1509                $a2  = self::factory()->activity->create(
     1510                        array(
     1511                                'content'       => 'Life Drools',
     1512                                'component'     => 'blogs',
     1513                                'type'          => 'new_blog_comment',
     1514                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     1515                                'user_id'       => $u,
     1516                        )
     1517                );
    13191518
    13201519                // This one will show up in the stream because it's a comment
    13211520                // on a blog post
    1322                 $a3 = bp_activity_new_comment( array(
    1323                         'activity_id' => $a1,
    1324                         'content' => 'Candy is good',
    1325                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 200 ),
    1326                         'user_id' => $u,
    1327                 ) );
    1328 
    1329                 $a4 = self::factory()->activity->create( array(
    1330                         'content' => 'Life Rulez',
    1331                         'component' => 'activity',
    1332                         'type' => 'activity_update',
    1333                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 300 ),
    1334                         'user_id' => $u,
    1335                 ) );
     1521                $a3 = bp_activity_new_comment(
     1522                        array(
     1523                                'activity_id'   => $a1,
     1524                                'content'       => 'Candy is good',
     1525                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 200 ),
     1526                                'user_id'       => $u,
     1527                        )
     1528                );
     1529
     1530                $a4 = self::factory()->activity->create(
     1531                        array(
     1532                                'content'       => 'Life Rulez',
     1533                                'component'     => 'activity',
     1534                                'type'          => 'activity_update',
     1535                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 300 ),
     1536                                'user_id'       => $u,
     1537                        )
     1538                );
    13361539
    13371540                // This one should not show up in the stream because it's a
    13381541                // comment on an activity item
    1339                 $a5 = bp_activity_new_comment( array(
    1340                         'activity_id' => $a4,
    1341                         'content' => 'Candy is great',
    1342                         'recorded_time' => date( 'Y-m-d H:i:s', $now - 400 ),
    1343                         'user_id' => $u,
    1344                 ) );
     1542                $a5 = bp_activity_new_comment(
     1543                        array(
     1544                                'activity_id'   => $a4,
     1545                                'content'       => 'Candy is great',
     1546                                'recorded_time' => date( 'Y-m-d H:i:s', $now - 400 ),
     1547                                'user_id'       => $u,
     1548                        )
     1549                );
    13451550                global $activities_template;
    13461551
    13471552                // prime
    1348                 bp_has_activities( array(
    1349                         'component' => 'blogs',
    1350                         'action' => 'new_blog_comment',
    1351                 ) );
     1553                bp_has_activities(
     1554                        array(
     1555                                'component' => 'blogs',
     1556                                'action'    => 'new_blog_comment',
     1557                        )
     1558                );
    13521559
    13531560                $this->assertEquals( array( $a3, $a2 ), wp_parse_id_list( wp_list_pluck( $activities_template->activities, 'id' ) ) );
    … …  
    13701577                // Fake the global
    13711578                global $activities_template;
    1372                 $activities_template = new stdClass;
    1373                 $activities_template->activity = new stdClass;
    1374                 $activities_template->activity->current_comment = new stdClass;
    1375 
    1376                 $comment = new stdClass;
     1579                $activities_template                            = new stdClass();
     1580                $activities_template->activity                  = new stdClass();
     1581                $activities_template->activity->current_comment = new stdClass();
     1582
     1583                $comment          = new stdClass();
    13771584                $comment->item_id = 4;
    13781585
    … …  
    14071614                // Fake the global
    14081615                global $activities_template;
    1409                 $activities_template = new stdClass;
    1410                 $activities_template->activity = new stdClass;
    1411                 $activities_template->activity->current_comment = new stdClass;
    1412 
    1413                 $comment = new stdClass;
     1616                $activities_template                            = new stdClass();
     1617                $activities_template->activity                  = new stdClass();
     1618                $activities_template->activity->current_comment = new stdClass();
     1619
     1620                $comment          = new stdClass();
    14141621                $comment->item_id = 4;
    14151622
    … …  
    14331640                $reset_activities_template = $activities_template;
    14341641
    1435                 $activities_template = new stdClass;
     1642                $activities_template                            = new stdClass();
    14361643                $activities_template->disable_blogforum_replies = true;
    1437                 $activities_template->activity = (object) array( 'type' => 'activity_comment' );
     1644                $activities_template->activity                  = (object) array( 'type' => 'activity_comment' );
    14381645
    14391646                $this->assertFalse( bp_activity_can_comment(), 'bp_activity_can_comment() should return false if the activity type is activity_comment' );
    … …  
    14431650                        'new_blog_comment',
    14441651                        'new_forum_topic',
    1445                         'new_forum_post'
     1652                        'new_forum_post',
    14461653                );
    14471654
    … …  
    14731680
    14741681                $reset_activities_template = $activities_template;
    1475                 $reset_activity_track = $bp->activity->track;
    1476 
    1477                 $activities_template = new stdClass;
     1682                $reset_activity_track      = $bp->activity->track;
     1683
     1684                $activities_template                            = new stdClass();
    14781685                $activities_template->disable_blogforum_replies = true;
    14791686
    1480                 register_post_type( 'foo', array(
    1481                         'label'   => 'foo',
    1482                         'public'   => true,
    1483                         'supports' => array( 'buddypress-activity' ),
    1484                 ) );
     1687                register_post_type(
     1688                        'foo',
     1689                        array(
     1690                                'label'    => 'foo',
     1691                                'public'   => true,
     1692                                'supports' => array( 'buddypress-activity' ),
     1693                        )
     1694                );
    14851695
    14861696                $bp->activity->track = bp_activity_get_post_types_tracking_args();
    … …  
    14961706                $this->assertFalse( bp_activity_can_comment(), 'If post type support comments, a post type activity cannot be commented' );
    14971707
    1498                 $bp_activity_support = (array) $bp->activity->track['new_foo'];
     1708                $bp_activity_support                     = (array) $bp->activity->track['new_foo'];
    14991709                $bp_activity_support['activity_comment'] = true;
    15001710
    … …  
    15381748                $args = array(
    15391749                        'count_total' => false,
    1540                         'per_page' => 2,
     1750                        'per_page'    => 2,
    15411751                );
    15421752
    … …  
    15791789                $args = array(
    15801790                        'count_total' => 'count_query',
    1581                         'per_page' => 2,
     1791                        'per_page'    => 2,
    15821792                );
    15831793
    … …  
    16011811
    16021812                $a1 = self::factory()->activity->create();
    1603                 $a2 = self::factory()->activity->create( array(
    1604                         'recorded_time' => '2001-01-01 12:00'
    1605                 ) );
    1606                 $a3 = self::factory()->activity->create( array(
    1607                         'recorded_time' => '2005-01-01 12:00'
    1608                 ) );
    1609 
    1610                 global $activities_template;
    1611                 bp_has_activities( array(
    1612                         'date_query' => array( array(
    1613                                 'after' => '1 day ago'
    1614                         ) )
    1615                 ) );
     1813                $a2 = self::factory()->activity->create(
     1814                        array(
     1815                                'recorded_time' => '2001-01-01 12:00',
     1816                        )
     1817                );
     1818                $a3 = self::factory()->activity->create(
     1819                        array(
     1820                                'recorded_time' => '2005-01-01 12:00',
     1821                        )
     1822                );
     1823
     1824                global $activities_template;
     1825                bp_has_activities(
     1826                        array(
     1827                                'date_query' => array(
     1828                                        array(
     1829                                                'after' => '1 day ago',
     1830                                        ),
     1831                                ),
     1832                        )
     1833                );
    16161834
    16171835                $ids = wp_list_pluck( $activities_template->activities, 'id' );
    … …  
    16241842         */
    16251843        public function test_bp_activity_template_should_give_precedence_to_acpage_URL_param() {
    1626                 $request = $_REQUEST;
     1844                $request            = $_REQUEST;
    16271845                $_REQUEST['acpage'] = '5';
    16281846
    1629                 $at = new BP_Activity_Template( array(
    1630                         'page' => 8,
    1631                 ) );
     1847                $at = new BP_Activity_Template(
     1848                        array(
     1849                                'page' => 8,
     1850                        )
     1851                );
    16321852
    16331853                $this->assertEquals( 5, $at->pag_page );
    … …  
    16411861         */
    16421862        public function test_bp_activity_template_should_reset_0_pag_page_URL_param_to_default_pag_page_value() {
    1643                 $request = $_REQUEST;
     1863                $request            = $_REQUEST;
    16441864                $_REQUEST['acpage'] = '0';
    16451865
    1646                 $at = new BP_Activity_Template( array(
    1647                         'page' => 8,
    1648                 ) );
     1866                $at = new BP_Activity_Template(
     1867                        array(
     1868                                'page' => 8,
     1869                        )
     1870                );
    16491871
    16501872                $this->assertEquals( 8, $at->pag_page );
    … …  
    16581880         */
    16591881        public function test_bp_activity_template_should_give_precedence_to_num_URL_param() {
    1660                 $request = $_REQUEST;
     1882                $request         = $_REQUEST;
    16611883                $_REQUEST['num'] = '14';
    16621884
    1663                 $at = new BP_Activity_Template( array(
    1664                         'per_page' => 13,
    1665                 ) );
     1885                $at = new BP_Activity_Template(
     1886                        array(
     1887                                'per_page' => 13,
     1888                        )
     1889                );
    16661890
    16671891                $this->assertEquals( 14, $at->pag_num );
    … …  
    16751899         */
    16761900        public function test_bp_activity_template_should_reset_0_pag_num_URL_param_to_default_pag_num_value() {
    1677                 $request = $_REQUEST;
     1901                $request         = $_REQUEST;
    16781902                $_REQUEST['num'] = '0';
    16791903
    1680                 $at = new BP_Activity_Template( array(
    1681                         'per_page' => 13,
    1682                 ) );
     1904                $at = new BP_Activity_Template(
     1905                        array(
     1906                                'per_page' => 13,
     1907                        )
     1908                );
    16831909
    16841910                $this->assertEquals( 13, $at->pag_num );
Note: See TracChangeset for help on using the changeset viewer.