mirror of
https://github.com/buddypress/buddypress.git
synced 2026-07-23 21:06:56 +08:00
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 git-svn-id: https://buddypress.svn.wordpress.org/trunk@14026 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
92 lines
1.5 KiB
PHP
92 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Controller testcase for BuddyPress REST API endpoints.
|
|
*/
|
|
abstract class BP_Test_REST_Controller_Testcase extends WP_Test_REST_Controller_Testcase {
|
|
|
|
/**
|
|
* The endpoint/controller class name.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $controller;
|
|
|
|
/**
|
|
* The endpoint controller object.
|
|
*
|
|
* @var object
|
|
*/
|
|
protected $endpoint;
|
|
|
|
/**
|
|
* The endpoint URL.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $endpoint_url;
|
|
|
|
/**
|
|
* The BP_UnitTestCase instance.
|
|
*
|
|
* Allows accessing BuddyPress custom factories.
|
|
*
|
|
* @var BP_UnitTestCase
|
|
*/
|
|
protected $bp;
|
|
|
|
/**
|
|
* The WP_REST_Server instance.
|
|
*
|
|
* @var WP_REST_Server
|
|
*/
|
|
protected $server;
|
|
|
|
/**
|
|
* The user ID.
|
|
*
|
|
* @var int
|
|
*/
|
|
protected $user;
|
|
|
|
/**
|
|
* The endpoint handle.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $handle;
|
|
|
|
public function set_up() {
|
|
parent::set_up();
|
|
|
|
if ( $this->controller ) {
|
|
$this->endpoint = new $this->controller();
|
|
}
|
|
|
|
if ( ! $this->bp ) {
|
|
$this->bp = new BP_UnitTestCase();
|
|
}
|
|
|
|
if ( $this->handle ) {
|
|
$this->endpoint_url = '/' . bp_rest_namespace() . '/' . bp_rest_version() . '/' . $this->handle;
|
|
}
|
|
|
|
if ( ! $this->server ) {
|
|
$this->server = rest_get_server();
|
|
}
|
|
|
|
$admin = static::factory()->user->create_and_get(
|
|
array(
|
|
'role' => 'administrator',
|
|
'user_email' => 'admin@example.com',
|
|
)
|
|
);
|
|
|
|
$this->user = $admin->ID;
|
|
|
|
if ( is_multisite() ) {
|
|
grant_super_admin( $this->user );
|
|
|
|
$admin->add_cap( 'manage_network_users' );
|
|
}
|
|
}
|
|
}
|