forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendHeaders.php
More file actions
81 lines (65 loc) · 1.87 KB
/
sendHeaders.php
File metadata and controls
81 lines (65 loc) · 1.87 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
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* @group wp
*
* @covers WP::send_headers
*/
class Tests_WP_SendHeaders extends WP_UnitTestCase {
protected $headers_sent = array();
/**
* @ticket 56068
*/
public function test_send_headers_runs_after_posts_have_been_queried() {
add_action(
'send_headers',
function ( $wp ) {
$this->assertQueryTrue( 'is_front_page', 'is_home' );
}
);
$this->go_to( home_url() );
}
/**
* @ticket 56840
*/
public function test_send_headers_sets_x_pingback_for_single_posts_that_allow_pings() {
add_action(
'wp_headers',
function ( $headers ) {
$this->assertArrayHasKey( 'X-Pingback', $headers );
}
);
$post_id = self::factory()->post->create();
$this->go_to( get_permalink( $post_id ) );
}
/**
* @ticket 61711
*/
public function test_send_headers_sets_cache_control_header_for_password_protected_posts() {
$password = 'password';
add_filter(
'wp_headers',
function ( $headers ) {
$this->headers_sent = $headers;
return $headers;
}
);
$post_id = self::factory()->post->create(
array(
'post_password' => $password,
)
);
$this->go_to( get_permalink( $post_id ) );
$headers_without_password = $this->headers_sent;
$password_status_without_password = post_password_required( $post_id );
require_once ABSPATH . WPINC . '/class-phpass.php';
$hash = ( new PasswordHash( 8, true ) )->HashPassword( $password );
$_COOKIE[ 'wp-postpass_' . COOKIEHASH ] = $hash;
$this->go_to( get_permalink( $post_id ) );
$headers_with_password = $this->headers_sent;
$password_status_with_password = post_password_required( $post_id );
$this->assertTrue( $password_status_without_password );
$this->assertArrayHasKey( 'Cache-Control', $headers_without_password );
$this->assertFalse( $password_status_with_password );
$this->assertArrayHasKey( 'Cache-Control', $headers_with_password );
}
}