@@ -211,15 +211,15 @@ Feature: Managed the WordPress object cache
211
211
When I run `wp cache supports set_multiple`
212
212
Then the return code should be 0
213
213
214
- Scenario : Nested values can be retrieved at any depth.
214
+ Scenario : Nested values from cache can be retrieved at any depth.
215
215
Given a WP install
216
216
And a wp-content/mu-plugins/test-harness.php file:
217
217
"""
218
218
<?php
219
219
$set_foo = function(){
220
220
wp_cache_set( 'my_key', ['foo' => 'bar'] );
221
221
wp_cache_set( 'my_key_2', ['foo' => ['bar' => 'baz']] );
222
- wp_cache_set( 'my_key_custom ', ['foo_custom ' => [ 'bar_custom' => 'baz_custom'] ], 'my_custom_group' );
222
+ wp_cache_set( 'my_key_3 ', ['foo ' => 'bar_custom'], 'my_custom_group' );
223
223
};
224
224
225
225
WP_CLI::add_hook( 'before_invoke:cache pluck', $set_foo );
@@ -237,8 +237,96 @@ Feature: Managed the WordPress object cache
237
237
baz
238
238
"""
239
239
240
- When I try `wp cache pluck my_key_custom foo_custom bar_custom --group=my_custom_group`
240
+ When I try `wp cache pluck my_key_3 foo --group=my_custom_group`
241
241
Then STDOUT should be:
242
242
"""
243
- baz_custom
243
+ bar_custom
244
+ """
245
+
246
+ Scenario : Nested values from cache can be updated at any depth.
247
+ Given a WP install
248
+ And a wp-content/mu-plugins/test-harness.php file:
249
+ """
250
+ <?php
251
+ $set_foo = function(){
252
+ wp_cache_set( 'my_key', ['foo' => 'bar'] );
253
+ wp_cache_set( 'other_key', ['fuz' => 'biz'] );
254
+
255
+ $complex_key = (object) [
256
+ 'foo' => (object) [
257
+ 'bar' => (object) [
258
+ 'baz' => 2,
259
+ ],
260
+ ],
261
+ ];
262
+ wp_cache_set( 'complex_key', $complex_key );
263
+ };
264
+
265
+ WP_CLI::add_hook( 'before_invoke:cache patch', $set_foo );
266
+ """
267
+
268
+ When I try `wp cache patch insert my_key fuz baz`
269
+ Then STDOUT should be:
270
+ """
271
+ Success: Updated cache key 'my_key'.
272
+ """
273
+
274
+ When I try `wp cache patch insert complex_key foo bar fuz 34`
275
+ Then STDOUT should be:
276
+ """
277
+ Success: Updated cache key 'complex_key'.
278
+ """
279
+
280
+ When I try `wp cache patch insert unknown_key foo bar`
281
+ Then STDERR should be:
282
+ """
283
+ Error: Cannot create key "foo" on data type boolean
284
+ """
285
+
286
+ When I try `wp cache patch update my_key foo test`
287
+ Then STDOUT should be:
288
+ """
289
+ Success: Updated cache key 'my_key'.
290
+ """
291
+
292
+ When I try `wp cache patch update other_key fuz biz`
293
+ Then STDOUT should be:
294
+ """
295
+ Success: Value passed for cache key 'other_key' is unchanged.
296
+ """
297
+
298
+ When I try `wp cache patch update complex_key foo bar baz 34`
299
+ Then STDOUT should be:
300
+ """
301
+ Success: Updated cache key 'complex_key'.
302
+ """
303
+
304
+ When I try `wp cache patch update unknown_key foo test`
305
+ Then STDERR should be:
306
+ """
307
+ Error: No data exists for key "foo"
308
+ """
309
+
310
+ When I try `wp cache patch update my_key bar test`
311
+ Then STDERR should be:
312
+ """
313
+ Error: No data exists for key "bar"
314
+ """
315
+
316
+ When I try `wp cache patch delete my_key foo`
317
+ Then STDOUT should be:
318
+ """
319
+ Success: Updated cache key 'my_key'.
320
+ """
321
+
322
+ When I try `wp cache patch delete unknown_key foo`
323
+ Then STDERR should be:
324
+ """
325
+ Error: No data exists for key "foo"
326
+ """
327
+
328
+ When I try `wp cache patch delete my_key bar`
329
+ Then STDERR should be:
330
+ """
331
+ Error: No data exists for key "bar"
244
332
"""
0 commit comments