-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathcron-event.feature
More file actions
214 lines (187 loc) · 6.55 KB
/
cron-event.feature
File metadata and controls
214 lines (187 loc) · 6.55 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
Feature: Manage WP Cron events
Background:
Given a WP install
# Fails on WordPress 4.9 because `wp cron event run --due-now`
# executes the "wp_privacy_delete_old_export_files" event there.
@require-wp-5.0
Scenario: --due-now with supplied events should only run those
# WP throws a notice here for older versions of core.
When I try `wp cron event run --all`
Then STDOUT should contain:
"""
Success: Executed a total of
"""
When I run `wp cron event run --due-now`
Then STDOUT should contain:
"""
Executed a total of 0 cron events
"""
When I run `wp cron event schedule wp_cli_test_event_1 now hourly`
Then STDOUT should contain:
"""
Success: Scheduled event with hook 'wp_cli_test_event_1'
"""
When I run `wp cron event schedule wp_cli_test_event_2 now hourly`
Then STDOUT should contain:
"""
Success: Scheduled event with hook 'wp_cli_test_event_2'
"""
When I run `wp cron event run wp_cli_test_event_1 --due-now`
Then STDOUT should contain:
"""
Executed the cron event 'wp_cli_test_event_1'
"""
And STDOUT should contain:
"""
Executed a total of 1 cron event
"""
When I run `wp cron event run --due-now --exclude=wp_cli_test_event_2`
Then STDOUT should contain:
"""
Executed a total of 0 cron events
"""
When I run `wp cron event run wp_cli_test_event_2 --due-now`
Then STDOUT should contain:
"""
Executed the cron event 'wp_cli_test_event_2'
"""
And STDOUT should contain:
"""
Executed a total of 1 cron event
"""
@require-wp-4.9.0
Scenario: Unschedule cron event
When I run `wp cron event schedule wp_cli_test_event_1 now hourly`
And I try `wp cron event unschedule wp_cli_test_event_1`
Then STDOUT should contain:
"""
Success: Unscheduled 1 event for hook 'wp_cli_test_event_1'.
"""
When I run `wp cron event schedule wp_cli_test_event_2 now hourly`
And I run `wp cron event schedule wp_cli_test_event_2 '+1 hour' hourly`
And I try `wp cron event unschedule wp_cli_test_event_2`
Then STDOUT should contain:
"""
Success: Unscheduled 2 events for hook 'wp_cli_test_event_2'.
"""
When I try `wp cron event unschedule wp_cli_test_event`
Then STDERR should be:
"""
Error: No events found for hook 'wp_cli_test_event'.
"""
Scenario: Run cron event with a registered shutdown function
Given a wp-content/mu-plugins/setup_shutdown_function.php file:
"""
add_action('mycron', function() {
breakthings();
});
register_shutdown_function(function() {
$error = error_get_last();
if ($error['type'] === E_ERROR) {
WP_CLI::line('MY SHUTDOWN FUNCTION');
}
});
"""
When I run `wp cron event schedule mycron now`
And I try `wp cron event run --due-now`
Then STDOUT should contain:
"""
MY SHUTDOWN FUNCTION
"""
Scenario: Run cron event with a registered shutdown function that logs to a file
Given a wp-content/mu-plugins/setup_shutdown_function_log.php file:
"""
<?php
add_action('mycronlog', function() {
breakthings();
});
register_shutdown_function(function() {
error_log('LOG A SHUTDOWN FROM ERROR');
});
"""
And I run `wp config set WP_DEBUG true --raw`
And I run `wp config set WP_DEBUG_LOG '{RUN_DIR}/server.log'`
When I try `wp cron event schedule mycronlog now`
And I try `wp cron event run --due-now`
Then STDERR should contain:
"""
Call to undefined function breakthings()
"""
And the {RUN_DIR}/server.log file should exist
And the {RUN_DIR}/server.log file should contain:
"""
LOG A SHUTDOWN FROM ERROR
"""
Scenario: Run cron event with arguments and debug output
When I run `wp cron event schedule wp_cli_test_event_with_args now --0=123 --1=test-value`
Then STDOUT should contain:
"""
Success: Scheduled event with hook 'wp_cli_test_event_with_args'
"""
When I try `wp cron event run wp_cli_test_event_with_args --due-now --debug=cron`
Then STDOUT should contain:
"""
Executed the cron event 'wp_cli_test_event_with_args'
"""
And STDERR should contain:
"""
Debug: Arguments: ["123","test-value"]
"""
When I run `wp cron event schedule wp_cli_test_event_no_args now`
And I try `wp cron event run wp_cli_test_event_no_args --due-now --debug=cron`
Then STDOUT should contain:
"""
Executed the cron event 'wp_cli_test_event_no_args'
"""
And STDERR should not contain:
"""
Debug: Arguments:
"""
Scenario: Run cron events with --network flag on non-multisite
When I try `wp cron event run --due-now --network`
Then STDERR should be:
"""
Error: This is not a multisite installation.
"""
And the return code should be 1
Scenario: Run cron events with --network flag on multisite
Given a WP multisite subdirectory install
And I run `wp site create --slug=site2`
And I run `wp site create --slug=site3`
When I run `wp cron event schedule wp_cli_network_test now`
Then STDOUT should contain:
"""
Success: Scheduled event with hook 'wp_cli_network_test'
"""
When I run `wp --url=example.com/site2 cron event schedule wp_cli_network_test_site2 now`
Then STDOUT should contain:
"""
Success: Scheduled event with hook 'wp_cli_network_test_site2'
"""
When I run `wp cron event run --due-now --network --exclude=wp_privacy_delete_old_export_files,wp_version_check,wp_update_plugins,wp_update_themes,wp_site_health_scheduled_check,wp_update_user_counts,wp_scheduled_delete,wp_scheduled_auto_draft_delete`
Then STDOUT should contain:
"""
Executed the cron event 'wp_cli_network_test'
"""
And STDOUT should contain:
"""
Executed the cron event 'wp_cli_network_test_site2'
"""
And STDOUT should contain:
"""
Success: Executed a total of 2 cron events across 3 sites.
"""
Scenario: Confirm that cron event run in debug mode shows the start of events
When I try `wp cron event run wp_version_check --debug=cron`
Then STDOUT should contain:
"""
Executed the cron event 'wp_version_check'
"""
And STDOUT should contain:
"""
Executed a total of 1 cron event
"""
And STDERR should contain:
"""
Debug: Beginning execution of cron event 'wp_version_check'
"""