-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathterm.feature
More file actions
300 lines (251 loc) · 8.53 KB
/
term.feature
File metadata and controls
300 lines (251 loc) · 8.53 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
Feature: Manage WordPress terms
Background:
Given a WP install
Scenario: Creating/listing a term
When I run `wp term create post_tag 'Test term' --slug=test --description='This is a test term' --porcelain`
Then STDOUT should be a number
And save STDOUT as {TERM_ID}
When I try the previous command again
Then STDERR should not be empty
And the return code should be 1
When I run `wp term list post_tag --format=json`
Then STDOUT should be JSON containing:
"""
[{
"name": "Test term",
"slug":"test",
"description":"This is a test term",
"parent":0,
"count":0
}]
"""
When I run `wp term list post_tag --fields=name,slug --format=csv`
Then STDOUT should be CSV containing:
| name | slug |
| Test term | test |
When I run `wp term create category 'Test category' --slug=test-category --description='This is a test category'`
Then STDOUT should not be empty
When I run `wp term list post_tag category --fields=name,slug --format=csv`
Then STDOUT should be CSV containing:
| name | slug |
| Test term | test |
| Test category | test-category |
When I run `wp term get post_tag {TERM_ID}`
Then STDOUT should be a table containing rows:
| Field | Value |
| term_id | {TERM_ID} |
| name | Test term |
When I run `wp term get post_tag {TERM_ID} --format=csv --fields=name,taxonomy`
Then STDOUT should be CSV containing:
| Field | Value |
| name | Test term |
| taxonomy | post_tag |
When I try `wp term list nonexistent_taxonomy`
Then STDERR should be:
"""
Error: Taxonomy nonexistent_taxonomy doesn't exist.
"""
And the return code should be 1
Scenario: Updating an invalid term should exit with an error
Given a WP install
When I try `wp term update category 22 --name=Foo`
Then the return code should be 1
And STDERR should contain:
"""
Error: Term doesn't exist.
"""
Scenario: Creating/deleting a term
When I run `wp term create post_tag 'Test delete term' --slug=test-delete --description='This is a test term to be deleted' --porcelain`
Then STDOUT should be a number
And save STDOUT as {TERM_ID}
When I run `wp term create post_tag 'Test delete term 2' --slug=test-two --description='This is a test term to be deleted' --porcelain`
Then STDOUT should be a number
And save STDOUT as {TERM_ID_TWO}
When I run `wp term get post_tag {TERM_ID} --field=slug --format=json`
Then STDOUT should be:
"""
"test-delete"
"""
When I run `wp term delete post_tag {TERM_ID}`
Then STDOUT should be:
"""
Deleted post_tag {TERM_ID}.
Success: Deleted 1 of 1 terms.
"""
And the return code should be 0
When I try the previous command again
Then STDOUT should be:
"""
Success: Term already deleted.
"""
And STDERR should be:
"""
Warning: post_tag {TERM_ID} doesn't exist.
"""
And the return code should be 0
When I try `wp term delete post_tag {TERM_ID} {TERM_ID_TWO}`
Then STDOUT should be:
"""
Deleted post_tag {TERM_ID_TWO}.
Success: Deleted 1 of 2 terms.
"""
And STDERR should be:
"""
Warning: post_tag {TERM_ID} doesn't exist.
"""
And the return code should be 0
Scenario: Term with a non-existent parent
When I try `wp term create category Apple --parent=99 --porcelain`
Then STDERR should be:
"""
Error: Parent term does not exist.
"""
And the return code should be 1
Scenario: Filter terms by term_id
When I run `wp term generate category --count=10`
And I run `wp term create category "My Test Category" --porcelain`
Then save STDOUT as {TERM_ID}
When I run `wp term list category --term_id={TERM_ID} --field=name`
Then STDOUT should be:
"""
My Test Category
"""
Scenario: Fetch term url
When I run `wp term create category "First Category" --porcelain`
Then save STDOUT as {TERM_ID}
When I run `wp term create category "Second Category" --porcelain`
Then save STDOUT as {SECOND_TERM_ID}
When I run `wp term url category {TERM_ID}`
Then STDOUT should be:
"""
https://example.com/?cat=2
"""
When I run `wp term url category {TERM_ID} {SECOND_TERM_ID}`
Then STDOUT should be:
"""
https://example.com/?cat=2
https://example.com/?cat=3
"""
When I run `wp term url category {SECOND_TERM_ID} {TERM_ID}`
Then STDOUT should be:
"""
https://example.com/?cat=3
https://example.com/?cat=2
"""
When I run `wp term get category 1 --field=url`
Then STDOUT should be:
"""
https://example.com/?cat=1
"""
Scenario: Make sure WordPress receives the slashed data it expects
When I run `wp term create category 'My\Term' --description='My\Term\Description' --porcelain`
Then save STDOUT as {TERM_ID}
When I run `wp term get category {TERM_ID} --field=name`
Then STDOUT should be:
"""
My\Term
"""
When I run `wp term get category {TERM_ID} --field=description`
Then STDOUT should be:
"""
My\Term\Description
"""
When I run `wp term update category {TERM_ID} --name='My\New\Term' --description='var isEmailValid = /^\S+@\S+.\S+$/.test(email);'`
Then STDOUT should not be empty
When I run `wp term get category {TERM_ID} --field=name`
Then STDOUT should be:
"""
My\New\Term
"""
When I run `wp term get category {TERM_ID} --field=description`
Then STDOUT should be:
"""
var isEmailValid = /^\S+@\S+.\S+$/.test(email);
"""
Scenario: Deleting a term by slug or ID
When I run `wp term create category Apple --description="A type of fruit"`
Then STDOUT should be:
"""
Success: Created category 2.
"""
When I run `wp term create category Orange --description="A type of fruit"`
Then STDOUT should be:
"""
Success: Created category 3.
"""
When I run `wp term create category Mango --description="A type of fruit"`
Then STDOUT should be:
"""
Success: Created category 4.
"""
When I run `wp term get category 2 --field=slug --format=json`
Then STDOUT should be:
"""
"apple"
"""
When I run `wp term delete category apple --by=slug`
Then STDOUT should be:
"""
Deleted category 2.
Success: Deleted 1 of 1 terms.
"""
When I run `wp term delete category 3 --by=id`
Then STDOUT should be:
"""
Deleted category 3.
Success: Deleted 1 of 1 terms.
"""
When I run `wp term delete category 4`
Then STDOUT should be:
"""
Deleted category 4.
Success: Deleted 1 of 1 terms.
"""
@require-wp-4.7
Scenario: Fetch term by slug or ID
When I run `wp term create category Apple --description="A type of fruit"`
Then STDOUT should be:
"""
Success: Created category 2.
"""
When I run `wp term get category 2 --by=id --format=json --fields=term_id,name,slug,count`
Then STDOUT should be:
"""
{"term_id":2,"name":"Apple","slug":"apple","count":0}
"""
When I run `wp term get category apple --by=slug --format=json --fields=term_id,name,slug,count`
Then STDOUT should be:
"""
{"term_id":2,"name":"Apple","slug":"apple","count":0}
"""
Scenario: Update term by slug or ID
When I run `wp term create category Apple --description="A type of fruit"`
Then STDOUT should be:
"""
Success: Created category 2.
"""
When I run `wp term update category apple --by=slug --name=PineApple`
Then STDOUT should be:
"""
Success: Term updated.
"""
When I run `wp term update category 2 --by=id --description="This is testing description"`
Then STDOUT should be:
"""
Success: Term updated.
"""
Scenario: Term list includes term_group as optional field
When I run `wp term create category 'Group Test' --slug=group-test --description='Test term_group field'`
Then STDOUT should not be empty
When I run `wp term list category --format=csv --fields=name,term_group`
Then STDOUT should contain:
"""
term_group
"""
When I run `wp term list category --format=json --fields=term_id,name,term_group`
Then STDOUT should be JSON containing:
"""
[{
"term_group":0
}]
"""