Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/27/2024 09:11:27 PM (9 months 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/xprofile/class-bp-xprofile-field.php

    r13980 r14026  
    1111    public function test_can_delete_save() {
    1212        $group = self::factory()->xprofile_group->create();
    13         $field = self::factory()->xprofile_field->create( array(
    14             'field_group_id' => $group,
    15         ) );
    16 
    17         $f = new BP_XProfile_Field( $field );
     13        $field = self::factory()->xprofile_field->create(
     14            array(
     15                'field_group_id' => $group,
     16            )
     17        );
     18
     19        $f             = new BP_XProfile_Field( $field );
    1820        $f->can_delete = 0;
    1921        $f->save();
     
    3234        $_POST['checkbox_option'] = array(
    3335            1 => 'BuddyPress',
    34             2 => 'WordPress'
     36            2 => 'WordPress',
    3537        );
    3638
    3739        // checkbox field
    38         $f1 = self::factory()->xprofile_field->create( array(
    39             'field_group_id' => $group,
    40             'type' => 'checkbox',
    41             'name' => 'Interests'
    42         ) );
     40        $f1 = self::factory()->xprofile_field->create(
     41            array(
     42                'field_group_id' => $group,
     43                'type'           => 'checkbox',
     44                'name'           => 'Interests',
     45            )
     46        );
    4347
    4448        // textbox field with the same name as our checkbox value
    45         $f2 = self::factory()->xprofile_field->create( array(
    46             'field_group_id' => $group,
    47             'type' => 'textbox',
    48             'name' => 'BuddyPress'
    49         ) );
     49        $f2 = self::factory()->xprofile_field->create(
     50            array(
     51                'field_group_id' => $group,
     52                'type'           => 'textbox',
     53                'name'           => 'BuddyPress',
     54            )
     55        );
    5056
    5157        $this->assertEquals( $f2, xprofile_get_field_id_from_name( 'BuddyPress' ) );
     
    105111            $_POST['required'],
    106112            $_POST['fieldtype'],
    107             $_POST['radio_option' ]
     113            $_POST['radio_option']
    108114        );
    109115    }
     
    113119     */
    114120    public function test_newly_created_field_should_have_field_id_property_set() {
    115         $field = new BP_XProfile_Field();
     121        $field           = new BP_XProfile_Field();
    116122        $field->group_id = 1;
    117         $field->name = 'Foo';
     123        $field->name     = 'Foo';
    118124
    119125        $new_field_id = $field->save();
     
    129135
    130136        $group = self::factory()->xprofile_group->create();
    131         $field = self::factory()->xprofile_field->create( array(
    132             'field_group_id' => $group,
    133         ) );
     137        $field = self::factory()->xprofile_field->create(
     138            array(
     139                'field_group_id' => $group,
     140            )
     141        );
    134142
    135143        bp_xprofile_update_meta( $field, 'field', 'default_visibility', 'loggedin' );
     
    137145        // Initial setup takes just one query.
    138146        $num_queries = $wpdb->num_queries;
    139         $field_obj = new BP_XProfile_Field( $field );
    140         $num_queries++;
     147        $field_obj   = new BP_XProfile_Field( $field );
     148        ++$num_queries;
    141149
    142150        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    144152        // Fetching the default_visibility should cause another query.
    145153        $this->assertSame( 'loggedin', $field_obj->default_visibility );
    146         $num_queries++;
     154        ++$num_queries;
    147155
    148156        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    156164
    157165        $group = self::factory()->xprofile_group->create();
    158         $field = self::factory()->xprofile_field->create( array(
    159             'field_group_id' => $group,
    160         ) );
     166        $field = self::factory()->xprofile_field->create(
     167            array(
     168                'field_group_id' => $group,
     169            )
     170        );
    161171
    162172        bp_xprofile_update_meta( $field, 'field', 'allow_custom_visibility', 'disabled' );
     
    164174        // Initial setup takes just one query.
    165175        $num_queries = $wpdb->num_queries;
    166         $field_obj = new BP_XProfile_Field( $field );
    167         $num_queries++;
     176        $field_obj   = new BP_XProfile_Field( $field );
     177        ++$num_queries;
    168178
    169179        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    171181        // Fetching the allow_custom_visibility should cause another query.
    172182        $this->assertSame( 'disabled', $field_obj->allow_custom_visibility );
    173         $num_queries++;
     183        ++$num_queries;
    174184
    175185        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    190200    public function test_update_position_should_invalidate_cache() {
    191201        $group = self::factory()->xprofile_group->create();
    192         $field = self::factory()->xprofile_field->create( array(
    193             'field_group_id' => $group,
    194         ) );
     202        $field = self::factory()->xprofile_field->create(
     203            array(
     204                'field_group_id' => $group,
     205            )
     206        );
    195207
    196208        // Prime cache.
    197         $fetched_field = xprofile_get_field( $field );
     209        $fetched_field   = xprofile_get_field( $field );
    198210        $new_field_order = 12345;
    199211
     
    210222     */
    211223    public function test_empty_datebox_fields_should_not_return_unix_epoch() {
    212         $user  = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    213         $group = self::factory()->xprofile_group->create();
    214         $field = self::factory()->xprofile_field->create( array(
    215             'field_group_id' => $group,
    216             'type' => 'datebox',
    217         ) );
     224        $user  = self::factory()->user->create();
     225        $group = self::factory()->xprofile_group->create();
     226        $field = self::factory()->xprofile_field->create(
     227            array(
     228                'field_group_id' => $group,
     229                'type'           => 'datebox',
     230            )
     231        );
    218232
    219233        $old_user = get_current_user_id();
    220234        self::set_current_user( $user );
    221235
    222         $value = bp_get_profile_field_data( array( 'user_id' => $user, 'field' => $field ) );
     236        $value = bp_get_profile_field_data(
     237            array(
     238                'user_id' => $user,
     239                'field'   => $field,
     240            )
     241        );
    223242        $this->assertEmpty( $value );
    224243
     
    231250    public function test_delete_field_should_delete_default_field_metadata() {
    232251        $group = self::factory()->xprofile_group->create();
    233         $field = self::factory()->xprofile_field->create( array(
    234             'field_group_id' => $group
    235         ) );
     252        $field = self::factory()->xprofile_field->create(
     253            array(
     254                'field_group_id' => $group,
     255            )
     256        );
    236257
    237258        $field_obj = new BP_XProfile_Field( $field );
     
    247268    public function test_delete_field_should_delete_custom_field_metadata() {
    248269        $group = self::factory()->xprofile_group->create();
    249         $field = self::factory()->xprofile_field->create( array(
    250             'field_group_id' => $group
    251         ) );
     270        $field = self::factory()->xprofile_field->create(
     271            array(
     272                'field_group_id' => $group,
     273            )
     274        );
    252275
    253276        bp_xprofile_update_meta( $field, 'field', 'custom', 'metadata' );
Note: See TracChangeset for help on using the changeset viewer.