mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-06 07:36:58 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@35773 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -619,4 +619,30 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
$this->assertContains( 'test/example', $namespaces );
|
||||
$this->assertContains( 'test/another', $namespaces );
|
||||
}
|
||||
|
||||
public function test_nocache_headers_on_authenticated_requests() {
|
||||
$editor = self::factory()->user->create( array( 'role' => 'editor' ) );
|
||||
$request = new WP_REST_Request( 'GET', '/', array() );
|
||||
wp_set_current_user( $editor );
|
||||
|
||||
$result = $this->server->serve_request('/');
|
||||
$headers = $this->server->sent_headers;
|
||||
|
||||
foreach ( wp_get_nocache_headers() as $header => $value ) {
|
||||
$this->assertTrue( isset( $headers[ $header ] ), sprintf( 'Header %s is not present in the response.', $header ) );
|
||||
$this->assertEquals( $value, $headers[ $header ] );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_no_nocache_headers_on_unauthenticated_requests() {
|
||||
$editor = self::factory()->user->create( array( 'role' => 'editor' ) );
|
||||
$request = new WP_REST_Request( 'GET', '/', array() );
|
||||
|
||||
$result = $this->server->serve_request('/');
|
||||
$headers = $this->server->sent_headers;
|
||||
|
||||
foreach ( wp_get_nocache_headers() as $header => $value ) {
|
||||
$this->assertFalse( isset( $headers[ $header ] ) && $headers[ $header ] === $value, sprintf( 'Header %s is set to nocache.', $header ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user