@webship.co/workspace-learnpress 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +312 -2
- package/ai/agents/learnpress-site-builder.md +112 -0
- package/ai/agents/learnpress-tester.md +163 -0
- package/ai/commands/learnpress-test.md +97 -0
- package/ai/prompts/learnpress-build-and-test.md +25 -0
- package/ai/prompts/learnpress-quiz-round.md +32 -0
- package/ai/skills/learnpress-scenarios/SKILL.md +211 -0
- package/ai/skills/learnpress-scenarios/examples/enrolling-and-lessons.feature +34 -0
- package/ai/skills/learnpress-scenarios/examples/the-course-editor.feature +29 -0
- package/ai/skills/learnpress-scenarios/examples/the-quiz.feature +43 -0
- package/commands/cmd-learnpress-project.sh +37 -0
- package/commands/cmd-tools-learnpress-courses.sh +26 -0
- package/dist/src/index.d.ts +37 -0
- package/dist/src/index.js +60 -0
- package/dist/src/index.js.map +1 -0
- package/features/learnpress-runtimes.feature +54 -0
- package/features/learnpress.feature +44 -0
- package/package.json +102 -4
- package/scripts/args/arg-learnpress-courses.sh +22 -0
- package/scripts/args/arg-learnpress.sh +40 -0
- package/scripts/functions/fun-learnpress.sh +415 -0
- package/scripts/learning-site.php +442 -0
- package/testing/courses.feature +38 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# LearnPress for the Webship Workspace: build a site of courses on WordPress, add its default accounts (one per place in
|
|
4
|
+
# the courses), add the sample courses, and wire its step pack into the testing setup, next to the WordPress step pack
|
|
5
|
+
# it extends.
|
|
6
|
+
#
|
|
7
|
+
# Placed by `plugins.sh --install learnpress` in core/scripts/plugins/learnpress/functions/, where bootstrap sources it
|
|
8
|
+
# with the core's own functions and the WordPress plugin's: this plugin needs @webship.co/workspace-wordpress, and its
|
|
9
|
+
# builder starts from that plugin's wordpress_build. Everything runs in the project's container (DDEV by default:
|
|
10
|
+
# `ddev wp …`), never on the host. The container tool writes the database settings, so nothing here writes any.
|
|
11
|
+
#
|
|
12
|
+
# LearnPress's activation makes its tables, its pages (Courses, Profile, Checkout, Instructors, Become an Instructor,
|
|
13
|
+
# Terms and Conditions) and its roles. The accounts' places and the sample courses are written with the plugin's own
|
|
14
|
+
# models by learning-site.php (beside these functions), run with WP-CLI in the container:
|
|
15
|
+
# bash cmd-tools-wordpress-cli.sh <site> --run "post list --post_type=lp_course"
|
|
16
|
+
#
|
|
17
|
+
# A site of courses is a project of the type `wordpress`. The builder leaves the claim of this plugin on the project,
|
|
18
|
+
# by which the core's tools take the test users of the courses for it instead of the WordPress list:
|
|
19
|
+
# .ddev/config.learnpress.yaml on DDEV, `platform: learnpress` in the x-webship block on another runtime.
|
|
20
|
+
#
|
|
21
|
+
# The runtimes: a site is built on DDEV, or with --runtime on Docker Compose, Podman, Kubernetes, Lando or Docksal. The
|
|
22
|
+
# WordPress plugin's builder makes the site on that runtime, and the commands here are the same on each: `ddev <verb>`
|
|
23
|
+
# is DDEV itself on a DDEV project, and on another runtime the core's layer (fun-runtime.sh) gives the verb its
|
|
24
|
+
# meaning. What differs is behind learnpress_runtime: the address (learnpress_url) and where the claim is.
|
|
25
|
+
#
|
|
26
|
+
# Four names are the ones the core's tools look for:
|
|
27
|
+
# set_learnpress_users the default accounts (cmd-tools-add-users.sh <project> learnpress)
|
|
28
|
+
# add_learnpress_users create them with WP-CLI (the same tool, and --add-users of the builder)
|
|
29
|
+
# cancel_learnpress_users delete them (cmd-tools-cancel-users.sh <project> learnpress)
|
|
30
|
+
# testing_configure_learnpress the step pack in the testing stack (cmd-tools-testing.sh <project>)
|
|
31
|
+
|
|
32
|
+
# The step pack a site of courses is tested with, and the release line it is required at. It brings the WordPress step
|
|
33
|
+
# pack along; the WordPress plugin's hook adds that one too.
|
|
34
|
+
readonly LEARNPRESS_STEPS_PACKAGE='@webship-js/learnpress-steps';
|
|
35
|
+
readonly LEARNPRESS_STEPS_VERSION='^2.0.0';
|
|
36
|
+
|
|
37
|
+
# The default accounts: one per place in the courses, the ones a scenario logs in as. Accounts are configuration,
|
|
38
|
+
# created once on the site; a test suite never creates or deletes one.
|
|
39
|
+
# administrator an administrator of the site (a second one: the installer's is the workspace account)
|
|
40
|
+
# instructor LearnPress's instructor role (lp_teacher): the sample courses are theirs
|
|
41
|
+
# student a subscriber enrolled in the first sample course
|
|
42
|
+
# student2 a subscriber enrolled in nothing
|
|
43
|
+
# The name the site shows is "<Login> Test" ("Student2 Test").
|
|
44
|
+
function set_learnpress_users() {
|
|
45
|
+
users=(administrator instructor student student2);
|
|
46
|
+
local user ;
|
|
47
|
+
for user in "${users[@]}" ; do
|
|
48
|
+
printf -v "user_${user}_name" '%s' "${user}" ;
|
|
49
|
+
printf -v "user_${user}_mail" '%s' "${user}@example.com" ;
|
|
50
|
+
printf -v "user_${user}_password" '%s' 'dD.123123ddd' ;
|
|
51
|
+
printf -v "user_${user}_role" '%s' 'subscriber' ;
|
|
52
|
+
printf -v "user_${user}_fullname" '%s' "${user^} Test" ;
|
|
53
|
+
done
|
|
54
|
+
user_administrator_role='administrator' ;
|
|
55
|
+
user_instructor_role='lp_teacher' ;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
# The runtime of the project in this folder, or of a new build (--runtime, else the workspace's setting, else DDEV). A
|
|
59
|
+
# core without the runtime layer has DDEV only.
|
|
60
|
+
function learnpress_runtime() {
|
|
61
|
+
if declare -f runtime_of > /dev/null ; then runtime_of ; else echo 'ddev' ; fi
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# The address of the site in this folder: https://<name>.ddev.site on DDEV, http://127.0.0.1:<port> on Docker Compose,
|
|
65
|
+
# Podman and Lando, the node's address and a port on Kubernetes, http://<name>.docksal.site on Docksal. Asked once the
|
|
66
|
+
# project is configured.
|
|
67
|
+
function learnpress_url() {
|
|
68
|
+
if declare -f rt_url > /dev/null ; then rt_url ; else echo "https://${PROJECT_NAME}.ddev.site" ; fi
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# Is this folder a site of courses? The builder leaves its claim in it (the file on DDEV, the x-webship block on another
|
|
72
|
+
# runtime: the core's rt_is_platform reads both); a WordPress project that got the plugin another way has the plugin's
|
|
73
|
+
# folder, at its root or in its docroot.
|
|
74
|
+
function learnpress_is_project() {
|
|
75
|
+
local project_path="$1" ;
|
|
76
|
+
[ -f "${project_path}/.ddev/config.learnpress.yaml" ] && return 0 ;
|
|
77
|
+
if declare -f rt_is_platform > /dev/null ; then
|
|
78
|
+
rt_is_platform "${project_path}" learnpress && return 0 ;
|
|
79
|
+
fi
|
|
80
|
+
[ -f "${project_path}/wp-content/plugins/learnpress/learnpress.php" ] && return 0 ;
|
|
81
|
+
compgen -G "${project_path}/*/wp-content/plugins/learnpress/learnpress.php" > /dev/null ;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Go to the project a tool was asked about, or say why not.
|
|
85
|
+
function learnpress_enter_project() {
|
|
86
|
+
local project_path="${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}";
|
|
87
|
+
if [ ! -d "${project_path}" ] ; then
|
|
88
|
+
echo "No project ${PROJECT_NAME} in ${WORKSPACE_ROOT}/${doc_name}." ;
|
|
89
|
+
return 1 ;
|
|
90
|
+
fi
|
|
91
|
+
if ! learnpress_is_project "${project_path}" ; then
|
|
92
|
+
echo "${doc_name}/${PROJECT_NAME} is not a site of courses: a WordPress project with LearnPress in its plugins." ;
|
|
93
|
+
return 1 ;
|
|
94
|
+
fi
|
|
95
|
+
cd "${project_path}" || return 1 ;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
# The claim of this plugin on a project, in the folder of the container tool: a config overlay with one key the web
|
|
99
|
+
# container does not use, the name of the platform the project was built as. The core's tools read the file's name: a
|
|
100
|
+
# project that carries config.<plugin>.yaml takes the test users of that plugin.
|
|
101
|
+
function learnpress_write_claim() {
|
|
102
|
+
local project_path="$1" ;
|
|
103
|
+
mkdir -p "${project_path}/.ddev" || return 1 ;
|
|
104
|
+
cat > "${project_path}/.ddev/config.learnpress.yaml" <<'YAMLEOF'
|
|
105
|
+
# Written by the LearnPress plugin of the Webship Workspace (cmd-learnpress-project.sh).
|
|
106
|
+
#
|
|
107
|
+
# It is the plugin's claim on this project: the workspace's tools take the test users of the courses for it
|
|
108
|
+
# (cmd-tools-add-users.sh <project> learnpress) instead of the WordPress list. The key below is in the environment of
|
|
109
|
+
# the web container from its next start; nothing of the site reads it.
|
|
110
|
+
web_environment:
|
|
111
|
+
- WEBSHIP_WORKSPACE_PLATFORM=learnpress
|
|
112
|
+
YAMLEOF
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
# Run learning-site.php in the site, in the project folder: the sample courses, a reset, a status, the counts, what
|
|
116
|
+
# deleted accounts left in the plugin's tables, each written or read with the plugin's own models.
|
|
117
|
+
function learnpress_learning_site() {
|
|
118
|
+
local script="${WORKSPACE_SCRIPTS}/plugins/learnpress/learning-site.php" status ;
|
|
119
|
+
if [ ! -f "${script}" ] ; then
|
|
120
|
+
echo "The LearnPress plugin's learning-site.php is not at ${script}: install the plugin again (plugins.sh --install learnpress)." ;
|
|
121
|
+
return 1 ;
|
|
122
|
+
fi
|
|
123
|
+
cp "${script}" .webship-learning-site.php || return 1 ;
|
|
124
|
+
ddev wp eval-file .webship-learning-site.php "$@" < /dev/null ;
|
|
125
|
+
status=$? ;
|
|
126
|
+
rm -f .webship-learning-site.php ;
|
|
127
|
+
return ${status} ;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
# Build a site of courses from nothing: the WordPress plugin's builder makes the site, then LearnPress is added.
|
|
131
|
+
function learnpress_build() {
|
|
132
|
+
trim_project_name ;
|
|
133
|
+
local base_url runtime ;
|
|
134
|
+
runtime="$(learnpress_runtime)" ;
|
|
135
|
+
if [ "${RUNTIME:-_none_}" != '_none_' ] && [ "${RUNTIME}" != "${runtime}" ] ; then
|
|
136
|
+
echo "--runtime ${RUNTIME} needs a Webship Workspace with the container runtimes (webship/workspace#694): update the workspace, or build on DDEV." ;
|
|
137
|
+
exit 1 ;
|
|
138
|
+
fi
|
|
139
|
+
local learnpress_version="${VERSION:-${site_version:-latest}}" ;
|
|
140
|
+
local add_users="${ADD_USERS}" launch="${LAUNCH}" ;
|
|
141
|
+
|
|
142
|
+
if ! declare -f wordpress_build > /dev/null ; then
|
|
143
|
+
echo "The LearnPress plugin builds on the WordPress plugin, which is not installed here:" ;
|
|
144
|
+
echo " bash core/scripts/plugins.sh --install wordpress" ;
|
|
145
|
+
exit 1 ;
|
|
146
|
+
fi
|
|
147
|
+
|
|
148
|
+
# The site, by the WordPress plugin's builder: the container, WordPress, and with --install the site with the
|
|
149
|
+
# workspace account as its administrator. Its --version is WordPress's; the accounts and the browser come after
|
|
150
|
+
# LearnPress is set up.
|
|
151
|
+
VERSION="${WORDPRESS_VERSION:-${wordpress_version:-latest}}" ;
|
|
152
|
+
ADD_USERS='no' ; LAUNCH='no' ;
|
|
153
|
+
( wordpress_build ) || exit 1 ;
|
|
154
|
+
ADD_USERS="${add_users}" ; LAUNCH="${launch}" ;
|
|
155
|
+
|
|
156
|
+
cd "${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}" || exit 1 ;
|
|
157
|
+
# The address is the runtime's to say, now the project is configured: never a written ddev.site.
|
|
158
|
+
base_url="$(learnpress_url)" ;
|
|
159
|
+
# The claim: a file of the container tool's on DDEV, the x-webship block on another runtime.
|
|
160
|
+
if [ "${runtime}" != 'ddev' ] ; then
|
|
161
|
+
rt_claim learnpress || { echo "The plugin's claim on the project could not be written." ; exit 1 ; } ;
|
|
162
|
+
else
|
|
163
|
+
learnpress_write_claim "${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}" || { echo "The plugin's claim on the project could not be written." ; exit 1 ; } ;
|
|
164
|
+
fi
|
|
165
|
+
|
|
166
|
+
if [ "${INSTALL}" != 'yes' ] ; then
|
|
167
|
+
# No site yet: LearnPress goes into the plugins, to activate once WordPress is installed.
|
|
168
|
+
local zip="learnpress.latest-stable.zip" ;
|
|
169
|
+
[ "${learnpress_version}" != 'latest' ] && zip="learnpress.${learnpress_version}.zip" ;
|
|
170
|
+
ddev exec "curl -fsSL https://downloads.wordpress.org/plugin/${zip} -o /tmp/learnpress.zip && unzip -oq /tmp/learnpress.zip -d wp-content/plugins && rm -f /tmp/learnpress.zip" < /dev/null \
|
|
171
|
+
|| { echo "LearnPress could not be downloaded." ; exit 1 ; } ;
|
|
172
|
+
[ "${ADD_USERS}" == 'yes' ] && echo "--add-users needs --install: there is no site to add accounts to yet." ;
|
|
173
|
+
[ "${SAMPLE_COURSE}" == 'yes' ] && echo "--sample-course needs --install: there are no courses to add it to yet." ;
|
|
174
|
+
echo "${doc_name} ${PROJECT_NAME} is ready to install, with LearnPress in its plugins.";
|
|
175
|
+
echo "Go to ${base_url}";
|
|
176
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
177
|
+
return 0 ;
|
|
178
|
+
fi
|
|
179
|
+
|
|
180
|
+
# Pretty addresses (the courses live at /courses/, the profile at /profile/), then LearnPress: its activation makes
|
|
181
|
+
# its tables, its pages and its roles.
|
|
182
|
+
ddev wp rewrite structure '/%postname%/' < /dev/null > /dev/null ;
|
|
183
|
+
ddev wp plugin install learnpress $( [ "${learnpress_version}" != 'latest' ] && echo "--version=${learnpress_version}" ) --activate < /dev/null \
|
|
184
|
+
|| { echo "LearnPress could not be installed." ; exit 1 ; } ;
|
|
185
|
+
|
|
186
|
+
# The accounts before the courses: the sample courses are the instructor's, and the student is enrolled.
|
|
187
|
+
if [ "${ADD_USERS}" == 'yes' ] ; then
|
|
188
|
+
set_learnpress_users ;
|
|
189
|
+
add_learnpress_users ;
|
|
190
|
+
cd ${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME} || exit 1 ;
|
|
191
|
+
fi
|
|
192
|
+
|
|
193
|
+
if [ "${SAMPLE_COURSE}" == 'yes' ] ; then
|
|
194
|
+
[ "${ADD_USERS}" == 'yes' ] || echo "Without --add-users the sample courses have only the accounts the site has." ;
|
|
195
|
+
learnpress_learning_site content || { echo "The sample courses could not be added." ; exit 1 ; } ;
|
|
196
|
+
fi
|
|
197
|
+
|
|
198
|
+
# The addresses of the courses, lessons and quizzes answer once the rules are written again.
|
|
199
|
+
ddev wp rewrite flush < /dev/null > /dev/null 2>&1 ;
|
|
200
|
+
echo "${doc_name} ${PROJECT_NAME} has been installed: WordPress $(ddev wp core version 2>/dev/null < /dev/null), LearnPress $(ddev wp plugin get learnpress --field=version 2>/dev/null < /dev/null).";
|
|
201
|
+
echo "Go to ${base_url}/courses/, and ${base_url}/wp-admin as ${account_name}";
|
|
202
|
+
|
|
203
|
+
if [ "${LAUNCH}" == 'yes' ] ; then
|
|
204
|
+
ddev launch /courses/ ;
|
|
205
|
+
fi
|
|
206
|
+
|
|
207
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
# Create the default accounts with WP-CLI, each with its role on the site and the name the site shows; an account that
|
|
211
|
+
# is already there keeps its password and gets its role and its name back. The list is loaded by the caller
|
|
212
|
+
# (set_learnpress_users): the core's add_users, the builder, the courses' tool, the testing setup.
|
|
213
|
+
function add_learnpress_users() {
|
|
214
|
+
learnpress_enter_project || return 1 ;
|
|
215
|
+
local user user_name user_mail user_password user_role user_fullname ;
|
|
216
|
+
for user in "${users[@]}" ; do
|
|
217
|
+
user_name="user_${user}_name"; user_mail="user_${user}_mail";
|
|
218
|
+
user_password="user_${user}_password"; user_role="user_${user}_role"; user_fullname="user_${user}_fullname";
|
|
219
|
+
|
|
220
|
+
echo " ---------------------------------------------------------------- ";
|
|
221
|
+
echo " User name: ${!user_name}";
|
|
222
|
+
echo " User mail: ${!user_mail}";
|
|
223
|
+
echo " User password: ${!user_password}";
|
|
224
|
+
echo " User role: ${!user_role}";
|
|
225
|
+
echo " Display name: ${!user_fullname:-${!user_name}}";
|
|
226
|
+
echo " ================================================================= ";
|
|
227
|
+
|
|
228
|
+
if ddev wp user get "${!user_name}" --field=ID < /dev/null > /dev/null 2>&1 ; then
|
|
229
|
+
echo " ${!user_name} is already there." ;
|
|
230
|
+
ddev wp user set-role "${!user_name}" "${!user_role}" < /dev/null > /dev/null ;
|
|
231
|
+
ddev wp user update "${!user_name}" --display_name="${!user_fullname:-${!user_name}}" < /dev/null > /dev/null ;
|
|
232
|
+
else
|
|
233
|
+
ddev wp user create "${!user_name}" "${!user_mail}" --role="${!user_role}" --user_pass="${!user_password}" --display_name="${!user_fullname:-${!user_name}}" < /dev/null ;
|
|
234
|
+
fi
|
|
235
|
+
done
|
|
236
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
# Delete the default accounts. WordPress deletes the instructor's courses, lessons, quizzes and questions with it, and
|
|
240
|
+
# the plugin's own tables keep what pointed at them (the accounts' enrolments, progress, history and orders, the
|
|
241
|
+
# sections of the courses and their items): learning-site.php takes that away once the accounts are gone. The sample
|
|
242
|
+
# courses come back with the accounts (--add-users, then --sample-course).
|
|
243
|
+
function cancel_learnpress_users() {
|
|
244
|
+
learnpress_enter_project || return 1 ;
|
|
245
|
+
local user user_name ;
|
|
246
|
+
for user in "${users[@]}" ; do
|
|
247
|
+
user_name="user_${user}_name";
|
|
248
|
+
echo " ---------------------------------------------------------------- ";
|
|
249
|
+
echo " User name: ${!user_name}";
|
|
250
|
+
echo " ================================================================= ";
|
|
251
|
+
if ddev wp user get "${!user_name}" --field=ID < /dev/null > /dev/null 2>&1 ; then
|
|
252
|
+
ddev wp user delete "${!user_name}" --yes < /dev/null ;
|
|
253
|
+
else
|
|
254
|
+
echo " ${!user_name} is not there." ;
|
|
255
|
+
fi
|
|
256
|
+
done
|
|
257
|
+
learnpress_learning_site orphans || echo " what the plugin's tables keep of the deleted accounts could not be taken away: is LearnPress active on the site?" ;
|
|
258
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
# What cmd-tools-learnpress-courses.sh does: the first of --add-users, --cancel-users, --sample-course, --tidy that was
|
|
262
|
+
# asked for; with none of them, what the courses hold.
|
|
263
|
+
function learnpress_courses_tool() {
|
|
264
|
+
trim_project_name ;
|
|
265
|
+
learnpress_enter_project || exit 1 ;
|
|
266
|
+
|
|
267
|
+
if ! ddev wp core is-installed < /dev/null > /dev/null 2>&1 ; then
|
|
268
|
+
ddev start -y < /dev/null || exit 1 ;
|
|
269
|
+
fi
|
|
270
|
+
if ! ddev wp plugin is-active learnpress < /dev/null > /dev/null 2>&1 ; then
|
|
271
|
+
echo "${doc_name}/${PROJECT_NAME}: LearnPress is not active on the site (is WordPress installed? bash cmd-tools-wordpress-cli.sh ${PROJECT_NAME})." ;
|
|
272
|
+
exit 1 ;
|
|
273
|
+
fi
|
|
274
|
+
|
|
275
|
+
if [ "${ADD_USERS}" == 'yes' ] ; then
|
|
276
|
+
set_learnpress_users ;
|
|
277
|
+
add_learnpress_users ;
|
|
278
|
+
elif [ "${CANCEL_USERS}" == 'yes' ] ; then
|
|
279
|
+
set_learnpress_users ;
|
|
280
|
+
cancel_learnpress_users ;
|
|
281
|
+
elif [ "${SAMPLE_COURSE}" == 'yes' ] ; then
|
|
282
|
+
learnpress_learning_site content || exit 1 ;
|
|
283
|
+
ddev wp rewrite flush < /dev/null > /dev/null 2>&1 ;
|
|
284
|
+
elif [ "${TIDY}" == 'yes' ] ; then
|
|
285
|
+
learnpress_learning_site reset || exit 1 ;
|
|
286
|
+
echo "The courses are back as the sample course left them." ;
|
|
287
|
+
else
|
|
288
|
+
echo "${doc_name}/${PROJECT_NAME}: LearnPress $(ddev wp plugin get learnpress --field=version 2>/dev/null < /dev/null) on WordPress $(ddev wp core version 2>/dev/null < /dev/null), at $(ddev wp option get siteurl 2>/dev/null < /dev/null)/courses/" ;
|
|
289
|
+
echo "" ;
|
|
290
|
+
learnpress_learning_site status || exit 1 ;
|
|
291
|
+
fi
|
|
292
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
# The step pack in the testing stack of a site of courses. The core's testing_configure calls this in the project
|
|
296
|
+
# folder once webship-js is scaffolded and before the dependencies are installed; for a project without LearnPress it
|
|
297
|
+
# changes nothing.
|
|
298
|
+
#
|
|
299
|
+
# The courses' pack extends the WordPress pack, and both go in the same profile: the WordPress plugin's hook runs first
|
|
300
|
+
# (its pack, its users registry, its first feature), whichever order the core calls the hooks in; then this one adds
|
|
301
|
+
# its pack to package.json and its step definitions to cucumber.js, the tags that keep its assertions that must fail
|
|
302
|
+
# out of a normal run, the courses' handles in the users registry (with the names the site shows, by which a step tells
|
|
303
|
+
# the account logged in), and a first feature for the courses when the project has none. Every part is skipped when it
|
|
304
|
+
# is already there, so a second run adds what the first missed and never resets a suite.
|
|
305
|
+
function testing_configure_learnpress() {
|
|
306
|
+
local project_path="$1";
|
|
307
|
+
learnpress_is_project "${project_path}" || return 0 ;
|
|
308
|
+
if [ ! -f "${project_path}/cucumber.js" ] || [ ! -f "${project_path}/package.json" ] ; then
|
|
309
|
+
echo " LearnPress: cucumber.js is not here yet — run the testing setup again once webship-js is scaffolded." ;
|
|
310
|
+
return 1 ;
|
|
311
|
+
fi
|
|
312
|
+
|
|
313
|
+
if declare -f testing_configure_wordpress > /dev/null ; then
|
|
314
|
+
testing_configure_wordpress "${project_path}" || return 1 ;
|
|
315
|
+
fi
|
|
316
|
+
|
|
317
|
+
echo "Adding the LearnPress step pack (${LEARNPRESS_STEPS_PACKAGE} ${LEARNPRESS_STEPS_VERSION}).";
|
|
318
|
+
set_learnpress_users ;
|
|
319
|
+
local registry="" user user_name user_mail user_password user_fullname handle ;
|
|
320
|
+
for user in "${users[@]}" ; do
|
|
321
|
+
user_name="user_${user}_name"; user_mail="user_${user}_mail"; user_password="user_${user}_password"; user_fullname="user_${user}_fullname";
|
|
322
|
+
# The WordPress pack's features call the administrator "admin".
|
|
323
|
+
handle="${user}" ; [ "${user}" == 'administrator' ] && handle="admin" ;
|
|
324
|
+
registry="${registry}${handle}|${!user_name}|${!user_password}|${!user_mail}|${!user_fullname}"$'\n' ;
|
|
325
|
+
done
|
|
326
|
+
|
|
327
|
+
python3 - "${project_path}" "${LEARNPRESS_STEPS_PACKAGE}" "${LEARNPRESS_STEPS_VERSION}" 'WP' "${registry}" <<'PYEOF' || return 1
|
|
328
|
+
import json, re, sys
|
|
329
|
+
|
|
330
|
+
project, pack, version, prefix, registry = sys.argv[1:6]
|
|
331
|
+
|
|
332
|
+
# package.json: the pack as a dev dependency, at the release line this plugin was proven on.
|
|
333
|
+
pkg_file = project + '/package.json'
|
|
334
|
+
pkg = json.load(open(pkg_file))
|
|
335
|
+
if pack not in pkg.get('dependencies', {}) and pack not in pkg.get('devDependencies', {}):
|
|
336
|
+
pkg.setdefault('devDependencies', {})[pack] = version
|
|
337
|
+
open(pkg_file, 'w').write(json.dumps(pkg, indent=2) + '\n')
|
|
338
|
+
print(' package.json: %s %s' % (pack, version))
|
|
339
|
+
|
|
340
|
+
cucumber_file = project + '/cucumber.js'
|
|
341
|
+
src = open(cucumber_file).read()
|
|
342
|
+
before = src
|
|
343
|
+
|
|
344
|
+
# The pack's step definitions, after webship-js's own (and the WordPress pack's, which it loads itself).
|
|
345
|
+
if ('node_modules/%s/' % pack) not in src:
|
|
346
|
+
line = "'node_modules/%s/tests/step-definitions/**/*.js'," % pack
|
|
347
|
+
anchor = re.search(r"^([ \t]*)'node_modules/@webship-js/wordpress-steps/tests/step-definitions/[^']*',.*$", src, re.M) \
|
|
348
|
+
or re.search(r"^([ \t]*)'node_modules/webship-js/tests/step-definitions/[^']*',.*$", src, re.M)
|
|
349
|
+
opening = re.search(r"^([ \t]*)require:[ \t]*\[[ \t]*$", src, re.M)
|
|
350
|
+
if anchor:
|
|
351
|
+
src = src[:anchor.end()] + '\n' + anchor.group(1) + line + src[anchor.end():]
|
|
352
|
+
elif opening:
|
|
353
|
+
src = src[:opening.end()] + '\n' + opening.group(1) + ' ' + line + src[opening.end():]
|
|
354
|
+
else:
|
|
355
|
+
sys.exit(" cucumber.js has no require list this can add to. Add this line to it:\n " + line)
|
|
356
|
+
print(' cucumber.js: the step definitions of %s' % pack)
|
|
357
|
+
|
|
358
|
+
# The pack's assertions that must fail are no part of a normal run.
|
|
359
|
+
if not re.search(r"^[ \t]*tags:", src, re.M):
|
|
360
|
+
default = re.search(r"^([ \t]*)default:[ \t]*\{[ \t]*$", src, re.M)
|
|
361
|
+
if default:
|
|
362
|
+
pad = default.group(1) + ' '
|
|
363
|
+
src = src[:default.end()] + '\n' + pad + "// Work in progress and the assertions that must fail (@must-fail) stay out of a normal run.\n" \
|
|
364
|
+
+ pad + "tags: process.env.CUCUMBER_TAGS || 'not @wip and not @must-fail'," + src[default.end():]
|
|
365
|
+
print(' cucumber.js: the tags that keep the assertions that must fail out of a normal run')
|
|
366
|
+
|
|
367
|
+
world = re.search(r"^([ \t]*)worldParameters:[ \t]*\{[ \t]*$", src, re.M)
|
|
368
|
+
if not world:
|
|
369
|
+
sys.exit(" cucumber.js has no worldParameters block to add the users registry to.")
|
|
370
|
+
pad = world.group(1) + ' '
|
|
371
|
+
|
|
372
|
+
rows = [r.split('|') for r in registry.splitlines() if r.strip()]
|
|
373
|
+
entry = lambda handle, login, password, mail, name: "%s: { username: process.env.%s_%s_USER || '%s', password: process.env.%s_%s_PASSWORD || '%s', email: '%s', name: '%s' }," % (
|
|
374
|
+
handle, prefix, handle.upper(), login, prefix, handle.upper(), password, mail, name)
|
|
375
|
+
users = re.search(r"^([ \t]*)users:[ \t]*\{[ \t]*$", src, re.M)
|
|
376
|
+
if users:
|
|
377
|
+
# The registry the WordPress plugin wrote: the courses' handles it does not have go in at its start, and a handle it
|
|
378
|
+
# has without an address or a name (admin) gets the address and the name the site shows.
|
|
379
|
+
missing = [r for r in rows if not re.search(r"^[ \t]*%s:[ \t]*\{" % re.escape(r[0]), src, re.M)]
|
|
380
|
+
if missing:
|
|
381
|
+
inner = users.group(1) + ' '
|
|
382
|
+
src = src[:users.end()] + '\n' + '\n'.join(inner + entry(*r) for r in missing) + src[users.end():]
|
|
383
|
+
print(' cucumber.js: the courses\' accounts in the users registry (%s)' % ', '.join(r[0] for r in missing))
|
|
384
|
+
for handle, login, password, mail, name in rows:
|
|
385
|
+
line = re.search(r"^([ \t]*%s:[ \t]*\{)([^\n]*)(\},?[ \t]*)$" % re.escape(handle), src, re.M)
|
|
386
|
+
if line and 'email:' not in line.group(2):
|
|
387
|
+
src = src[:line.start()] + line.group(1) + line.group(2).rstrip() + ", email: '%s' " % mail + line.group(3) + src[line.end():]
|
|
388
|
+
line = re.search(r"^([ \t]*%s:[ \t]*\{)([^\n]*)(\},?[ \t]*)$" % re.escape(handle), src, re.M)
|
|
389
|
+
if line and not re.search(r"(?<![A-Za-z_])name:", line.group(2)):
|
|
390
|
+
src = src[:line.start()] + line.group(1) + line.group(2).rstrip() + ", name: '%s' " % name + line.group(3) + src[line.end():]
|
|
391
|
+
else:
|
|
392
|
+
block = [
|
|
393
|
+
pad + "// The users registry: a handle a scenario reads, mapped to an account of this site (the default",
|
|
394
|
+
pad + "// accounts: cmd-tools-add-users.sh <project> learnpress). Override one with %s_<HANDLE>_USER and %s_<HANDLE>_PASSWORD." % (prefix, prefix),
|
|
395
|
+
pad + "users: {",
|
|
396
|
+
] + [pad + ' ' + entry(*r) for r in rows] + [pad + "},"]
|
|
397
|
+
src = src[:world.end()] + '\n' + '\n'.join(block) + src[world.end():]
|
|
398
|
+
print(' cucumber.js: the users registry (%s)' % ', '.join(r[0] for r in rows))
|
|
399
|
+
|
|
400
|
+
if src != before:
|
|
401
|
+
open(cucumber_file, 'w').write(src)
|
|
402
|
+
PYEOF
|
|
403
|
+
|
|
404
|
+
# A first feature for the courses, when the project has none: the course list, a course, each account in its place.
|
|
405
|
+
local feature="${WORKSPACE_SCRIPTS}/plugins/learnpress/courses.feature" ;
|
|
406
|
+
if [ -f "${feature}" ] && [ ! -f "${project_path}/tests/features/courses.feature" ] ; then
|
|
407
|
+
mkdir -p "${project_path}/tests/features" && cp "${feature}" "${project_path}/tests/features/courses.feature" \
|
|
408
|
+
&& echo " tests/features/courses.feature: a first feature for the courses" ;
|
|
409
|
+
fi
|
|
410
|
+
|
|
411
|
+
# The scenarios log in as the default accounts: make sure an installed site has them.
|
|
412
|
+
if ddev wp core is-installed < /dev/null > /dev/null 2>&1 ; then
|
|
413
|
+
( add_learnpress_users > /dev/null ) && echo " the default accounts of the courses are on the site (${users[*]})" ;
|
|
414
|
+
fi
|
|
415
|
+
}
|