Last change
on this file since 35773 was
35773,
checked in by wonderboymusic, 10 years ago
|
REST API: Core typically sends nocache headers on all auth'ed responses, as in wp , admin-ajax , etc. Because the REST API infrastructure is hooked in pre-wp, we should be setting this ourselves.
Adds unit tests.
Props joehoyle.
Fixes #34832.
|
File size:
821 bytes
|
Line | |
---|
1 | <?php |
---|
2 | |
---|
3 | class Spy_REST_Server extends WP_REST_Server { |
---|
4 | |
---|
5 | public $sent_headers = array(); |
---|
6 | public $sent_body = ''; |
---|
7 | |
---|
8 | /** |
---|
9 | * Get the raw $endpoints data from the server |
---|
10 | * |
---|
11 | * @return array |
---|
12 | */ |
---|
13 | public function get_raw_endpoint_data() { |
---|
14 | return $this->endpoints; |
---|
15 | } |
---|
16 | |
---|
17 | /** |
---|
18 | * Allow calling protected methods from tests |
---|
19 | * |
---|
20 | * @param string $method Method to call |
---|
21 | * @param array $args Arguments to pass to the method |
---|
22 | * @return mixed |
---|
23 | */ |
---|
24 | public function __call( $method, $args ) { |
---|
25 | return call_user_func_array( array( $this, $method ), $args ); |
---|
26 | } |
---|
27 | |
---|
28 | public function send_header( $header, $value ) { |
---|
29 | $this->sent_headers[ $header ] = $value; |
---|
30 | } |
---|
31 | |
---|
32 | public function serve_request( $path = null ) { |
---|
33 | |
---|
34 | ob_start(); |
---|
35 | $result = parent::serve_request( $path ); |
---|
36 | $this->sent_body = ob_get_clean(); |
---|
37 | return $result; |
---|
38 | } |
---|
39 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.