-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathmenu-item.feature
More file actions
324 lines (257 loc) · 11.9 KB
/
menu-item.feature
File metadata and controls
324 lines (257 loc) · 11.9 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
Feature: Manage WordPress menu items
Background:
Given a WP install
Scenario: Add / update / remove items from a menu
When I run `wp post create --post_title='Test post' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}
When I run `wp post url {POST_ID}`
Then save STDOUT as {POST_LINK}
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 run `wp term url post_tag {TERM_ID}`
Then save STDOUT as {TERM_LINK}
When I run `wp menu create "Sidebar Menu"`
Then STDOUT should not be empty
When I run `wp menu item add-post sidebar-menu {POST_ID} --title="Custom Test Post" --description="Georgia peaches" --porcelain`
Then save STDOUT as {POST_ITEM_ID}
When I run `wp menu item update {POST_ITEM_ID} --description="Washington Apples"`
Then STDOUT should be:
"""
Success: Menu item updated.
"""
When I run `wp menu item add-term sidebar-menu post_tag {TERM_ID} --porcelain`
Then save STDOUT as {TERM_ITEM_ID}
When I run `wp menu item add-custom sidebar-menu Apple https://apple.com --parent-id={POST_ITEM_ID} --porcelain`
Then save STDOUT as {CUSTOM_ITEM_ID}
When I run `wp menu item update {CUSTOM_ITEM_ID} --title=WordPress --link='https://wordpress.org' --target=_blank --position=2`
Then STDOUT should be:
"""
Success: Menu item updated.
"""
When I run `wp menu item update {TERM_ITEM_ID} --position=3`
Then STDOUT should be:
"""
Success: Menu item updated.
"""
When I run `wp menu item list sidebar-menu --fields=type,title,description,position,link,menu_item_parent`
Then STDOUT should be a table containing rows:
| type | title | description | position | link | menu_item_parent |
| post_type | Custom Test Post | Washington Apples | 1 | {POST_LINK} | 0 |
| custom | WordPress | | 2 | https://wordpress.org | {POST_ITEM_ID} |
| taxonomy | Test term | | 3 | {TERM_LINK} | 0 |
When I run `wp menu item list sidebar-menu --format=ids`
Then STDOUT should not be empty
When I run `wp menu item delete {CUSTOM_ITEM_ID}`
Then STDOUT should be:
"""
Success: Deleted 1 of 1 menu items.
"""
And I run `wp menu item list sidebar-menu --format=count`
And STDOUT should be:
"""
2
"""
When I run `wp menu item delete {POST_ITEM_ID} {TERM_ITEM_ID}`
Then STDOUT should be:
"""
Success: Deleted 2 of 2 menu items.
"""
And I run `wp menu item list sidebar-menu --format=count`
And STDOUT should be:
"""
0
"""
Scenario: Preserve grandparent item as ancestor of child item when parent item is removed.
When I run `wp menu create "Grandparent Test"`
Then STDOUT should not be empty
When I run `wp menu item add-custom grandparent-test Grandparent https://example.com/grandparent --porcelain`
Then save STDOUT as {GRANDPARENT_ID}
When I run `wp menu item add-custom grandparent-test Parent https://example.com/parent --porcelain --parent-id={GRANDPARENT_ID}`
Then save STDOUT as {PARENT_ID}
When I run `wp menu item add-custom grandparent-test Child https://example.com/child --porcelain --parent-id={PARENT_ID}`
Then save STDOUT as {CHILD_ID}
When I run `wp menu item list grandparent-test --fields=title,db_id,menu_item_parent`
Then STDOUT should be a table containing rows:
| title | db_id | menu_item_parent |
| Grandparent | {GRANDPARENT_ID} | 0 |
| Parent | {PARENT_ID} | {GRANDPARENT_ID} |
| Child | {CHILD_ID} | {PARENT_ID} |
When I run `wp menu item delete {PARENT_ID}`
And I run `wp menu item list grandparent-test --fields=title,db_id,menu_item_parent`
Then STDOUT should be a table containing rows:
| title | db_id | menu_item_parent |
| Grandparent | {GRANDPARENT_ID} | 0 |
| Child | {CHILD_ID} | {GRANDPARENT_ID} |
Scenario: Error deleting one or more menu items
When I run `wp menu create "Sidebar Menu"`
Then STDOUT should not be empty
When I try `wp menu item delete 99999999`
Then STDERR should be:
"""
Warning: Couldn't delete menu item 99999999.
Error: No menu items deleted.
"""
And the return code should be 1
When I run `wp menu item add-custom sidebar-menu Apple https://apple.com --porcelain`
Then save STDOUT as {CUSTOM_ITEM_ID}
When I try `wp menu item delete {CUSTOM_ITEM_ID} 99999999`
Then STDERR should be:
"""
Warning: Couldn't delete menu item 99999999.
Error: Only deleted 1 of 2 menu items.
"""
And the return code should be 1
Scenario: Menu order is recalculated on insertion
When I run `wp menu create "Sidebar Menu"`
Then STDOUT should not be empty
When I run `wp menu item add-custom sidebar-menu First https://first.com --porcelain`
Then save STDOUT as {ITEM_ID_1}
When I run `wp menu item add-custom sidebar-menu Second https://second.com --porcelain`
Then save STDOUT as {ITEM_ID_2}
When I run `wp menu item add-custom sidebar-menu Third https://third.com --porcelain`
Then save STDOUT as {ITEM_ID_3}
When I run `wp menu item list sidebar-menu --fields=type,title,position,link`
Then STDOUT should be a table containing rows:
| type | title | position | link |
| custom | First | 1 | https://first.com |
| custom | Second | 2 | https://second.com |
| custom | Third | 3 | https://third.com |
When I run `wp menu item add-custom sidebar-menu Fourth https://fourth.com --position=2 --porcelain`
Then save STDOUT as {ITEM_ID_4}
When I run `wp menu item list sidebar-menu --fields=type,title,position,link`
Then STDOUT should be a table containing rows:
| type | title | position | link |
| custom | First | 1 | https://first.com |
| custom | Fourth | 2 | https://fourth.com |
| custom | Second | 3 | https://second.com |
| custom | Third | 4 | https://third.com |
Scenario: Menu order is recalculated on deletion
When I run `wp menu create "Sidebar Menu"`
Then STDOUT should not be empty
When I run `wp menu item add-custom sidebar-menu First https://first.com --porcelain`
Then save STDOUT as {ITEM_ID_1}
When I run `wp menu item add-custom sidebar-menu Second https://second.com --porcelain`
Then save STDOUT as {ITEM_ID_2}
When I run `wp menu item add-custom sidebar-menu Third https://third.com --porcelain`
Then save STDOUT as {ITEM_ID_3}
When I run `wp menu item list sidebar-menu --fields=type,title,position,link`
Then STDOUT should be a table containing rows:
| type | title | position | link |
| custom | First | 1 | https://first.com |
| custom | Second | 2 | https://second.com |
| custom | Third | 3 | https://third.com |
When I run `wp menu item delete {ITEM_ID_2}`
Then STDOUT should be:
"""
Success: Deleted 1 of 1 menu items.
"""
When I run `wp menu item list sidebar-menu --fields=type,title,position,link`
Then STDOUT should be a table containing rows:
| type | title | position | link |
| custom | First | 1 | https://first.com |
| custom | Third | 2 | https://third.com |
Scenario: Menu order is recalculated on update
When I run `wp menu create "Sidebar Menu"`
Then STDOUT should not be empty
When I run `wp menu item add-custom sidebar-menu Alpha https://alpha.com --porcelain`
Then save STDOUT as {ITEM_ID_1}
When I run `wp menu item add-custom sidebar-menu Beta https://beta.com --porcelain`
Then save STDOUT as {ITEM_ID_2}
When I run `wp menu item add-custom sidebar-menu Gamma https://gamma.com --porcelain`
Then save STDOUT as {ITEM_ID_3}
When I run `wp menu item list sidebar-menu --fields=type,title,position,link`
Then STDOUT should be a table containing rows:
| type | title | position | link |
| custom | Alpha | 1 | https://alpha.com |
| custom | Beta | 2 | https://beta.com |
| custom | Gamma | 3 | https://gamma.com |
When I run `wp menu item update {ITEM_ID_3} --position=1`
Then STDOUT should be:
"""
Success: Menu item updated.
"""
When I run `wp menu item list sidebar-menu --fields=type,title,position,link`
Then STDOUT should be a table containing rows:
| type | title | position | link |
| custom | Gamma | 1 | https://gamma.com |
| custom | Alpha | 2 | https://alpha.com |
| custom | Beta | 3 | https://beta.com |
When I run `wp menu item update {ITEM_ID_1} --position=3`
Then STDOUT should be:
"""
Success: Menu item updated.
"""
When I run `wp menu item list sidebar-menu --fields=type,title,position,link`
Then STDOUT should be a table containing rows:
| type | title | position | link |
| custom | Gamma | 1 | https://gamma.com |
| custom | Beta | 2 | https://beta.com |
| custom | Alpha | 3 | https://alpha.com |
Scenario: Get menu item details
When I run `wp menu create "Sidebar Menu"`
Then STDOUT should not be empty
When I run `wp menu item add-custom sidebar-menu Apple https://apple.com --porcelain`
Then save STDOUT as {ITEM_ID}
When I run `wp menu item get {ITEM_ID}`
Then STDOUT should be a table containing rows:
| Field | Value |
| db_id | {ITEM_ID} |
| type | custom |
| title | Apple |
| link | https://apple.com |
| position | 1 |
When I run `wp menu item get {ITEM_ID} --format=json`
Then STDOUT should be JSON containing:
"""
{
"db_id": {ITEM_ID},
"type": "custom",
"title": "Apple",
"link": "https://apple.com"
}
"""
When I run `wp menu item get {ITEM_ID} --field=title`
Then STDOUT should be:
"""
Apple
"""
When I run `wp menu item get {ITEM_ID} --fields=db_id,title,type --format=csv`
Then STDOUT should be CSV containing:
| Field | Value |
| db_id | {ITEM_ID} |
| title | Apple |
| type | custom |
When I try `wp menu item get 99999999`
Then STDERR should be:
"""
Error: Invalid menu item.
"""
And the return code should be 1
When I run `wp post create --post_title='Test Post' --porcelain`
Then save STDOUT as {POST_ID}
When I try `wp menu item get {POST_ID}`
Then STDERR should be:
"""
Error: Invalid menu item.
"""
And the return code should be 1
Scenario: Add a post type archive as a menu item
When I run `wp menu create "Archive Menu"`
Then STDOUT should not be empty
When I run `wp menu item add-post-type-archive archive-menu post --porcelain`
Then STDOUT should be a number
And save STDOUT as {ITEM_ID}
When I run `wp menu item list archive-menu --fields=db_id,type,object`
Then STDOUT should be a table containing rows:
| db_id | type | object |
| {ITEM_ID} | post_type_archive | post |
When I run `wp menu item get {ITEM_ID} --field=link`
Then STDOUT should not be empty
When I try `wp menu item add-post-type-archive archive-menu invalidposttype`
Then STDERR should be:
"""
Error: Invalid post type.
"""
And the return code should be 1