From 7e8c2ced0e219a495ee553f88e3e65d5b1dc415a Mon Sep 17 00:00:00 2001 From: Clement Boirie Date: Fri, 8 Dec 2023 17:08:10 +0100 Subject: [PATCH] split `patch` feature tests and add additionnal checks with `transient get` --- features/transient-patch.feature | 108 ++++++++++++++++++++++++++----- 1 file changed, 92 insertions(+), 16 deletions(-) diff --git a/features/transient-patch.feature b/features/transient-patch.feature index b44186d0..336784a2 100644 --- a/features/transient-patch.feature +++ b/features/transient-patch.feature @@ -1,6 +1,6 @@ Feature: Patch command available for the transient cache - Scenario: Nested values from transient can be updated at any depth. + Scenario: Nested values from transient can be inserted at any depth. Given a WP install And I run `wp eval "set_transient( 'my_key', ['foo' => 'bar'] );"` And I run `wp eval "set_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );"` @@ -11,64 +11,140 @@ Feature: Patch command available for the transient cache Success: Updated transient 'my_key'. """ - When I run `wp transient patch insert my_key_2 foo fuz bar` + When I run `wp transient get my_key --format=json` + Then STDOUT should be: + """ + {"foo":"bar","fuz":"baz"} + """ + + When I run `wp transient patch insert my_key foo bar` + Then STDOUT should be: + """ + Success: Value passed for transient 'my_key' is unchanged. + """ + + When I run `wp transient get my_key --format=json` + Then STDOUT should be: + """ + {"foo":"bar","fuz":"baz"} + """ + + When I run `wp transient patch insert my_key_2 foo fuz biz` Then STDOUT should be: """ Success: Updated transient 'my_key_2'. """ - When I try `wp transient patch insert unknown_key foo bar` - Then STDERR should be: + When I run `wp transient get my_key_2 --format=json` + Then STDOUT should be: """ - Error: Cannot create key "foo" on data type boolean + {"foo":{"bar":"baz","fuz":"biz"}} """ - When I run `wp transient patch insert my_key foo bar` + When I run `wp transient patch insert my_key_2 foo bar baz` Then STDOUT should be: """ - Success: Value passed for transient 'my_key' is unchanged. + Success: Value passed for transient 'my_key_2' is unchanged. + """ + + When I run `wp transient get my_key_2 --format=json` + Then STDOUT should be: """ + {"foo":{"bar":"baz","fuz":"biz"}} + """ + + Scenario: Nested values from transient can be updated at any depth. + Given a WP install + And I run `wp eval "set_transient( 'my_key', ['foo' => 'bar'] );"` + And I run `wp eval "set_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );"` - When I run `wp transient patch update my_key foo biz` + When I run `wp transient patch update my_key foo baz` Then STDOUT should be: """ Success: Updated transient 'my_key'. """ + When I run `wp transient get my_key --format=json` + Then STDOUT should be: + """ + {"foo":"baz"} + """ + + When I run `wp transient patch update my_key foo baz` + Then STDOUT should be: + """ + Success: Value passed for transient 'my_key' is unchanged. + """ + + When I run `wp transient get my_key --format=json` + Then STDOUT should be: + """ + {"foo":"baz"} + """ + When I run `wp transient patch update my_key_2 foo bar biz` Then STDOUT should be: """ Success: Updated transient 'my_key_2'. """ - When I try `wp transient patch update unknown_key foo bar` - Then STDERR should be: + When I run `wp transient get my_key_2 --format=json` + Then STDOUT should be: """ - Error: No data exists for key "foo" + {"foo":{"bar":"biz"}} """ - When I run `wp transient patch update my_key foo bar` + When I run `wp transient patch update my_key_2 foo bar biz` Then STDOUT should be: """ - Success: Value passed for transient 'my_key' is unchanged. + Success: Value passed for transient 'my_key_2' is unchanged. """ + When I run `wp transient get my_key_2 --format=json` + Then STDOUT should be: + """ + {"foo":{"bar":"biz"}} + """ + + Scenario: Nested values from transient can be deleted at any depth. + Given a WP install + And I run `wp eval "set_transient( 'my_key', ['foo' => 'bar'] );"` + And I run `wp eval "set_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );"` + When I run `wp transient patch delete my_key foo` Then STDOUT should be: """ Success: Updated transient 'my_key'. """ + When I run `wp transient get my_key --format=json` + Then STDOUT should be: + """ + [] + """ + When I run `wp transient patch delete my_key_2 foo bar` Then STDOUT should be: """ Success: Updated transient 'my_key_2'. """ - When I try `wp transient patch delete unknown_key foo` - Then STDERR should be: + When I run `wp transient get my_key_2 --format=json` + Then STDOUT should be: """ - Error: No data exists for key "foo" + {"foo":[]} + """ + + When I run `wp transient patch delete my_key_2 foo` + Then STDOUT should be: + """ + Success: Updated transient 'my_key_2'. + """ + + When I run `wp transient get my_key_2 --format=json` + Then STDOUT should be: + """ + [] """ Scenario: Nested values from site transient can be updated at any depth.