-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathsite-option-pluck-patch.feature
More file actions
271 lines (237 loc) · 6.83 KB
/
site-option-pluck-patch.feature
File metadata and controls
271 lines (237 loc) · 6.83 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
Feature: Site option commands have pluck and patch.
@pluck
Scenario: Nested values can be retrieved.
Given a WP multisite install
And an input.json file:
"""
{
"foo": "bar"
}
"""
And I run `wp site option update option_name --format=json < input.json`
When I run `wp site option pluck option_name foo`
Then STDOUT should be:
"""
bar
"""
@pluck @pluck-deep
Scenario: A nested value can be retrieved at any depth.
Given a WP multisite install
And an input.json file:
"""
{
"foo": {
"bar": {
"baz": "some value"
}
},
"foo.com": {
"visitors": 999
}
}
"""
And I run `wp site option update option_name --format=json < input.json`
When I run `wp site option pluck option_name foo bar baz`
Then STDOUT should be:
"""
some value
"""
When I run `wp site option pluck option_name foo.com visitors`
Then STDOUT should be:
"""
999
"""
@pluck @pluck-fail
Scenario: Attempting to pluck a non-existent nested value fails.
Given a WP multisite install
And I run `wp site option update option_name '{ "key": "value" }' --format=json`
When I run `wp site option pluck option_name key`
Then STDOUT should be:
"""
value
"""
When I try `wp site option pluck option_name foo`
Then STDOUT should be empty
And the return code should be 1
@pluck @pluck-fail
Scenario: Attempting to pluck from a primitive value fails.
Given a WP multisite install
And I run `wp site option update option_name simple-value`
When I try `wp site option pluck option_name foo`
Then STDOUT should be empty
And the return code should be 1
@pluck @pluck-numeric
Scenario: A nested value can be retrieved from an integer key.
Given a WP multisite install
And I run `wp site option update option_name '[ "foo", "bar" ]' --format=json`
When I run `wp site option pluck option_name 0`
Then STDOUT should be:
"""
foo
"""
@patch @patch-update @patch-arg
Scenario: Nested values can be changed.
Given a WP multisite install
And an input.json file:
"""
{
"foo": "bar"
}
"""
And I run `wp site option update option_name --format=json < input.json`
When I run `wp site option patch update option_name foo baz`
Then STDOUT should be:
"""
Success: Updated 'option_name' site option.
"""
When I run `wp site option get option_name --format=json`
Then STDOUT should be JSON containing:
"""
{
"foo": "baz"
}
"""
@patch @patch-update @patch-stdin
Scenario: Nested values can be set with a value from STDIN.
Given a WP multisite install
And an input.json file:
"""
{
"foo": {
"bar": "baz"
},
"bar": "bad"
}
"""
And a patch file:
"""
new value
"""
And I run `wp site option update option_name --format=json < input.json`
When I run `wp site option patch update option_name foo bar < patch`
Then STDOUT should be:
"""
Success: Updated 'option_name' site option.
"""
When I run `wp site option get option_name --format=json`
Then STDOUT should be JSON containing:
"""
{
"foo": {
"bar": "new value"
},
"bar": "bad"
}
"""
@patch @patch-update @patch-fail
Scenario: Attempting to update a nested value fails if a parent's key does not exist.
Given a WP multisite install
And an input.json file:
"""
{
"foo": {
"bar": "baz"
},
"bar": "bad"
}
"""
And I run `wp site option update option_name --format=json < input.json`
When I try `wp site option patch update option_name foo not-a-key new-value`
Then STDOUT should be empty
And STDERR should contain:
"""
No data exists for key "not-a-key"
"""
And the return code should be 1
@patch @patch-delete
Scenario: A key can be deleted from a nested value.
Given a WP multisite install
And an input.json file:
"""
{
"foo": {
"bar": "baz",
"abe": "lincoln"
}
}
"""
And I run `wp site option update option_name --format=json < input.json`
When I run `wp site option patch delete option_name foo bar`
Then STDOUT should be:
"""
Success: Updated 'option_name' site option.
"""
When I run `wp site option get option_name --format=json`
Then STDOUT should be JSON containing:
"""
{
"foo": {
"abe": "lincoln"
}
}
"""
@patch @patch-fail @patch-delete @patch-delete-fail
Scenario: A key cannot be deleted from a nested value from a non-existent key.
Given a WP multisite install
And an input.json file:
"""
{
"foo": {
"bar": "baz"
}
}
"""
And I run `wp site option update option_name --format=json < input.json`
When I try `wp site option patch delete option_name foo not-a-key`
Then STDOUT should be empty
And STDERR should contain:
"""
No data exists for key "not-a-key"
"""
And the return code should be 1
@patch @patch-insert
Scenario: A new key can be inserted into a nested value.
Given a WP multisite install
And I run `wp site option update option_name '{}' --format=json`
When I run `wp site option patch insert option_name foo bar`
Then STDOUT should be:
"""
Success: Updated 'option_name' site option.
"""
When I run `wp site option get option_name --format=json`
Then STDOUT should be JSON containing:
"""
{
"foo": "bar"
}
"""
@patch @patch-fail @patch-insert @patch-insert-fail
Scenario: A new key cannot be inserted into a non-nested value.
Given a WP multisite install
And I run `wp site option update option_name 'a simple value'`
When I try `wp site option patch insert option_name foo bar`
Then STDOUT should be empty
And STDERR should contain:
"""
Cannot create key "foo"
"""
And the return code should be 1
When I run `wp site option get option_name`
Then STDOUT should be:
"""
a simple value
"""
@patch @patch-numeric
Scenario: A nested value can be updated using an integer key.
Given a WP multisite install
And I run `wp site option update option_name '[ "foo", "bar" ]' --format=json`
When I run `wp site option patch update option_name 0 new`
Then STDOUT should be:
"""
Success: Updated 'option_name' site option.
"""
When I run `wp site option get option_name --format=json`
Then STDOUT should be JSON containing:
"""
[ "new", "bar" ]
"""