Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/27/2024 09:11:27 PM (15 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/core/class-bp-component.php

    r13422 r14026  
    11<?php
    22
    3 include_once BP_TESTS_DIR . '/assets/bp-rest-api-controllers.php';
    43include_once BP_TESTS_DIR . '/assets/class-bptest-component.php';
    54
     
    98 */
    109class BP_Tests_BP_Component_TestCases extends BP_UnitTestCase {
    11     public function set_up() {
    12         parent::set_up();
    13 
    14         $bp = buddypress();
    15         $bp->unit_test_rest = new stdClass;
    16         $bp->unit_test_rest->controllers = array();
    17     }
    18 
    19     public function remove_controller( $controllers ) {
    20         return array_diff( $controllers, array( 'BP_REST_Members_Endpoint' ) );
    21     }
    22 
    23     public function add_controller( $controllers ) {
    24         return array_merge( $controllers, array( 'Foo_Bar' ) );
    25     }
    26 
    27     public function test_rest_api_init_for_members_component() {
    28         $bp_members = new BP_Members_Component();
    29         $bp         = buddypress();
    30 
    31         $bp_members->rest_api_init();
    32 
    33         $this->assertSame( $bp->unit_test_rest->controllers, array(
    34             'BP_REST_Members_Endpoint',
    35             'BP_REST_Attachments_Member_Avatar_Endpoint',
    36             'BP_REST_Attachments_Member_Cover_Endpoint',
    37         ) );
    38     }
    39 
    40     public function test_rest_api_init_for_members_component_can_remove_controller() {
    41         $bp_members = new BP_Members_Component();
    42         $bp         = buddypress();
    43 
    44         add_filter( 'bp_members_rest_api_controllers', array( $this, 'remove_controller' ) );
    45 
    46         $bp_members->rest_api_init();
    47 
    48         remove_filter( 'bp_members_rest_api_controllers', array( $this, 'remove_controller' ) );
    49 
    50         $this->assertSame( $bp->unit_test_rest->controllers, array(
    51             'BP_REST_Attachments_Member_Avatar_Endpoint',
    52             'BP_REST_Attachments_Member_Cover_Endpoint',
    53         ) );
    54     }
    55 
    56     public function test_rest_api_init_for_members_component_cannot_add_controller() {
    57         $bp_members = new BP_Members_Component();
    58         $bp         = buddypress();
    59 
    60         add_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
    61 
    62         $bp_members->rest_api_init();
    63 
    64         remove_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
    65 
    66         $this->assertSame( $bp->unit_test_rest->controllers, array(
    67             'BP_REST_Members_Endpoint',
    68             'BP_REST_Attachments_Member_Avatar_Endpoint',
    69             'BP_REST_Attachments_Member_Cover_Endpoint',
    70         ) );
    71     }
    7210
    7311    /**
Note: See TracChangeset for help on using the changeset viewer.