-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathwidget-reset.feature
More file actions
200 lines (171 loc) · 5.48 KB
/
widget-reset.feature
File metadata and controls
200 lines (171 loc) · 5.48 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
Feature: Reset WordPress sidebars
Background:
Given a WP install
And I try `wp theme delete twentytwelve --force`
And I run `wp theme install twentytwelve --activate`
And I try `wp widget reset --all`
And I try `wp widget delete wp_inactive_widgets $(wp widget list wp_inactive_widgets --format=ids)`
Scenario: Reset sidebar
Given I run `wp widget add text sidebar-1 --title="Text"`
When I run `wp widget list sidebar-1 --format=count`
# The count should be non-zero (= the sidebar contains widgets)
Then STDOUT should match /^\s*[1-9][0-9]*\s*$/
When I run `wp widget reset sidebar-1`
And I run `wp widget list sidebar-1 --format=count`
Then STDOUT should be:
"""
0
"""
When I try `wp widget reset`
Then STDERR should be:
"""
Error: Please specify one or more sidebars, or use --all or --inactive.
"""
When I try `wp widget reset sidebar-1`
Then STDERR should be:
"""
Warning: Sidebar 'sidebar-1' is already empty.
"""
And STDOUT should be:
"""
Success: Sidebar already reset.
"""
And the return code should be 0
When I try `wp widget reset non-existing-sidebar-id`
Then STDERR should be:
"""
Warning: Invalid sidebar: non-existing-sidebar-id
Error: No sidebars reset.
"""
And the return code should be 1
When I run `wp widget add calendar sidebar-1 --title="Calendar"`
Then STDOUT should not be empty
When I run `wp widget list sidebar-1 --format=count`
Then STDOUT should be:
"""
1
"""
When I run `wp widget add search sidebar-2 --title="Quick Search"`
Then STDOUT should not be empty
When I run `wp widget list sidebar-2 --format=count`
# The count should be non-zero (= the sidebar contains widgets)
Then STDOUT should match /^\s*[1-9][0-9]*\s*$/
When I try `wp widget reset sidebar-1 sidebar-2 non-existing-sidebar-id`
Then STDERR should be:
"""
Warning: Invalid sidebar: non-existing-sidebar-id
Error: Only reset 2 of 3 sidebars.
"""
And the return code should be 1
When I run `wp widget list sidebar-1 --format=count`
Then STDOUT should be:
"""
0
"""
When I run `wp widget list sidebar-2 --format=count`
Then STDOUT should be:
"""
0
"""
Scenario: Reset all sidebars
When I run `wp widget add calendar sidebar-1 --title="Calendar"`
Then STDOUT should not be empty
When I run `wp widget add search sidebar-2 --title="Quick Search"`
Then STDOUT should not be empty
When I run `wp widget add text sidebar-3 --title="Text"`
Then STDOUT should not be empty
When I run `wp widget reset --all`
Then STDOUT should be:
"""
Sidebar 'sidebar-1' reset.
Sidebar 'sidebar-2' reset.
Sidebar 'sidebar-3' reset.
Success: Reset 3 of 3 sidebars.
"""
And the return code should be 0
When I run `wp widget list sidebar-1 --format=count`
Then STDOUT should be:
"""
0
"""
When I run `wp widget list sidebar-2 --format=count`
Then STDOUT should be:
"""
0
"""
When I run `wp widget list sidebar-3 --format=count`
Then STDOUT should be:
"""
0
"""
When I run `wp widget list wp_inactive_widgets --format=ids`
Then STDOUT should contain:
"""
calendar-1
"""
And STDOUT should contain:
"""
search-1
"""
And STDOUT should contain:
"""
text-1
"""
@skip-windows
Scenario: Testing movement of widgets while reset
When I run `wp widget add calendar sidebar-2 --title="Calendar"`
Then STDOUT should not be empty
When I run `wp widget add search sidebar-2 --title="Quick Search"`
Then STDOUT should not be empty
When I run `wp widget list sidebar-2 --format=ids`
Then STDOUT should contain:
"""
calendar-1 search-1
"""
# TODO: Investigate why output is not empty on Windows
When I run `wp widget list wp_inactive_widgets --format=ids`
Then STDOUT should be empty
When I run `wp widget reset sidebar-2`
And I run `wp widget list sidebar-2 --format=ids`
Then STDOUT should be empty
When I run `wp widget list wp_inactive_widgets --format=ids`
And STDOUT should contain:
"""
calendar-1 search-1
"""
Scenario: Reset inactive sidebars
When I try `wp widget reset --inactive`
Then STDERR should be:
"""
Error: No inactive sidebars found.
"""
And the return code should be 1
When I run `wp widget add calendar sidebar-1 --title="Calendar"`
Then STDOUT should not be empty
# Simulate an inactive (unregistered) sidebar by moving widget data to an orphaned key
Given a widget-orphaned-reset.php file:
"""
<?php
$w = wp_get_sidebars_widgets();
$w['orphaned-sidebar-1'] = $w['sidebar-1'];
$w['sidebar-1'] = [];
update_option( 'sidebars_widgets', $w );
"""
When I run `wp eval-file widget-orphaned-reset.php`
And I run `wp sidebar list --inactive --fields=id --format=ids`
Then STDOUT should be:
"""
orphaned-sidebar-1
"""
When I run `wp widget reset --inactive`
Then STDOUT should be:
"""
Sidebar 'orphaned-sidebar-1' reset.
Success: Reset 1 of 1 sidebars.
"""
And the return code should be 0
When I run `wp widget list wp_inactive_widgets --format=ids`
Then STDOUT should contain:
"""
calendar-1
"""