Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace CalderaLearn\RestSearch\Tests\Integration;
// phpcs:disable
/**
* Class RestAPITestCase
*
* Test case that all REST API integration tests MUST extend
*
* @package CalderaLearn\RestSearch\Tests\Integration
*/
abstract class RestAPITestCase extends IntegrationTestCase
{
/**
* Copied from \WP_Test_REST_Controller_Testcase
*
* @inheritdoc
*/
public function setUp()
{
parent::setUp();
add_filter('rest_url', array( $this, 'filter_rest_url_for_leading_slash' ), 10, 2);
/** @var \WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$wp_rest_server = new \Spy_REST_Server;
do_action('rest_api_init', $wp_rest_server);
}
/**
* Copied from \WP_Test_REST_Controller_Testcase
*
* @inheritdoc
*/
public function tearDown()
{
parent::tearDown();
remove_filter('rest_url', array( $this, 'test_rest_url_for_leading_slash' ), 10, 2);
/** @var \WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$wp_rest_server = null;
}
public function filter_rest_url_for_leading_slash($url, $path)
{
if (is_multisite()) {
return $url;
}
// Make sure path for rest_url has a leading slash for proper resolution.
$this->assertTrue(0 === strpos($path, '/'), 'REST API URL should have a leading slash.');
return $url;
}
}
// phpcs:enable