@@ -7,12 +7,12 @@ Feature: Granular cache flushing operations
77 """
88 <?php
99 $cache_post = function(){
10- wp_cache_set( 'post_123' , array( 'ID' => 123, 'post_title' => 'Test' ), 'posts' );
11- wp_cache_set( 'meta_123' , array( 'key' => 'value' ), 'post_meta' );
10+ wp_cache_set( 123 , array( 'ID' => 123, 'post_title' => 'Test' ), 'posts' );
11+ wp_cache_set( 123 , array( 'key' => 'value' ), 'post_meta' );
1212 };
1313 $verify_cache_cleared = function(){
14- $post = wp_cache_get( 'post_123' , 'posts' );
15- $meta = wp_cache_get( 'meta_123' , 'post_meta' );
14+ $post = wp_cache_get( 123 , 'posts' );
15+ $meta = wp_cache_get( 123 , 'post_meta' );
1616 if ( false !== $post || false !== $meta ) {
1717 WP_CLI::error( 'Cache was not properly cleared.' );
1818 }
@@ -34,12 +34,12 @@ Feature: Granular cache flushing operations
3434 """
3535 <?php
3636 $cache_term = function(){
37- wp_cache_set( 'term_5' , array( 'term_id' => 5 ), 'terms' );
38- wp_cache_set( 'term_meta_5' , array(), 'term_meta' );
37+ wp_cache_set( 5 , array( 'term_id' => 5 ), 'terms' );
38+ wp_cache_set( 5 , array(), 'term_meta' );
3939 };
4040 $verify_cache_cleared = function(){
41- $term = wp_cache_get( 'term_5' , 'terms' );
42- $meta = wp_cache_get( 'term_meta_5' , 'term_meta' );
41+ $term = wp_cache_get( 5 , 'terms' );
42+ $meta = wp_cache_get( 5 , 'term_meta' );
4343 if ( false !== $term || false !== $meta ) {
4444 WP_CLI::error( 'Cache was not properly cleared.' );
4545 }
@@ -54,19 +54,29 @@ Feature: Granular cache flushing operations
5454 Success: Term cache for ID 5 cleared.
5555 """
5656
57+ @skip-object-cache
58+ Scenario : Flush cache for an existing term resolves its taxonomy
59+ Given a WP install
60+
61+ When I run `wp cache flush-term 1`
62+ Then STDOUT should contain:
63+ """
64+ Success: Term cache for ID 1 cleared.
65+ """
66+
5767 @skip-object-cache
5868 Scenario : Flush specific comment cache
5969 Given a WP install
6070 And a wp-content/mu-plugins/test-harness.php file:
6171 """
6272 <?php
6373 $cache_comment = function(){
64- wp_cache_set( 'comment_42' , array(), 'comment' );
65- wp_cache_set( 'comment_meta_42' , array(), 'comment_meta' );
74+ wp_cache_set( 42 , array(), 'comment' );
75+ wp_cache_set( 42 , array(), 'comment_meta' );
6676 };
6777 $verify_cache_cleared = function(){
68- $comment = wp_cache_get( 'comment_42' , 'comment' );
69- $meta = wp_cache_get( 'comment_meta_42' , 'comment_meta' );
78+ $comment = wp_cache_get( 42 , 'comment' );
79+ $meta = wp_cache_get( 42 , 'comment_meta' );
7080 if ( false !== $comment || false !== $meta ) {
7181 WP_CLI::error( 'Cache was not properly cleared.' );
7282 }
@@ -88,12 +98,12 @@ Feature: Granular cache flushing operations
8898 """
8999 <?php
90100 $cache_user = function(){
91- wp_cache_set( 'user_1' , array( 'ID' => 1 ), 'users' );
92- wp_cache_set( 'user_meta_1' , array(), 'user_meta' );
101+ wp_cache_set( 1 , array( 'ID' => 1 ), 'users' );
102+ wp_cache_set( 1 , array(), 'user_meta' );
93103 };
94104 $verify_cache_cleared = function(){
95- $user = wp_cache_get( 'user_1' , 'users' );
96- $meta = wp_cache_get( 'user_meta_1' , 'user_meta' );
105+ $user = wp_cache_get( 1 , 'users' );
106+ $meta = wp_cache_get( 1 , 'user_meta' );
97107 if ( false !== $user || false !== $meta ) {
98108 WP_CLI::error( 'Cache was not properly cleared.' );
99109 }
@@ -175,6 +185,66 @@ Feature: Granular cache flushing operations
175185 Please provide a valid user ID.
176186 """
177187
188+ @skip-object-cache
189+ Scenario Outline : Non-positive post IDs fail gracefully
190+ Given a WP install
191+
192+ When I try `wp cache flush-post <id> `
193+ Then STDERR should contain:
194+ """
195+ Please provide a valid post ID.
196+ """
197+
198+ Examples :
199+ | id |
200+ | 0 |
201+ | -1 |
202+
203+ @skip-object-cache
204+ Scenario Outline : Non-positive term IDs fail gracefully
205+ Given a WP install
206+
207+ When I try `wp cache flush-term <id> `
208+ Then STDERR should contain:
209+ """
210+ Please provide a valid term ID.
211+ """
212+
213+ Examples :
214+ | id |
215+ | 0 |
216+ | -1 |
217+
218+ @skip-object-cache
219+ Scenario Outline : Non-positive comment IDs fail gracefully
220+ Given a WP install
221+
222+ When I try `wp cache flush-comment <id> `
223+ Then STDERR should contain:
224+ """
225+ Please provide a valid comment ID.
226+ """
227+
228+ Examples :
229+ | id |
230+ | 0 |
231+ | -1 |
232+
233+ @skip-object-cache
234+ Scenario Outline : Non-positive user IDs fail gracefully
235+ Given a WP install
236+
237+ When I try `wp cache flush-user <id> `
238+ Then STDERR should contain:
239+ """
240+ Please provide a valid user ID.
241+ """
242+
243+ Examples :
244+ | id |
245+ | 0 |
246+ | -1 |
247+
178248 @require-wp-6-1 @skip-object-cache
179249 Scenario : Flush all post caches on WordPress 6.1+
180250 Given a WP install
0 commit comments