@@ -147,81 +147,149 @@ Feature: Patch command available for the transient cache
147147 []
148148 """
149149
150- Scenario : Nested values from site transient can be updated at any depth.
151- Given a WP install
152- And a wp-content/mu-plugins/test-harness.php file:
153- """php
154- <?php
155- $set_foo = function(){
156- set_site_transient( 'my_key', ['foo' => 'bar'] );
157- set_site_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );
158- };
159-
160- WP_CLI::add_hook( 'before_invoke:transient patch', $set_foo );
161- """
150+ Scenario : Nested values from site transient can be inserted at any depth.
151+ Given a WP multisite install
152+ And I run `wp eval "set_site_transient( 'my_key', ['foo' => 'bar'] );" `
153+ And I run `wp eval "set_site_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );" `
162154
163155 When I run `wp transient patch insert my_key fuz baz --network`
164156 Then STDOUT should be:
165157 """
166158 Success: Updated transient 'my_key'.
167159 """
168160
169- When I run `wp transient patch insert my_key_2 foo fuz bar --network`
161+ When I run `wp transient get my_key --format=json --network`
162+ Then STDOUT should be:
163+ """
164+ {"foo":"bar","fuz":"baz"}
165+ """
166+
167+ When I run `wp transient patch insert my_key foo bar --network`
168+ Then STDOUT should be:
169+ """
170+ Success: Value passed for transient 'my_key' is unchanged.
171+ """
172+
173+ When I run `wp transient get my_key --format=json --network`
174+ Then STDOUT should be:
175+ """
176+ {"foo":"bar","fuz":"baz"}
177+ """
178+
179+ When I run `wp transient patch insert my_key_2 foo fuz biz --network`
170180 Then STDOUT should be:
171181 """
172182 Success: Updated transient 'my_key_2'.
173183 """
174184
175- When I try `wp transient patch insert unknown_key foo bar --network`
176- Then STDERR should be:
185+ When I run `wp transient get my_key_2 --format=json --network`
186+ Then STDOUT should be:
177187 """
178- Error: Cannot create key "foo" on data type boolean
188+ { "foo":{"bar":"baz","fuz":"biz"}}
179189 """
180190
181- When I run `wp transient patch insert my_key foo bar --network`
191+ When I run `wp transient patch insert my_key_2 foo bar baz --network`
182192 Then STDOUT should be:
183193 """
184- Success: Value passed for transient 'my_key ' is unchanged.
194+ Success: Value passed for transient 'my_key_2 ' is unchanged.
185195 """
186196
187- When I run `wp transient patch update my_key foo biz --network`
197+ When I run `wp transient get my_key_2 --format=json --network`
198+ Then STDOUT should be:
199+ """
200+ {"foo":{"bar":"baz","fuz":"biz"}}
201+ """
202+
203+ Scenario : Nested values from site transient can be updated at any depth.
204+ Given a WP multisite install
205+ And I run `wp eval "set_site_transient( 'my_key', ['foo' => 'bar'] );" `
206+ And I run `wp eval "set_site_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );" `
207+
208+ When I run `wp transient patch update my_key foo baz --network`
188209 Then STDOUT should be:
189210 """
190211 Success: Updated transient 'my_key'.
191212 """
192213
214+ When I run `wp transient get my_key --format=json --network`
215+ Then STDOUT should be:
216+ """
217+ {"foo":"baz"}
218+ """
219+
220+ When I run `wp transient patch update my_key foo baz --network`
221+ Then STDOUT should be:
222+ """
223+ Success: Value passed for transient 'my_key' is unchanged.
224+ """
225+
226+ When I run `wp transient get my_key --format=json --network`
227+ Then STDOUT should be:
228+ """
229+ {"foo":"baz"}
230+ """
231+
193232 When I run `wp transient patch update my_key_2 foo bar biz --network`
194233 Then STDOUT should be:
195234 """
196235 Success: Updated transient 'my_key_2'.
197236 """
198237
199- When I try `wp transient patch update unknown_key foo bar --network`
200- Then STDERR should be:
238+ When I run `wp transient get my_key_2 --format=json --network`
239+ Then STDOUT should be:
201240 """
202- Error: No data exists for key "foo"
241+ { "foo":{"bar":"biz"}}
203242 """
204243
205- When I run `wp transient patch update my_key foo bar --network`
244+ When I run `wp transient patch update my_key_2 foo bar biz --network`
206245 Then STDOUT should be:
207246 """
208- Success: Value passed for transient 'my_key' is unchanged.
247+ Success: Value passed for transient 'my_key_2' is unchanged.
248+ """
249+
250+ When I run `wp transient get my_key_2 --format=json --network`
251+ Then STDOUT should be:
252+ """
253+ {"foo":{"bar":"biz"}}
209254 """
210255
256+ Scenario : Nested values from site transient can be deleted at any depth.
257+ Given a WP multisite install
258+ And I run `wp eval "set_site_transient( 'my_key', ['foo' => 'bar'] );" `
259+ And I run `wp eval "set_site_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );" `
260+
211261 When I run `wp transient patch delete my_key foo --network`
212262 Then STDOUT should be:
213263 """
214264 Success: Updated transient 'my_key'.
215265 """
216266
267+ When I run `wp transient get my_key --format=json --network`
268+ Then STDOUT should be:
269+ """
270+ []
271+ """
272+
217273 When I run `wp transient patch delete my_key_2 foo bar --network`
218274 Then STDOUT should be:
219275 """
220276 Success: Updated transient 'my_key_2'.
221277 """
222278
223- When I try `wp transient patch delete unknown_key foo --network`
224- Then STDERR should be:
279+ When I run `wp transient get my_key_2 --format=json --network`
280+ Then STDOUT should be:
281+ """
282+ {"foo":[]}
283+ """
284+
285+ When I run `wp transient patch delete my_key_2 foo --network`
286+ Then STDOUT should be:
287+ """
288+ Success: Updated transient 'my_key_2'.
289+ """
290+
291+ When I run `wp transient get my_key_2 --format=json --network`
292+ Then STDOUT should be:
225293 """
226- Error: No data exists for key "foo"
294+ []
227295 """
0 commit comments