forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdatePostCache.php
More file actions
141 lines (123 loc) · 2.87 KB
/
updatePostCache.php
File metadata and controls
141 lines (123 loc) · 2.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Test `update_post_cache()`.
*
* @package WordPress
*/
/**
* Test class for `update_post_cache()`.
*
* @group post
* @group query
*
* @covers ::update_post_cache
*/
class Tests_Post_UpdatePostCache extends WP_UnitTestCase {
/**
* Post IDs from the shared fixture.
*
* @var int[]
*/
public static $post_ids;
/**
* Set up test resources before the class.
*
* @param WP_UnitTest_Factory $factory The unit test factory.
*/
public static function wpSetupBeforeClass( WP_UnitTest_Factory $factory ) {
self::$post_ids = $factory->post->create_many( 1 );
}
/**
* Ensure that `update_post_cache()` returns `null` when
* `$posts` is empty.
*
* @ticket 50567
*/
public function test_should_return_null_with_an_empty_array() {
$posts = array();
$this->assertNull( update_post_cache( $posts ) );
}
/**
* Ensure filter = raw is always set via Query.
*
* @ticket 50567
*/
public function test_query_caches_post_filter() {
$post_id = self::$post_ids[0];
$this->go_to( '/' );
$cached_post = wp_cache_get( $post_id, 'posts' );
$this->assertIsObject(
$cached_post,
'The cached post is not an object'
);
$this->assertObjectHasProperty(
'filter',
$cached_post,
'The cached post does not have a "filter" property'
);
$this->assertSame(
'raw',
$cached_post->filter,
'The filter is not set to "raw"'
);
}
/**
* Ensure filter = raw is always set via get_post.
*
* @ticket 50567
*/
public function test_get_post_caches_post_filter() {
$post_id = self::$post_ids[0];
get_post( $post_id );
$cached_post = wp_cache_get( $post_id, 'posts' );
$this->assertSame( 'raw', $cached_post->filter );
}
/**
* Ensure filter = raw is always set via get_post called with a different filter setting.
*
* @ticket 50567
*/
public function test_get_post_caches_post_filter_is_always_raw() {
$post_id = self::$post_ids[0];
get_post( $post_id, OBJECT, 'display' );
$cached_post = wp_cache_get( $post_id, 'posts' );
$this->assertIsObject(
$cached_post,
'The cached post is not an object'
);
$this->assertObjectHasProperty(
'filter',
$cached_post,
'The cached post does not have a "filter" property'
);
$this->assertSame(
'raw',
$cached_post->filter,
'The filter is not set to "raw"'
);
}
/**
* Ensure filter = raw is always set via get_posts.
*
* @ticket 50567
*/
public function test_get_posts_caches_post_filter_is_always_raw() {
$post_id = self::$post_ids[0];
get_posts( array( 'includes' => $post_id ) );
$cached_post = wp_cache_get( $post_id, 'posts' );
$this->assertIsObject(
$cached_post,
'The cached post is not an object'
);
$this->assertObjectHasProperty(
'filter',
$cached_post,
'The cached post does not have a "filter" property'
);
$this->assertSame(
'raw',
$cached_post->filter,
'The filter is not set to "raw"'
);
}
}