-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathscaffold-plugin-tests.feature
More file actions
329 lines (296 loc) · 11.1 KB
/
scaffold-plugin-tests.feature
File metadata and controls
329 lines (296 loc) · 11.1 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
324
325
326
327
328
329
Feature: Scaffold plugin unit tests
# TODO: Fix this on Windows. Fails because is_executable() fails for .sh files.
@skip-windows
Scenario: Scaffold plugin tests
Given a WP install
When I run `wp plugin path`
Then save STDOUT as {PLUGIN_DIR}
When I run `wp scaffold plugin hello-world --skip-tests`
Then STDOUT should not be empty
And the {PLUGIN_DIR}/hello-world/.editorconfig file should exist
And the {PLUGIN_DIR}/hello-world/hello-world.php file should exist
And the {PLUGIN_DIR}/hello-world/readme.txt file should exist
And the {PLUGIN_DIR}/hello-world/tests directory should not exist
When I run `wp scaffold plugin-tests hello-world`
Then STDOUT should not be empty
And the {PLUGIN_DIR}/hello-world/tests directory should contain:
"""
bootstrap.php
test-sample.php
"""
And the {PLUGIN_DIR}/hello-world/tests/bootstrap.php file should contain:
"""
require dirname( __DIR__ ) . '/hello-world.php';
"""
And the {PLUGIN_DIR}/hello-world/tests/bootstrap.php file should contain:
"""
* @package Hello_World
"""
And the {PLUGIN_DIR}/hello-world/tests/test-sample.php file should contain:
"""
* @package Hello_World
"""
And the {PLUGIN_DIR}/hello-world/bin directory should contain:
"""
install-wp-tests.sh
"""
And the {PLUGIN_DIR}/hello-world/phpunit.xml.dist file should contain:
"""
<exclude>./tests/test-sample.php</exclude>
"""
And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should exist
And the {PLUGIN_DIR}/hello-world/circle.yml file should not exist
And the {PLUGIN_DIR}/hello-world/bitbucket-pipelines.yml file should not exist
And the {PLUGIN_DIR}/hello-world/.gitlab-ci.yml file should not exist
And the {PLUGIN_DIR}/hello-world/.circleci/config.yml file should contain:
"""
jobs:
php56-build:
<<: *php_job
docker:
- image: circleci/php:5.6
- image: *mysql_image
"""
And the {PLUGIN_DIR}/hello-world/.circleci/config.yml file should contain:
"""
workflows:
version: 2
main:
jobs:
- php56-build
- php70-build
- php71-build
- php72-build
- php73-build
- php74-build
"""
When I run `wp eval "if ( is_executable( '{PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh' ) ) { echo 'executable'; } else { exit( 1 ); }"`
Then STDOUT should be:
"""
executable
"""
Scenario: Scaffold plugin tests with Circle as the provider, part one
Given a WP install
And I run `wp scaffold plugin hello-world --ci=circle`
When I run `wp plugin path hello-world --dir`
Then save STDOUT as {PLUGIN_DIR}
And the {PLUGIN_DIR}/circle.yml file should not exist
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
"""
version: 2
"""
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
"""
php56-build
"""
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
"""
php70-build
"""
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
"""
php71-build
"""
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
"""
php72-build
"""
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
"""
php73-build
"""
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
"""
php74-build
"""
Scenario: Scaffold plugin tests with Circle as the provider, part two
Given a WP install
And I run `wp scaffold plugin hello-world --skip-tests`
When I run `wp plugin path hello-world --dir`
Then save STDOUT as {PLUGIN_DIR}
When I run `wp scaffold plugin-tests hello-world --ci=circle`
Then STDOUT should not be empty
And the {PLUGIN_DIR}/circle.yml file should not exist
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
"""
version: 2
"""
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
"""
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 4.5 $SKIP_DB_CREATE
phpunit
WP_MULTISITE=1 phpunit
SKIP_DB_CREATE=true
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest $SKIP_DB_CREATE
phpunit
WP_MULTISITE=1 phpunit
SKIP_DB_CREATE=true
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 trunk $SKIP_DB_CREATE
phpunit
WP_MULTISITE=1 phpunit
SKIP_DB_CREATE=true
"""
Scenario: Scaffold plugin tests with Gitlab as the provider
Given a WP install
And I run `wp scaffold plugin hello-world --skip-tests`
When I run `wp plugin path hello-world --dir`
Then save STDOUT as {PLUGIN_DIR}
When I run `wp scaffold plugin-tests hello-world --ci=gitlab`
Then STDOUT should not be empty
And the {PLUGIN_DIR}/.gitlab-ci.yml file should contain:
"""
MYSQL_DATABASE
"""
Scenario: Scaffold plugin tests with Bitbucket Pipelines as the provider
Given a WP install
And I run `wp scaffold plugin hello-world --skip-tests`
When I run `wp plugin path hello-world --dir`
Then save STDOUT as {PLUGIN_DIR}
When I run `wp scaffold plugin-tests hello-world --ci=bitbucket`
Then STDOUT should not be empty
And the {PLUGIN_DIR}/bitbucket-pipelines.yml file should contain:
"""
pipelines:
default:
"""
And the {PLUGIN_DIR}/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:7.4
name: "PHP 7.4"
script:
# Install Dependencies
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends
"""
And the {PLUGIN_DIR}/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:8.0
name: "PHP 8.0"
script:
# Install Dependencies
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends
"""
And the {PLUGIN_DIR}/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:8.2
name: "PHP 8.2"
script:
# Install Dependencies
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends
"""
And the {PLUGIN_DIR}/bitbucket-pipelines.yml file should contain:
"""
definitions:
services:
database:
image: mysql:latest
environment:
MYSQL_DATABASE: 'wordpress_tests'
MYSQL_ROOT_PASSWORD: 'root'
"""
Scenario: Scaffold plugin tests with invalid slug
Given a WP install
And a wp-content/plugins/foo.php file:
"""
<?php
/**
* Plugin Name: Foo
* Description: Foo plugin
*/
"""
Then the {RUN_DIR}/wp-content/plugins/foo.php file should exist
When I try `wp scaffold plugin-tests foo`
Then STDERR should match #Error: Invalid plugin slug specified\. No such target directory '.*wp-content/plugins/foo'\.#
And the return code should be 1
When I try `wp scaffold plugin-tests .`
Then STDERR should be:
"""
Error: Invalid plugin slug specified. The slug cannot be '.' or '..'.
"""
And the return code should be 1
When I try `wp scaffold plugin-tests ../`
Then STDERR should be:
"""
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
"""
And the return code should be 1
When I try `wp scaffold plugin-tests my-plugin/`
Then STDERR should be:
"""
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
"""
And the return code should be 1
When I try `wp scaffold plugin-tests my-plugin\\`
Then STDERR should be:
"""
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
"""
And the return code should be 1
Scenario: Scaffold plugin tests with invalid directory
Given a WP install
And I run `wp scaffold plugin hello-world --skip-tests`
When I run `wp plugin path hello-world --dir`
Then save STDOUT as {PLUGIN_DIR}
When I try `wp scaffold plugin-tests hello-world --dir=non-existent-dir`
Then STDERR should be:
"""
Error: Invalid plugin directory specified. No such directory 'non-existent-dir'.
"""
And the return code should be 1
When I run `rm -rf {PLUGIN_DIR} && touch {PLUGIN_DIR}`
Then the return code should be 0
When I try `wp scaffold plugin-tests hello-world`
Then STDERR should match #Error: Invalid plugin slug specified\. No such target directory '.*hello-world'\.#
And the return code should be 1
Scenario: Scaffold plugin tests with a symbolic link
Given a WP install
And I run `wp scaffold plugin hello-world --skip-tests`
When I run `wp plugin path hello-world --dir`
Then save STDOUT as {PLUGIN_DIR}
When I run `mv {PLUGIN_DIR} {RUN_DIR} && ln -s {RUN_DIR}/hello-world {PLUGIN_DIR}`
Then the return code should be 0
When I run `wp scaffold plugin-tests hello-world`
Then STDOUT should not be empty
And the {PLUGIN_DIR}/tests directory should contain:
"""
bootstrap.php
"""
Scenario: Scaffold plugin tests with custom main file
Given a WP install
And a wp-content/plugins/foo/bar.php file:
"""
<?php
/**
* Plugin Name: Foo
* Plugin URI: https://example.com
* Description: Foo description
* Author: John Doe
* Author URI: https://example.com
* Text Domain: foo
* Domain Path: /languages
* Version: 0.1.0
*
* @package Foo
*/
"""
When I run `wp scaffold plugin-tests foo`
Then the wp-content/plugins/foo/tests/bootstrap.php file should contain:
"""
require dirname( __DIR__ ) . '/bar.php';
"""
Scenario: Accept bitbucket as valid CI in plugin scaffold
Given a WP install
When I run `wp plugin path`
Then save STDOUT as {PLUGIN_DIR}
When I run `wp scaffold plugin hello-world --ci=bitbucket`
Then STDOUT should not be empty
And the {PLUGIN_DIR}/hello-world/.editorconfig file should exist
And the {PLUGIN_DIR}/hello-world/hello-world.php file should exist
And the {PLUGIN_DIR}/hello-world/readme.txt file should exist
And the {PLUGIN_DIR}/hello-world/bitbucket-pipelines.yml file should exist
And the {PLUGIN_DIR}/hello-world/tests directory should exist