1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Tests for the `sites/%s/jetpack/modules` endpoints. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
require_jetpack_file( 'class.json-api.php' ); |
9
|
|
|
require_jetpack_file( 'class.json-api-endpoints.php' ); |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Tests for the `sites/%s/jetpack/modules` endpoints. |
13
|
|
|
*/ |
14
|
|
|
class WP_Test_Jetpack_Modules_Json_Api_Endpoints extends WP_UnitTestCase { |
15
|
|
|
/** |
16
|
|
|
* Inserts globals needed to initialize the endpoint. |
17
|
|
|
*/ |
18
|
|
|
private function set_globals() { |
19
|
|
|
$_SERVER['REQUEST_METHOD'] = 'Get'; |
20
|
|
|
$_SERVER['HTTP_HOST'] = '127.0.0.1'; |
21
|
|
|
$_SERVER['REQUEST_URI'] = '/'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Prepare the environment for the test. |
26
|
|
|
*/ |
27
|
|
View Code Duplication |
public function setUp() { |
28
|
|
|
global $blog_id; |
29
|
|
|
|
30
|
|
|
if ( ! defined( 'WPCOM_JSON_API__BASE' ) ) { |
31
|
|
|
define( 'WPCOM_JSON_API__BASE', 'public-api.wordpress.com/rest/v1' ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
parent::setUp(); |
35
|
|
|
|
36
|
|
|
$this->set_globals(); |
37
|
|
|
|
38
|
|
|
WPCOM_JSON_API::init()->token_details = array( 'blog_id' => $blog_id ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Unit test for the `v1.2/modules/%s` endpoint. |
43
|
|
|
*/ |
44
|
|
|
public function test_get_modules_v1_2() { |
45
|
|
|
global $blog_id; |
46
|
|
|
|
47
|
|
|
$endpoint = new Jetpack_JSON_API_Modules_List_V1_2_Endpoint( |
48
|
|
|
array( |
49
|
|
|
'description' => 'Get the list of available Jetpack modules on your site', |
50
|
|
|
'method' => 'GET', |
51
|
|
|
'path' => '/sites/%s/jetpack/modules', |
52
|
|
|
'stat' => 'jetpack:modules', |
53
|
|
|
'min_version' => '1.2', |
54
|
|
|
'path_labels' => array( |
55
|
|
|
'$site' => '(int|string) The site ID, The site domain', |
56
|
|
|
), |
57
|
|
|
'response_format' => array( |
58
|
|
|
'modules' => '(array) An array of module objects.', |
59
|
|
|
), |
60
|
|
|
'allow_jetpack_site_auth' => true, |
61
|
|
|
'example_request_data' => array( |
62
|
|
|
'headers' => array( |
63
|
|
|
'authorization' => 'Bearer YOUR_API_TOKEN', |
64
|
|
|
), |
65
|
|
|
), |
66
|
|
|
'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/example.wordpress.org/jetpack/modules', |
67
|
|
|
) |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$response = $endpoint->callback( '', $blog_id ); |
71
|
|
|
|
72
|
|
|
$this->assertArrayHasKey( 'modules', $response ); |
73
|
|
|
$this->assertTrue( is_array( $response['modules'] ) ); |
74
|
|
|
|
75
|
|
|
$module = array_pop( $response['modules'] ); |
76
|
|
|
$this->assertArrayHasKey( 'name', $module ); |
77
|
|
|
$this->assertArrayHasKey( 'description', $module ); |
78
|
|
|
$this->assertArrayHasKey( 'activated', $module ); |
79
|
|
|
$this->assertArrayHasKey( 'available', $module ); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|