-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathscaffold-theme-tests.feature
More file actions
275 lines (251 loc) · 9.09 KB
/
scaffold-theme-tests.feature
File metadata and controls
275 lines (251 loc) · 9.09 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
Feature: Scaffold theme unit tests
Background:
Given a WP install
And I try `wp theme install twentytwelve --force`
And I run `wp scaffold child-theme t12child --parent_theme=twentytwelve`
When I run `wp theme path`
Then save STDOUT as {THEME_DIR}
@require-php-7.0 @require-mysql
Scenario: Scaffold theme tests
When I run `wp scaffold theme-tests t12child`
Then STDOUT should not be empty
And the {THEME_DIR}/t12child/tests directory should contain:
"""
bootstrap.php
test-sample.php
"""
And the {THEME_DIR}/t12child/tests/bootstrap.php file should contain:
"""
register_theme_directory( $theme_root );
"""
And the {THEME_DIR}/t12child/tests/bootstrap.php file should contain:
"""
* @package T12child
"""
And the {THEME_DIR}/t12child/tests/test-sample.php file should contain:
"""
* @package T12child
"""
And the {THEME_DIR}/t12child/bin directory should contain:
"""
install-wp-tests.sh
"""
And the {THEME_DIR}/t12child/phpunit.xml.dist file should contain:
"""
<exclude>./tests/test-sample.php</exclude>
"""
And the {THEME_DIR}/t12child/.phpcs.xml.dist file should exist
And the {THEME_DIR}/t12child/bitbucket-pipelines.yml file should not exist
And the {THEME_DIR}/t12child/.gitlab-ci.yml file should not exist
And the {THEME_DIR}/t12child/.circleci/config.yml file should contain:
"""
jobs:
php56-build:
<<: *php_job
docker:
- image: circleci/php:5.6
- image: *mysql_image
"""
And the {THEME_DIR}/t12child/.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( '{THEME_DIR}/t12child/bin/install-wp-tests.sh' ) ) { echo 'executable'; } else { exit( 1 ); }"`
Then STDOUT should be:
"""
executable
"""
# Warning: overwriting generated functions.php file, so functions.php file loaded only tests beyond here...
Given a wp-content/themes/t12child/functions.php file:
"""
<?php echo __FILE__ . " loaded.\n";
"""
# This throws a warning for the password provided via command line.
And I try `mysql -u{DB_USER} -p{DB_PASSWORD} -h{MYSQL_HOST} -P{MYSQL_PORT} --protocol=tcp -e "DROP DATABASE IF EXISTS wp_cli_test_scaffold"`
And I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress {THEME_DIR}/t12child/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest`
Then the return code should be 0
When I run `cd {THEME_DIR}/t12child; WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib phpunit`
Then STDOUT should contain:
"""
t12child/functions.php loaded.
"""
And STDOUT should contain:
"""
Running as single site
"""
And STDOUT should contain:
"""
No tests executed!
"""
When I run `cd {THEME_DIR}/t12child; WP_MULTISITE=1 WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib phpunit`
Then STDOUT should contain:
"""
t12child/functions.php loaded.
"""
And STDOUT should contain:
"""
Running as multisite
"""
And STDOUT should contain:
"""
No tests executed!
"""
Scenario: Scaffold theme tests invalid theme
When I try `wp scaffold theme-tests p3child`
Then STDERR should be:
"""
Error: Invalid theme slug specified. The theme 'p3child' does not exist.
"""
And the return code should be 1
Scenario: Scaffold theme tests with Circle as the provider
When I run `wp scaffold theme-tests t12child --ci=circle`
Then STDOUT should not be empty
And the {THEME_DIR}/t12child/circle.yml file should not exist
And the {THEME_DIR}/t12child/.circleci/config.yml file should contain:
"""
version: 2
"""
And the {THEME_DIR}/t12child/.circleci/config.yml file should contain:
"""
php56-build
"""
And the {THEME_DIR}/t12child/.circleci/config.yml file should contain:
"""
php70-build
"""
And the {THEME_DIR}/t12child/.circleci/config.yml file should contain:
"""
php71-build
"""
And the {THEME_DIR}/t12child/.circleci/config.yml file should contain:
"""
php72-build
"""
And the {THEME_DIR}/t12child/.circleci/config.yml file should contain:
"""
php73-build
"""
And the {THEME_DIR}/t12child/.circleci/config.yml file should contain:
"""
php74-build
"""
Scenario: Scaffold theme tests with Gitlab as the provider
When I run `wp scaffold theme-tests t12child --ci=gitlab`
Then STDOUT should not be empty
And the {THEME_DIR}/t12child/.gitlab-ci.yml file should contain:
"""
MYSQL_DATABASE
"""
Scenario: Scaffold theme tests with Bitbucket Pipelines as the provider
When I run `wp scaffold theme-tests t12child --ci=bitbucket`
Then STDOUT should not be empty
And the {THEME_DIR}/t12child/bitbucket-pipelines.yml file should contain:
"""
pipelines:
default:
"""
And the {THEME_DIR}/t12child/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 {THEME_DIR}/t12child/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 {THEME_DIR}/t12child/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 {THEME_DIR}/t12child/bitbucket-pipelines.yml file should contain:
"""
definitions:
services:
database:
image: mysql:latest
environment:
MYSQL_DATABASE: 'wordpress_tests'
MYSQL_ROOT_PASSWORD: 'root'
"""
Scenario: Scaffold theme tests with invalid slug
When I try `wp scaffold theme-tests .`
Then STDERR should be:
"""
Error: Invalid theme slug specified. The slug cannot be '.' or '..'.
"""
And the return code should be 1
When I try `wp scaffold theme-tests ../`
Then STDERR should be:
"""
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
"""
And the return code should be 1
When I try `wp scaffold theme-tests t12child/`
Then STDERR should be:
"""
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
"""
And the return code should be 1
When I try `wp scaffold theme-tests t12child\\`
Then STDERR should be:
"""
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
"""
And the return code should be 1
Scenario: Scaffold theme tests with invalid directory
When I try `wp scaffold theme-tests twentytwelve --dir=non-existent-dir`
Then STDERR should be:
"""
Error: Invalid theme directory specified. No such directory 'non-existent-dir'.
"""
And the return code should be 1
# Temporarily move.
When I run `mv -f {THEME_DIR}/twentytwelve {THEME_DIR}/hide-twentytwelve && touch {THEME_DIR}/twentytwelve`
Then the return code should be 0
When I try `wp scaffold theme-tests twentytwelve`
Then STDERR should be:
"""
Error: Invalid theme slug specified. No such target directory '{THEME_DIR}/twentytwelve'.
"""
And the return code should be 1
# Restore.
When I run `rm -f {THEME_DIR}/twentytwelve && mv -f {THEME_DIR}/hide-twentytwelve {THEME_DIR}/twentytwelve`
Then the return code should be 0
# TODO: Fix this on Windows. Fails because unlink fails on directories.
@skip-windows
Scenario: Scaffold theme tests with a symbolic link
# Temporarily move the whole theme dir and create a symbolic link to it.
When I run `mv -f {THEME_DIR} {RUN_DIR}/alt-themes && ln -s {RUN_DIR}/alt-themes {THEME_DIR}`
Then the return code should be 0
When I run `wp scaffold theme-tests twentytwelve`
Then STDOUT should not be empty
And the {THEME_DIR}/twentytwelve/tests directory should contain:
"""
bootstrap.php
"""
# Restore.
When I run `unlink {THEME_DIR} && mv -f {RUN_DIR}/alt-themes {THEME_DIR}`
Then the return code should be 0