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/groups/activity.php

    r13980 r14026  
    1515                $u = self::factory()->user->create();
    1616                $g = self::factory()->group->create();
    17                 $a = self::factory()->activity->create( array(
    18                         'component' => buddypress()->groups->id,
    19                         'type' => 'created_group',
    20                         'user_id' => $u,
    21                         'item_id' => $g,
    22                 ) );
     17                $a = self::factory()->activity->create(
     18                        array(
     19                                'component' => buddypress()->groups->id,
     20                                'type'      => 'created_group',
     21                                'user_id'   => $u,
     22                                'item_id'   => $g,
     23                        )
     24                );
    2325
    2426                $a_obj = new BP_Activity_Activity( $a );
    2527                $g_obj = groups_get_group( $g );
    2628
    27                 $expected = sprintf( __( '%s created the group %s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' );
     29                $expected = sprintf( __( '%1$s created the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' );
    2830
    2931                $this->assertSame( $expected, $a_obj->action );
    … …  
    3739                $u = self::factory()->user->create();
    3840                $g = self::factory()->group->create();
    39                 $a = self::factory()->activity->create( array(
    40                         'component' => buddypress()->groups->id,
    41                         'type' => 'joined_group',
    42                         'user_id' => $u,
    43                         'item_id' => $g,
    44                 ) );
     41                $a = self::factory()->activity->create(
     42                        array(
     43                                'component' => buddypress()->groups->id,
     44                                'type'      => 'joined_group',
     45                                'user_id'   => $u,
     46                                'item_id'   => $g,
     47                        )
     48                );
    4549
    4650                $a_obj = new BP_Activity_Activity( $a );
    4751                $g_obj = groups_get_group( $g );
    4852
    49                 $expected = sprintf( __( '%s joined the group %s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' );
     53                $expected = sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . $g_obj->name . '</a>' );
    5054
    5155                $this->assertSame( $expected, $a_obj->action );
    … …  
    5862        public function test_bp_groups_format_activity_action_group_details_updated_with_no_change() {
    5963                $group = self::factory()->group->create_and_get();
    60                 groups_edit_base_group_details( array(
     64                groups_edit_base_group_details(
     65                        array(
    6166                                'group_id'       => $group->id,
    6267                                'name'           => $group->name,
    … …  
    6469                                'description'    => $group->description,
    6570                                'notify_members' => true,
    66                 ) );
    67 
    68                 $a = bp_activity_get( array(
    69                         'component' => buddypress()->groups->id,
    70                         'action' => 'group_details_updated',
    71                         'item_id' => $group->id,
    72                 ) );
     71                        )
     72                );
     73
     74                $a = bp_activity_get(
     75                        array(
     76                                'component' => buddypress()->groups->id,
     77                                'action'    => 'group_details_updated',
     78                                'item_id'   => $group->id,
     79                        )
     80                );
    7381
    7482                $this->assertTrue( empty( $a['activities'] ) );
    … …  
    8189        public function test_bp_groups_format_activity_action_group_details_updated_with_notify_members_false() {
    8290                $group = self::factory()->group->create_and_get();
    83                 groups_edit_base_group_details( array(
    84                         'group_id'       => $group->id,
    85                         'name'           => 'Foo',
    86                         'slug'           => $group->slug,
    87                         'description'    => $group->description,
    88                         'notify_members' => false,
    89                 ) );
    90 
    91                 $a = bp_activity_get( array(
    92                         'component' => buddypress()->groups->id,
    93                         'action' => 'group_details_updated',
    94                         'item_id' => $group->id,
    95                 ) );
     91                groups_edit_base_group_details(
     92                        array(
     93                                'group_id'       => $group->id,
     94                                'name'           => 'Foo',
     95                                'slug'           => $group->slug,
     96                                'description'    => $group->description,
     97                                'notify_members' => false,
     98                        )
     99                );
     100
     101                $a = bp_activity_get(
     102                        array(
     103                                'component' => buddypress()->groups->id,
     104                                'action'    => 'group_details_updated',
     105                                'item_id'   => $group->id,
     106                        )
     107                );
    96108
    97109                $this->assertTrue( empty( $a['activities'] ) );
    … …  
    104116        public function test_bp_groups_format_activity_action_group_details_updated_with_updated_name() {
    105117                $old_user = get_current_user_id();
    106                 $u = self::factory()->user->create();
     118                $u        = self::factory()->user->create();
    107119                self::set_current_user( $u );
    108120
    109121                $group = self::factory()->group->create_and_get();
    110                 groups_edit_base_group_details( array(
    111                         'group_id'       => $group->id,
    112                         'name'           => 'Foo',
    113                         'slug'           => $group->slug,
    114                         'description'    => $group->description,
    115                         'notify_members' => true,
    116                 ) );
    117 
    118                 $a = bp_activity_get( array(
    119                         'component' => buddypress()->groups->id,
    120                         'action' => 'group_details_updated',
    121                         'item_id' => $group->id,
    122                 ) );
     122                groups_edit_base_group_details(
     123                        array(
     124                                'group_id'       => $group->id,
     125                                'name'           => 'Foo',
     126                                'slug'           => $group->slug,
     127                                'description'    => $group->description,
     128                                'notify_members' => true,
     129                        )
     130                );
     131
     132                $a = bp_activity_get(
     133                        array(
     134                                'component' => buddypress()->groups->id,
     135                                'action'    => 'group_details_updated',
     136                                'item_id'   => $group->id,
     137                        )
     138                );
    123139
    124140                $this->assertNotEmpty( $a['activities'] );
    125141
    126                 $expected = sprintf( esc_html__( '%s changed the name of the group %s from "%s" to "%s"', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>', $group->name, 'Foo' );
     142                $expected = sprintf( esc_html__( '%1$s changed the name of the group %2$s from "%3$s" to "%4$s"', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>', $group->name, 'Foo' );
    127143                $this->assertSame( $expected, $a['activities'][0]->action );
    128144
    … …  
    136152        public function test_bp_groups_format_activity_action_group_details_updated_with_updated_description() {
    137153                $old_user = get_current_user_id();
    138                 $u = self::factory()->user->create();
     154                $u        = self::factory()->user->create();
    139155                self::set_current_user( $u );
    140156
    141157                $group = self::factory()->group->create_and_get();
    142                 groups_edit_base_group_details( array(
    143                         'group_id'       => $group->id,
    144                         'name'           => $group->name,
    145                         'slug'           => $group->slug,
    146                         'description'    => 'Bar',
    147                         'notify_members' => true,
    148                 ) );
    149 
    150                 $a = bp_activity_get( array(
    151                         'component' => buddypress()->groups->id,
    152                         'action' => 'group_details_updated',
    153                         'item_id' => $group->id,
    154                 ) );
     158                groups_edit_base_group_details(
     159                        array(
     160                                'group_id'       => $group->id,
     161                                'name'           => $group->name,
     162                                'slug'           => $group->slug,
     163                                'description'    => 'Bar',
     164                                'notify_members' => true,
     165                        )
     166                );
     167
     168                $a = bp_activity_get(
     169                        array(
     170                                'component' => buddypress()->groups->id,
     171                                'action'    => 'group_details_updated',
     172                                'item_id'   => $group->id,
     173                        )
     174                );
    155175
    156176                $this->assertNotEmpty( $a['activities'] );
    157177
    158                 $expected = sprintf( esc_html__( '%s changed the description of the group %s from "%s" to "%s"', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">' . $group->name . '</a>', $group->description, 'Bar' );
     178                $expected = sprintf( esc_html__( '%1$s changed the description of the group %2$s from "%3$s" to "%4$s"', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">' . $group->name . '</a>', $group->description, 'Bar' );
    159179                $this->assertSame( $expected, $a['activities'][0]->action );
    160180
    … …  
    168188        public function test_bp_groups_format_activity_action_group_details_updated_with_updated_slug() {
    169189                $old_user = get_current_user_id();
    170                 $u = self::factory()->user->create();
     190                $u        = self::factory()->user->create();
    171191                self::set_current_user( $u );
    172192
    173193                $group = self::factory()->group->create_and_get();
    174                 groups_edit_base_group_details( array(
    175                         'group_id'       => $group->id,
    176                         'name'           => $group->name,
    177                         'slug'           => 'flaxen',
    178                         'description'    => $group->description,
    179                         'notify_members' => true,
    180                 ) );
     194                groups_edit_base_group_details(
     195                        array(
     196                                'group_id'       => $group->id,
     197                                'name'           => $group->name,
     198                                'slug'           => 'flaxen',
     199                                'description'    => $group->description,
     200                                'notify_members' => true,
     201                        )
     202                );
    181203                $new_group_details = groups_get_group( $group->id );
    182204
    183                 $a = bp_activity_get( array(
    184                         'component' => buddypress()->groups->id,
    185                         'action' => 'group_details_updated',
    186                         'item_id' => $group->id,
    187                 ) );
     205                $a = bp_activity_get(
     206                        array(
     207                                'component' => buddypress()->groups->id,
     208                                'action'    => 'group_details_updated',
     209                                'item_id'   => $group->id,
     210                        )
     211                );
    188212
    189213                $this->assertNotEmpty( $a['activities'] );
    190214
    191                 $expected = sprintf( __( '%s changed the permalink of the group %s.', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $new_group_details ) ) . '">' . $group->name . '</a>' );
     215                $expected = sprintf( __( '%1$s changed the permalink of the group %2$s.', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $new_group_details ) ) . '">' . $group->name . '</a>' );
    192216                $this->assertSame( $expected, $a['activities'][0]->action );
    193217
    … …  
    201225        public function test_bp_groups_format_activity_action_group_details_updated_with_updated_name_and_description() {
    202226                $old_user = get_current_user_id();
    203                 $u = self::factory()->user->create();
     227                $u        = self::factory()->user->create();
    204228                self::set_current_user( $u );
    205229
    206230                $group = self::factory()->group->create_and_get();
    207                 groups_edit_base_group_details( array(
    208                         'group_id'       => $group->id,
    209                         'name'           => 'Foo',
    210                         'slug'           => $group->slug,
    211                         'description'    => 'Bar',
    212                         'notify_members' => true,
    213                 ) );
    214 
    215                 $a = bp_activity_get( array(
    216                         'component' => buddypress()->groups->id,
    217                         'action' => 'group_details_updated',
    218                         'item_id' => $group->id,
    219                 ) );
     231                groups_edit_base_group_details(
     232                        array(
     233                                'group_id'       => $group->id,
     234                                'name'           => 'Foo',
     235                                'slug'           => $group->slug,
     236                                'description'    => 'Bar',
     237                                'notify_members' => true,
     238                        )
     239                );
     240
     241                $a = bp_activity_get(
     242                        array(
     243                                'component' => buddypress()->groups->id,
     244                                'action'    => 'group_details_updated',
     245                                'item_id'   => $group->id,
     246                        )
     247                );
    220248
    221249                $this->assertNotEmpty( $a['activities'] );
    222250
    223                 $expected = sprintf( __( '%s changed the name and description of the group %s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>' );
     251                $expected = sprintf( __( '%1$s changed the name and description of the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $group ) ) . '">Foo</a>' );
    224252                $this->assertSame( $expected, $a['activities'][0]->action );
    225253
    … …  
    234262                $u = self::factory()->user->create();
    235263                $g = self::factory()->group->create();
    236                 $a = self::factory()->activity->create( array(
    237                         'component' => buddypress()->groups->id,
    238                         'type' => 'activity_update',
    239                         'user_id' => $u,
    240                         'item_id' => $g,
    241                 ) );
     264                $a = self::factory()->activity->create(
     265                        array(
     266                                'component' => buddypress()->groups->id,
     267                                'type'      => 'activity_update',
     268                                'user_id'   => $u,
     269                                'item_id'   => $g,
     270                        )
     271                );
    242272
    243273                $a_obj = new BP_Activity_Activity( $a );
    244274                $g_obj = groups_get_group( $g );
    245275
    246                 $expected = sprintf( esc_html__( '%1$s posted an update in the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ),  '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . esc_html( $g_obj->name ) . '</a>' );
     276                $expected = sprintf( esc_html__( '%1$s posted an update in the group %2$s', 'buddypress' ), bp_core_get_userlink( $u ), '<a href="' . esc_url( bp_get_group_url( $g_obj ) ) . '">' . esc_html( $g_obj->name ) . '</a>' );
    247277
    248278                $this->assertSame( $expected, $a_obj->action );
    … …  
    296326                );
    297327
    298                 $a = groups_post_update( $activity_args );
     328                $a     = groups_post_update( $activity_args );
    299329                $a_obj = new BP_Activity_Activity( $a );
    300330
    … …  
    310340        public function test_groups_activity_can_comment() {
    311341                $old_user = get_current_user_id();
    312                 $u1 = self::factory()->user->create();
    313                 $u2 = self::factory()->user->create();
     342                $u1       = self::factory()->user->create();
     343                $u2       = self::factory()->user->create();
    314344
    315345                $g = self::factory()->group->create();
    … …  
    318348                groups_join_group( $g, $u1 );
    319349
    320                 $a = self::factory()->activity->create( array(
    321                         'component' => buddypress()->groups->id,
    322                         'type' => 'created_group',
    323                         'user_id' => $u1,
    324                         'item_id' => $g,
    325                 ) );
     350                $a = self::factory()->activity->create(
     351                        array(
     352                                'component' => buddypress()->groups->id,
     353                                'type'      => 'created_group',
     354                                'user_id'   => $u1,
     355                                'item_id'   => $g,
     356                        )
     357                );
    326358
    327359                self::set_current_user( $u1 );
    328360                if ( bp_has_activities( array( 'in' => $a ) ) ) {
    329                         while ( bp_activities() ) : bp_the_activity();
     361                        while ( bp_activities() ) :
     362                                bp_the_activity();
    330363                                // User 1 should be able to comment.
    331364                                $this->assertTrue( bp_activity_can_comment() );
    … …  
    335368                self::set_current_user( $u2 );
    336369                if ( bp_has_activities( array( 'in' => $a ) ) ) {
    337                         while ( bp_activities() ) : bp_the_activity();
     370                        while ( bp_activities() ) :
     371                                bp_the_activity();
    338372                                // User 2 should not be able to comment.
    339373                                $this->assertFalse( bp_activity_can_comment() );
    … …  
    345379
    346380        public function groups_post_update_args( $args = array() ) {
    347                 $this->groups_post_update_args = array_intersect_key( $args, array(
    348                         'content'    => true,
    349                         'user_id'    => true,
    350                         'item_id'    => true,
    351                         'error_type' => true,
    352                 ) );
     381                $this->groups_post_update_args = array_intersect_key(
     382                        $args,
     383                        array(
     384                                'content'    => true,
     385                                'user_id'    => true,
     386                                'item_id'    => true,
     387                                'error_type' => true,
     388                        )
     389                );
    353390
    354391                return $args;
    … …  
    359396         */
    360397        public function test_user_can_delete_group_activity() {
    361                 $u1             = self::factory()->user->create();
    362                 $u2             = self::factory()->user->create();
     398                $u1            = self::factory()->user->create();
     399                $u2            = self::factory()->user->create();
    363400                $original_user = bp_loggedin_user_id();
    364401
    … …  
    416453
    417454                // Misc user can't delete activity.
    418                 $misc_user = self::factory()->user->create( array( 'role' => 'subscriber' ) );
     455                $misc_user = self::factory()->user->create();
    419456                self::set_current_user( $misc_user );
    420457                $this->assertFalse( bp_activity_user_can_delete( $activity ) );
    421458
    422459                // Misc group member can't delete activity.
    423                 $misc_user_2 = self::factory()->user->create( array( 'role' => 'subscriber' ) );
     460                $misc_user_2 = self::factory()->user->create();
    424461                self::add_user_to_group( $misc_user_2, $g );
    425462                self::set_current_user( $misc_user_2 );
    … …  
    427464
    428465                // Group mod can delete activity.
    429                 $misc_user_3 = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    430                 self::add_user_to_group( $misc_user_3, $g, [ 'is_mod' => true ] );
     466                $misc_user_3 = self::factory()->user->create();
     467                self::add_user_to_group( $misc_user_3, $g, array( 'is_mod' => true ) );
    431468                self::set_current_user( $misc_user_3 );
    432469                $this->assertTrue( bp_activity_user_can_delete( $activity ) );
    433470
    434471                // Group admin can delete activity.
    435                 $misc_user_4 = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    436                 self::add_user_to_group( $misc_user_4, $g, [ 'is_admin' => true ] );
     472                $misc_user_4 = self::factory()->user->create();
     473                self::add_user_to_group( $misc_user_4, $g, array( 'is_admin' => true ) );
    437474                self::set_current_user( $misc_user_4 );
    438475                $this->assertTrue( bp_activity_user_can_delete( $activity ) );
    … …  
    455492                $a  = self::factory()->activity->create(
    456493                        array(
    457                                 'user_id'   => $u1,
    458                                 'content'   => 'Random Activity content',
     494                                'user_id' => $u1,
     495                                'content' => 'Random Activity content',
    459496                        )
    460497                );
    … …  
    484521
    485522                // Add u2 as Admin of g2.
    486                 self::add_user_to_group( $u2, $g, [ 'is_admin' => true ] );
     523                self::add_user_to_group( $u2, $g, array( 'is_admin' => true ) );
    487524
    488525                self::set_current_user( $u2 );
Note: See TracChangeset for help on using the changeset viewer.