This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathtest-env-setup.sh
executable file
·361 lines (308 loc) · 11.6 KB
/
test-env-setup.sh
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#!/usr/bin/env bash
###################################################################################################
# Get the directory of the current script
###################################################################################################
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
###################################################################################################
# Empty site to prevent conflicts with existing data
###################################################################################################
wp-env run tests-cli "wp site empty --yes"
###################################################################################################
# If no attributes exist, otherwiese create them
###################################################################################################
attributes=$(wp-env run tests-cli "wc product_attribute list --format=json --user=1")
if [ -z "$attributes" ] || [ "$attributes" == "[]" ]; then
pa_color=$(wp-env run tests-cli "wc product_attribute create \
--name=Color \
--slug=pa_color \
--user=1 \
--porcelain \
")
pa_size=$(wp-env run tests-cli "wc product_attribute create \
--name=Size \
--slug=pa_size \
--user=1 \
--porcelain \
")
fi
###################################################################################################
# Import sample products and egenerate product lookup tables
###################################################################################################
wp-env run tests-cli "wp import wp-content/plugins/woocommerce/sample-data/sample_products.xml --authors=skip"
wp-env run tests-cli "wp wc tool run regenerate_product_lookup_tables --user=1"
###################################################################################################
# Create pages and posts
###################################################################################################
post_content=$(cat "${script_dir}/all-products.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--menu_order=0 \
--post_type=page \
--post_status=publish \
--post_author=1 \
--post_title='All Products block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/cart.txt" | sed 's/"/\\"/g')
post_id=$(wp-env run tests-cli "wp post create \
--porcelain \
--menu_order=1 \
--post_type=page \
--post_status=publish \
--post_author=1 \
--post_title='Cart block' \
--post_content=\"$post_content\"
")
wp-env run tests-cli "wp option update woocommerce_cart_page_id $post_id"
post_content=$(cat "${script_dir}/checkout.txt" | sed 's/"/\\"/g')
post_id=$(wp-env run tests-cli "wp post create \
--porcelain \
--menu_order=2 \
--post_type=page \
--post_status=publish \
--post_author=1 \
--post_title='Checkout block' \
--post_content=\"$post_content\"
")
wp-env run tests-cli "wp option update woocommerce_checkout_page_id $post_id"
post_content=$(cat "${script_dir}/my-account.txt" | sed 's/"/\\"/g')
post_id=$(wp-env run tests-cli "wp post create \
--porcelain \
--menu_order=3 \
--post_type=page \
--post_status=publish \
--post_author=1 \
--post_title='My Account' \
--post_content=\"$post_content\"
")
wp-env run tests-cli "wp option update woocommerce_myaccount_page_id $post_id"
post_id=$(wp-env run tests-cli "wp post create \
--porcelain \
--menu_order=4 \
--post_type=page \
--post_status=publish \
--post_author=1 \
--post_title='Terms'")
wp-env run tests-cli "wp option update woocommerce_terms_page_id $post_id"
post_id=$(wp-env run tests-cli "wp post create \
--porcelain \
--menu_order=5 \
--post_type=page \
--post_status=publish \
--post_author=1 \
--post_title='Privacy'
")
wp-env run tests-cli "wp option update wp_page_for_privacy_policy $post_id"
post_content=$(cat "${script_dir}/all-reviews.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='All Reviews block' \
--post_content=\"$post_content\"
"
if [ "$pa_color" ] && [ "$pa_size" ]; then
post_content=$(cat "${script_dir}/active-filters.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Active Filters block' \
--post_content=\"$post_content\"
"
fi
post_content=$(cat "${script_dir}/mini-cart.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Mini-Cart block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/product-best-sellers.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Best Selling Products block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/products-by-attribute.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Products by Attribute block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/single-product.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Single Product block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/customer-account.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Customer Account block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/featured-category.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Featured Category block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/featured-product.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Featured Product block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/handpicked-products.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Hand-picked Products block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/product-new.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Newest Products block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/product-on-sale.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='On Sale Products block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/product-category.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Products by Category block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/product-category.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Products by Category block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/product-categories.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Product Categories List block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/product-search.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Product Search block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/reviews-by-category.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Reviews by Category block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/reviews-by-product.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Reviews by Product block' \
--post_content=\"$post_content\"
"
post_content=$(cat "${script_dir}/product-top-rated.txt" | sed 's/"/\\"/g')
wp-env run tests-cli "wp post create \
--post_status=publish \
--post_author=1 \
--post_title='Top Rated Products block' \
--post_content=\"$post_content\"
"
###################################################################################################
# Set up shipping
###################################################################################################
wp-env run tests-cli "wp wc shipping_zone_method create 0 \
--order=1 \
--enabled=true \
--user=1 \
--settings='{\"title\":\"Flat rate shipping\", \"cost\": \"10\"}' \
--method_id=flat_rate
"
wp-env run tests-cli "wp wc shipping_zone_method create 0 \
--order=2 \
--enabled=true \
--user=1 \
--settings='{\"title\":\"Free shipping\"}' \
--method_id=free_shipping
"
###################################################################################################
# Set up payment methods
###################################################################################################
wp-env run tests-cli "wp option set --format=json woocommerce_cod_settings '{
\"enabled\":\"yes\",
\"title\":\"Cash on delivery\",
\"description\":\"Cash on delivery description\",
\"instructions\":\"Cash on delivery instructions\"
}'"
wp-env run tests-cli "wp option set --format=json woocommerce_bacs_settings '{
\"enabled\":\"yes\",
\"title\":\"Direct bank transfer\",
\"description\":\"Direct bank transfer description\",
\"instructions\":\"Direct bank transfer instructions\"
}'"
wp-env run tests-cli "wp option set --format=json woocommerce_cheque_settings '{
\"enabled\":\"yes\",
\"title\":\"Check payments\",
\"description\":\"Check payments description\",
\"instructions\":\"Check payments instructions\"
}'"
###################################################################################################
# Set up tax
###################################################################################################
wp-env run tests-cli "wp option set woocommerce_calc_taxes yes"
wp-env run tests-cli "wp wc tax create \
--user=1 \
--rate=20 \
--class=standard \
"
wp-env run tests-cli "wp wc tax create \
--user=1 \
--rate=10 \
--class=reduced-rate \
"
wp-env run tests-cli "wp wc tax create \
--user=1 \
--rate=0 \
--class=zero-rate \
"
###################################################################################################
# Adjust and flush rewrite rules
###################################################################################################
# Currently, the rewrite rules don't work properly in the test environment: https://github.com/WordPress/gutenberg/issues/28201
wp-env run tests-wordpress "chmod -c ugo+w /var/www/html"
wp-env run tests-cli "wp rewrite structure /%postname%/ --hard"
wp-env run tests-cli "wp rewrite flush --hard"
###################################################################################################
# Create a customer
###################################################################################################
wp-env run tests-cli "wp user create customer customer@woocommerceblockse2etestsuite.com \
--user_pass=password \
--role=subscriber \
--first_name='Jane' \
--last_name='Smith' \
--path=/var/www/html \
--user_registered='2022-01-01 12:23:45'
"
###################################################################################################
# Update blog name
###################################################################################################
wp-env run tests-cli "wp option update blogname 'WooCommerce Blocks E2E Test Suite'"