1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Base plugin tests to ensure the JSON API is loaded correctly. These will |
5
|
|
|
* likely need the most changes when merged into core. |
6
|
|
|
* |
7
|
|
|
* @group json_api |
8
|
|
|
* |
9
|
|
|
* @package WordPress |
10
|
|
|
* @subpackage JSON API |
11
|
|
|
*/ |
12
|
|
|
class WP_Test_REST_Plugin extends WP_UnitTestCase { |
13
|
|
|
public function setUp() { |
14
|
|
|
// Override the normal server with our spying server |
15
|
|
|
$GLOBALS['wp_rest_server'] = new WP_Test_Spy_REST_Server(); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The plugin should be installed and activated. |
20
|
|
|
*/ |
21
|
|
|
public function test_plugin_activated() { |
22
|
|
|
$this->assertTrue( class_exists( 'WP_REST_Posts_Controller' ) ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The rest_api_init hook should have been registered with init, and should |
27
|
|
|
* have a default priority of 10. |
28
|
|
|
*/ |
29
|
|
|
public function test_init_action_added() { |
30
|
|
|
$this->assertEquals( 10, has_action( 'init', 'rest_api_init' ) ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function test_add_extra_api_taxonomy_arguments() { |
34
|
|
|
|
35
|
|
|
// bootstrap the taxonomy variables |
36
|
|
|
_add_extra_api_taxonomy_arguments(); |
37
|
|
|
|
38
|
|
|
$taxonomy = get_taxonomy( 'category' ); |
39
|
|
|
$this->assertTrue( $taxonomy->show_in_rest ); |
40
|
|
|
$this->assertEquals( 'categories', $taxonomy->rest_base ); |
41
|
|
|
$this->assertEquals( 'WP_REST_Terms_Controller', $taxonomy->rest_controller_class ); |
42
|
|
|
|
43
|
|
|
$taxonomy = get_taxonomy( 'post_tag' ); |
44
|
|
|
$this->assertTrue( $taxonomy->show_in_rest ); |
45
|
|
|
$this->assertEquals( 'tags', $taxonomy->rest_base ); |
46
|
|
|
$this->assertEquals( 'WP_REST_Terms_Controller', $taxonomy->rest_controller_class ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function test_add_extra_api_post_type_arguments() { |
50
|
|
|
|
51
|
|
|
$post_type = get_post_type_object( 'post' ); |
52
|
|
|
$this->assertTrue( $post_type->show_in_rest ); |
53
|
|
|
$this->assertEquals( 'posts', $post_type->rest_base ); |
54
|
|
|
$this->assertEquals( 'WP_REST_Posts_Controller', $post_type->rest_controller_class ); |
55
|
|
|
|
56
|
|
|
$post_type = get_post_type_object( 'page' ); |
57
|
|
|
$this->assertTrue( $post_type->show_in_rest ); |
58
|
|
|
$this->assertEquals( 'pages', $post_type->rest_base ); |
59
|
|
|
$this->assertEquals( 'WP_REST_Posts_Controller', $post_type->rest_controller_class ); |
60
|
|
|
|
61
|
|
|
$post_type = get_post_type_object( 'attachment' ); |
62
|
|
|
$this->assertTrue( $post_type->show_in_rest ); |
63
|
|
|
$this->assertEquals( 'media', $post_type->rest_base ); |
64
|
|
|
$this->assertEquals( 'WP_REST_Attachments_Controller', $post_type->rest_controller_class ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|