-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
31 lines (20 loc) · 1.06 KB
/
index.php
File metadata and controls
31 lines (20 loc) · 1.06 KB
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
<?php
header('Content-Type:text/plain');
echo '{ "tests": ['.PHP_EOL;
// generic test from the internet
sut_rest_test( 'http://echo.jsontest.com/key/value/wp_rest_cache/test_1?update_value=group_a', 'simple test');
// test using internal REST service for more advanced use cases
sut_rest_test( get_home_url() . '/wp-json/sut/v1/echo/1', 'simple test');
// build test 2 with cacheable value
sut_rest_test( get_home_url() . '/wp-json/sut/v1/echo/2', 'header value should be fresh in this call', ['value'=>'2']);
// this test will print a 2 until cache expires the first time, then it will print 3 for header value
sut_rest_test( get_home_url() . '/wp-json/sut/v1/echo/2', 'header value should be fresh in this call', ['value'=>'3']);
echo '{"end of tests":"0"}';
echo "]}".PHP_EOL;
function sut_rest_test( $url, $notes, $headers = [] ){
$response = wp_remote_get( $url, array ( 'headers' => $headers ) );
$data['request'] = $url;
$data['notes'] = $notes;
$data = array_merge( $data, json_decode( $response['body'], true ) );
echo print_r( json_encode($data), true ) . ',';
}