@webship.co/workspace-craft-cms 0.0.0-stage → 1.0.8
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/README.md +214 -2
- package/ai/agents/craft-cms-site-builder.md +120 -0
- package/ai/agents/craft-cms-tester.md +139 -0
- package/ai/commands/craft-cms-test.md +90 -0
- package/ai/prompts/craft-cms-build-and-test.md +27 -0
- package/ai/skills/craft-cms-scenarios/SKILL.md +179 -0
- package/ai/skills/craft-cms-scenarios/examples/control-panel-navigation.feature +34 -0
- package/ai/skills/craft-cms-scenarios/examples/control-panel-session.feature +31 -0
- package/ai/skills/craft-cms-scenarios/examples/front-page.feature +15 -0
- package/commands/cmd-craft-cms-project.sh +35 -0
- package/commands/cmd-tools-craft-cms-cli.sh +26 -0
- package/dist/src/index.d.ts +32 -0
- package/dist/src/index.js +54 -0
- package/dist/src/index.js.map +1 -0
- package/docs/plugin-items-pattern.md +150 -0
- package/features/craft-cms.feature +30 -0
- package/package.json +95 -4
- package/scripts/args/arg-craft-cms-cli.sh +25 -0
- package/scripts/args/arg-craft-cms.sh +25 -0
- package/scripts/functions/fun-craft-cms.sh +333 -0
- package/testing/site.feature +39 -0
package/package.json
CHANGED
|
@@ -1,6 +1,97 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webship.co/workspace-craft-cms",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.8",
|
|
4
|
+
"description": "Craft CMS for Webship Workspace: the builder (`cmd-craft-cms-project.sh`) and the craft console tool in every sites folder, the default account of the free Solo edition, the Craft CMS step pack wired into the testing setup, and its AI items in their folders: two agents, a skill, a command and a prompt.",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"types": "dist/src/index.d.ts",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/webship/workspace-craft-cms.git"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/src",
|
|
14
|
+
"ai",
|
|
15
|
+
"commands",
|
|
16
|
+
"docs",
|
|
17
|
+
"features",
|
|
18
|
+
"scripts",
|
|
19
|
+
"testing",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -p tsconfig.json",
|
|
24
|
+
"prepare": "npm run build",
|
|
25
|
+
"test": "npm run build && node --test dist/tests/*.test.js",
|
|
26
|
+
"lint": "tsc -p tsconfig.json --noEmit"
|
|
27
|
+
},
|
|
28
|
+
"workspacePlugin": {
|
|
29
|
+
"name": "craft-cms",
|
|
30
|
+
"label": "Craft CMS",
|
|
31
|
+
"needs": [
|
|
32
|
+
[
|
|
33
|
+
"dev",
|
|
34
|
+
"test",
|
|
35
|
+
"sandboxes",
|
|
36
|
+
"demos"
|
|
37
|
+
],
|
|
38
|
+
"ai-agents",
|
|
39
|
+
"ai-skills",
|
|
40
|
+
"ai-commands",
|
|
41
|
+
"ai-prompts"
|
|
42
|
+
],
|
|
43
|
+
"commands": {
|
|
44
|
+
"types": [
|
|
45
|
+
"sites"
|
|
46
|
+
],
|
|
47
|
+
"workspaces": [
|
|
48
|
+
"dev",
|
|
49
|
+
"test",
|
|
50
|
+
"sandboxes",
|
|
51
|
+
"demos"
|
|
52
|
+
],
|
|
53
|
+
"files": [
|
|
54
|
+
"commands/cmd-craft-cms-project.sh",
|
|
55
|
+
"commands/cmd-tools-craft-cms-cli.sh"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"functions": [
|
|
60
|
+
"scripts/functions/fun-craft-cms.sh"
|
|
61
|
+
],
|
|
62
|
+
"args": [
|
|
63
|
+
"scripts/args/arg-craft-cms.sh",
|
|
64
|
+
"scripts/args/arg-craft-cms-cli.sh"
|
|
65
|
+
],
|
|
66
|
+
"machine": [
|
|
67
|
+
"testing/site.feature"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"ai": {
|
|
71
|
+
"agents": [
|
|
72
|
+
"ai/agents/craft-cms-site-builder.md",
|
|
73
|
+
"ai/agents/craft-cms-tester.md"
|
|
74
|
+
],
|
|
75
|
+
"skills": [
|
|
76
|
+
"ai/skills/craft-cms-scenarios"
|
|
77
|
+
],
|
|
78
|
+
"commands": [
|
|
79
|
+
"ai/commands/craft-cms-test.md"
|
|
80
|
+
],
|
|
81
|
+
"prompts": [
|
|
82
|
+
"ai/prompts/craft-cms-build-and-test.md"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
"features": [
|
|
86
|
+
"features/craft-cms.feature"
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@types/node": "^24.0.0",
|
|
91
|
+
"@webship.co/workspace-plugin-api": "^1.0.7",
|
|
92
|
+
"typescript": "^5.9.0"
|
|
93
|
+
},
|
|
94
|
+
"publishConfig": {
|
|
95
|
+
"access": "public"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
argparse "$@" <<ARGEOF || exit 1
|
|
4
|
+
parser.add_argument('PROJECT_NAME',
|
|
5
|
+
help='The Craft CMS project in this workspace.')
|
|
6
|
+
parser.add_argument('-r', '--run',
|
|
7
|
+
default="_none_",
|
|
8
|
+
help='A craft console command to run in the project, without the leading php craft. Example: --run "project-config/apply"')
|
|
9
|
+
parser.add_argument('-u', '--update',
|
|
10
|
+
action='store_true',
|
|
11
|
+
default=False,
|
|
12
|
+
help='Update Craft CMS and the plugins of the project to their latest releases, and clear the caches. The edition stays what it is.')
|
|
13
|
+
parser.add_argument('-f', '--flush',
|
|
14
|
+
action='store_true',
|
|
15
|
+
default=False,
|
|
16
|
+
help='Clear every cache, and nothing else.')
|
|
17
|
+
parser.add_argument('-a', '--add-users',
|
|
18
|
+
action='store_true',
|
|
19
|
+
default=False,
|
|
20
|
+
help='Say whether the one account of the site is the default account. The Solo edition has one account, so none is created.')
|
|
21
|
+
parser.add_argument('-c', '--cancel-users',
|
|
22
|
+
action='store_true',
|
|
23
|
+
default=False,
|
|
24
|
+
help='Say why the default account stays: it is the only account of the site.')
|
|
25
|
+
ARGEOF
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
argparse "$@" <<ARGEOF || exit 1
|
|
4
|
+
parser.add_argument('PROJECT_NAME',
|
|
5
|
+
help='The name of the project: its folder, its DDEV project and its host name.')
|
|
6
|
+
parser.add_argument('-v', '--version',
|
|
7
|
+
default="${site_version}",
|
|
8
|
+
help='The Craft CMS release, as a Composer constraint of craftcms/cms. Example: --version 5.8.0 [default %(default)s]')
|
|
9
|
+
parser.add_argument('-i', '--install',
|
|
10
|
+
action='store_true',
|
|
11
|
+
default=False,
|
|
12
|
+
help='Install Craft CMS on the free Solo edition, with the workspace account as its one account, an admin.')
|
|
13
|
+
parser.add_argument('-a', '--add-users',
|
|
14
|
+
action='store_true',
|
|
15
|
+
default=False,
|
|
16
|
+
help='With --install, make the one account of the site the default account instead: the one the test scenarios log in as. The Solo edition has no second account.')
|
|
17
|
+
parser.add_argument('-l', '--launch',
|
|
18
|
+
action='store_true',
|
|
19
|
+
default=False,
|
|
20
|
+
help='Open the site in a browser when it is ready.')
|
|
21
|
+
parser.add_argument('--php-version',
|
|
22
|
+
default="8.3",
|
|
23
|
+
choices=['8.4', '8.3', '8.2'],
|
|
24
|
+
help='PHP version for the project container. Example: --php-version 8.4 [default %(default)s]')
|
|
25
|
+
ARGEOF
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Craft CMS for the Webship Workspace: build a site, run the craft console on it, name its one
|
|
4
|
+
# account, and wire its step pack into the testing setup.
|
|
5
|
+
#
|
|
6
|
+
# Placed by `plugins.sh --install craft-cms` in core/scripts/plugins/craft-cms/functions/, where
|
|
7
|
+
# bootstrap sources it after the core's own functions. Everything runs in the project's container
|
|
8
|
+
# (DDEV by default: `ddev composer …`, `ddev exec php craft …`), never on the host. The container
|
|
9
|
+
# tool gives the project its database settings; nothing here writes any.
|
|
10
|
+
#
|
|
11
|
+
# The site is the free Solo edition and stays on it: it has ONE account, an admin, and no user
|
|
12
|
+
# groups. Nothing here enters a licence, switches a paid edition on (not even as a trial), or signs
|
|
13
|
+
# in to any account or store. So the list of default accounts has one entry, and it cannot be
|
|
14
|
+
# added to a site whose one account is somebody else's.
|
|
15
|
+
#
|
|
16
|
+
# Four names are the ones the core's tools look for, under the DDEV project type `craftcms`:
|
|
17
|
+
# set_craftcms_users the default account (cmd-tools-add-users.sh <project> craftcms)
|
|
18
|
+
# add_craftcms_users say whether it is on the site (the same tool, and --add-users of the builder)
|
|
19
|
+
# cancel_craftcms_users say why it stays (cmd-tools-cancel-users.sh <project> craftcms)
|
|
20
|
+
# testing_configure_craftcms the step pack in the testing stack (cmd-tools-testing.sh <project>)
|
|
21
|
+
|
|
22
|
+
# The step pack a Craft CMS project is tested with, and the release line it is required at.
|
|
23
|
+
readonly CRAFT_STEPS_PACKAGE='@webship-js/craft-cms-steps';
|
|
24
|
+
readonly CRAFT_STEPS_VERSION='^2.0.0';
|
|
25
|
+
|
|
26
|
+
# The default account: the one a scenario logs in as. The Solo edition has one account, so the
|
|
27
|
+
# list has one entry. Accounts are configuration; a test suite never creates or deletes one.
|
|
28
|
+
function set_craftcms_users() {
|
|
29
|
+
users=(administrator);
|
|
30
|
+
printf -v "user_administrator_name" '%s' 'administrator' ;
|
|
31
|
+
printf -v "user_administrator_mail" '%s' 'administrator@example.com' ;
|
|
32
|
+
printf -v "user_administrator_password" '%s' 'dD.123123ddd' ;
|
|
33
|
+
printf -v "user_administrator_role" '%s' 'admin' ;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# Is this folder a Craft CMS project? Its DDEV project type says so.
|
|
37
|
+
function craftcms_is_project() {
|
|
38
|
+
local project_path="$1";
|
|
39
|
+
grep -qE '^type:[[:space:]]*"?craftcms"?[[:space:]]*$' "${project_path}/.ddev/config.yaml" 2>/dev/null ;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# Is the site installed? The installer writes the project config, and nothing else does.
|
|
43
|
+
function craftcms_is_installed() {
|
|
44
|
+
[ -f "$1/config/project/project.yaml" ] ;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# Go to the project a tool was asked about, or say why not.
|
|
48
|
+
function craftcms_enter_project() {
|
|
49
|
+
local project_path="${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}";
|
|
50
|
+
if [ ! -d "${project_path}" ] ; then
|
|
51
|
+
echo "No project ${PROJECT_NAME} in ${WORKSPACE_ROOT}/${doc_name}." ;
|
|
52
|
+
return 1 ;
|
|
53
|
+
fi
|
|
54
|
+
if ! craftcms_is_project "${project_path}" ; then
|
|
55
|
+
echo "${doc_name}/${PROJECT_NAME} is not a Craft CMS project (its .ddev/config.yaml does not say type: craftcms)." ;
|
|
56
|
+
return 1 ;
|
|
57
|
+
fi
|
|
58
|
+
cd "${project_path}" || return 1 ;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# Run the craft console in the container of the project the shell is in. Every argument is
|
|
62
|
+
# quoted for the container's shell, so a site name of two words arrives as one argument.
|
|
63
|
+
function craftcms_cli() {
|
|
64
|
+
local line="php craft" arg ;
|
|
65
|
+
for arg in "$@" ; do
|
|
66
|
+
line="${line} $(printf '%q' "${arg}")" ;
|
|
67
|
+
done
|
|
68
|
+
ddev exec "${line}" ;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# Is the admin of this username the site's account?
|
|
72
|
+
function craftcms_user_exists() {
|
|
73
|
+
craftcms_cli users/list-admins 2>/dev/null | sed 's/\x1b\[[0-9;]*m//g' | grep -qE "(^|[^A-Za-z0-9._-])$1([^A-Za-z0-9._@-]|$)" ;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
# The release of Craft CMS in the project the shell is in.
|
|
77
|
+
function craftcms_version() {
|
|
78
|
+
ddev composer show craftcms/cms 2>/dev/null | awk '/^versions/ {print $NF}' | tr -d '\r' ;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# The edition the site is on, from its project config.
|
|
82
|
+
function craftcms_edition() {
|
|
83
|
+
sed -nE 's/^[[:space:]]+edition:[[:space:]]*([a-z]+).*$/\1/p' "$1/config/project/project.yaml" 2>/dev/null | head -1 ;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# Build a Craft CMS site from nothing: the container, the code, and with --install the site itself.
|
|
87
|
+
function craftcms_build() {
|
|
88
|
+
trim_project_name ;
|
|
89
|
+
local base_url="https://${PROJECT_NAME}.ddev.site" ;
|
|
90
|
+
local version="${VERSION:-${site_version:-^5}}" ;
|
|
91
|
+
local php_version="${PHP_VERSION:-${site_php_version:-8.3}}" ;
|
|
92
|
+
local admin_name="${account_name}" admin_pass="${account_pass}" admin_mail="${account_mail}" ;
|
|
93
|
+
|
|
94
|
+
cd ${WORKSPACE_ROOT}/${doc_name} || exit 1 ;
|
|
95
|
+
|
|
96
|
+
drop_database ;
|
|
97
|
+
rm -rf "${PROJECT_NAME}" ;
|
|
98
|
+
mkdir -p "${PROJECT_NAME}" ;
|
|
99
|
+
cd ${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME} || exit 1 ;
|
|
100
|
+
|
|
101
|
+
ddev config --project-type=craftcms --docroot="${distribution_webroot}" --project-name=${PROJECT_NAME} \
|
|
102
|
+
--php-version=${php_version} --nodejs-version=$(ddev_nodejs_version) || exit 1 ;
|
|
103
|
+
ddev_up start -y || exit 1 ;
|
|
104
|
+
|
|
105
|
+
# The starter project. Its post-create script opens an installer that asks questions, so the
|
|
106
|
+
# scripts are skipped and their steps are done here: the environment file and the project's own
|
|
107
|
+
# composer.json.
|
|
108
|
+
ddev composer create-project "${project_template}" --no-scripts --no-interaction \
|
|
109
|
+
|| { echo "composer create-project ${project_template} failed." ; exit 1 ; } ;
|
|
110
|
+
cp .env.example.dev .env || exit 1 ;
|
|
111
|
+
rm -f composer.json && mv composer.json.default composer.json || exit 1 ;
|
|
112
|
+
if [ ! "${version}" == '^5' ] ; then
|
|
113
|
+
ddev composer require "craftcms/cms:${version}" --no-interaction --with-all-dependencies \
|
|
114
|
+
|| { echo "composer require craftcms/cms:${version} failed." ; exit 1 ; } ;
|
|
115
|
+
fi
|
|
116
|
+
|
|
117
|
+
craftcms_cli setup/keys || exit 1 ;
|
|
118
|
+
|
|
119
|
+
if [ "${INSTALL}" == 'yes' ] ; then
|
|
120
|
+
if [ "${ADD_USERS}" == 'yes' ] ; then
|
|
121
|
+
# The Solo edition has one account. With --add-users it is the default account, so that a
|
|
122
|
+
# scenario logs in with an account made for tests and never with the workspace account.
|
|
123
|
+
set_craftcms_users ;
|
|
124
|
+
admin_name="${user_administrator_name}" ; admin_pass="${user_administrator_password}" ; admin_mail="${user_administrator_mail}" ;
|
|
125
|
+
echo "The free Solo edition has one account: it is the default account, ${admin_name}." ;
|
|
126
|
+
fi
|
|
127
|
+
|
|
128
|
+
craftcms_cli install/craft --interactive=0 \
|
|
129
|
+
--username="${admin_name}" --password="${admin_pass}" --email="${admin_mail}" \
|
|
130
|
+
--site-name="${doc_name} ${PROJECT_NAME}" --site-url="${base_url}" --language=en-US \
|
|
131
|
+
|| { echo "craft install/craft failed. Craft CMS asks for a password of 6 characters or more: see account: pass in core/config/settings.yml." ; exit 1 ; } ;
|
|
132
|
+
|
|
133
|
+
echo "${doc_name} ${PROJECT_NAME} has been installed: Craft CMS $(craftcms_version), the $(craftcms_edition "$(pwd)") edition.";
|
|
134
|
+
echo "Go to ${base_url}/admin and log in as ${admin_name}";
|
|
135
|
+
else
|
|
136
|
+
[ "${ADD_USERS}" == 'yes' ] && echo "--add-users needs --install: there is no site to give an account to yet." ;
|
|
137
|
+
echo "${doc_name} ${PROJECT_NAME} is ready to install.";
|
|
138
|
+
echo "Go to ${base_url}/admin/install";
|
|
139
|
+
fi
|
|
140
|
+
|
|
141
|
+
if [ "${LAUNCH}" == 'yes' ] ; then
|
|
142
|
+
ddev launch ;
|
|
143
|
+
fi
|
|
144
|
+
|
|
145
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
# The default account on a site that is already there. The Solo edition has one account and the
|
|
149
|
+
# installer made it, so there is nothing to create: this says whether that account is the
|
|
150
|
+
# default one, and what to do when it is not.
|
|
151
|
+
# The list is loaded by the caller (set_craftcms_users): the core's add_users, the builder, the CLI tool.
|
|
152
|
+
function add_craftcms_users() {
|
|
153
|
+
craftcms_enter_project || return 1 ;
|
|
154
|
+
local user user_name user_mail user_role status=0 ;
|
|
155
|
+
for user in "${users[@]}" ; do
|
|
156
|
+
user_name="user_${user}_name"; user_mail="user_${user}_mail"; user_role="user_${user}_role";
|
|
157
|
+
|
|
158
|
+
echo " ---------------------------------------------------------------- ";
|
|
159
|
+
echo " User name: ${!user_name}";
|
|
160
|
+
echo " User mail: ${!user_mail}";
|
|
161
|
+
echo " User role: ${!user_role}";
|
|
162
|
+
echo " ================================================================= ";
|
|
163
|
+
|
|
164
|
+
if craftcms_user_exists "${!user_name}" ; then
|
|
165
|
+
echo " ${!user_name} is already there: it is the site's account." ;
|
|
166
|
+
else
|
|
167
|
+
echo " The free Solo edition has one account, and this site's is not ${!user_name}." ;
|
|
168
|
+
echo " A second account needs a paid edition, which this workspace does not switch on." ;
|
|
169
|
+
echo " Build the site again with --install --add-users to make its one account the default account." ;
|
|
170
|
+
status=1 ;
|
|
171
|
+
fi
|
|
172
|
+
done
|
|
173
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
174
|
+
return ${status} ;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
# The default account cannot be taken away: it is the site's only account.
|
|
178
|
+
function cancel_craftcms_users() {
|
|
179
|
+
craftcms_enter_project || return 1 ;
|
|
180
|
+
local user user_name ;
|
|
181
|
+
for user in "${users[@]}" ; do
|
|
182
|
+
user_name="user_${user}_name";
|
|
183
|
+
echo " ---------------------------------------------------------------- ";
|
|
184
|
+
echo " User name: ${!user_name}";
|
|
185
|
+
echo " ================================================================= ";
|
|
186
|
+
if craftcms_user_exists "${!user_name}" ; then
|
|
187
|
+
echo " ${!user_name} stays: the free Solo edition has one account, and a site cannot be without it." ;
|
|
188
|
+
echo " Build the site again with --install, and without --add-users, to give that account to the workspace account." ;
|
|
189
|
+
else
|
|
190
|
+
echo " ${!user_name} is not there." ;
|
|
191
|
+
fi
|
|
192
|
+
done
|
|
193
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
# What cmd-tools-craft-cms-cli.sh does: the first of --run, --update, --flush, --add-users,
|
|
197
|
+
# --cancel-users that was asked for; with none of them, what the site is.
|
|
198
|
+
function craftcms_cli_tool() {
|
|
199
|
+
trim_project_name ;
|
|
200
|
+
craftcms_enter_project || exit 1 ;
|
|
201
|
+
|
|
202
|
+
if ! ddev describe -j 2>/dev/null | grep -q '"status":"running"' ; then
|
|
203
|
+
ddev start -y || exit 1 ;
|
|
204
|
+
fi
|
|
205
|
+
|
|
206
|
+
if [ ! "${RUN}" == '_none_' ] ; then
|
|
207
|
+
# One string on purpose: --run "project-config/apply --force" is a command and its arguments.
|
|
208
|
+
ddev exec "php craft ${RUN}" ;
|
|
209
|
+
exit $? ;
|
|
210
|
+
fi
|
|
211
|
+
|
|
212
|
+
if [ "${UPDATE}" == 'yes' ] ; then
|
|
213
|
+
craftcms_cli update all --interactive=0 && craftcms_cli clear-caches/all ;
|
|
214
|
+
elif [ "${FLUSH}" == 'yes' ] ; then
|
|
215
|
+
craftcms_cli clear-caches/all ;
|
|
216
|
+
elif [ "${ADD_USERS}" == 'yes' ] ; then
|
|
217
|
+
set_craftcms_users ;
|
|
218
|
+
add_craftcms_users ;
|
|
219
|
+
elif [ "${CANCEL_USERS}" == 'yes' ] ; then
|
|
220
|
+
set_craftcms_users ;
|
|
221
|
+
cancel_craftcms_users ;
|
|
222
|
+
else
|
|
223
|
+
echo "${doc_name}/${PROJECT_NAME}: Craft CMS $(craftcms_version) at https://${PROJECT_NAME}.ddev.site" ;
|
|
224
|
+
if craftcms_is_installed "$(pwd)" ; then
|
|
225
|
+
echo "Edition: $(craftcms_edition "$(pwd)")" ;
|
|
226
|
+
echo "" ; echo "The account:" ; craftcms_cli users/list-admins ;
|
|
227
|
+
echo "" ; echo "Plugins:" ; craftcms_cli plugin/list ;
|
|
228
|
+
else
|
|
229
|
+
echo "The site is not installed yet: open its address at /admin/install, or build it again with --install." ;
|
|
230
|
+
fi
|
|
231
|
+
fi
|
|
232
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
# The step pack in the testing stack of a Craft CMS project. The core's testing_configure calls
|
|
236
|
+
# this in the project folder once webship-js is scaffolded and before the dependencies are
|
|
237
|
+
# installed; for a project that is not Craft CMS it changes nothing.
|
|
238
|
+
#
|
|
239
|
+
# It adds the pack to package.json, lists its step definitions in cucumber.js after webship-js's
|
|
240
|
+
# own, gives cucumber.js the users registry of the default account (a handle a scenario reads,
|
|
241
|
+
# mapped to an account; never the workspace account), and writes a first feature when the project
|
|
242
|
+
# has none of its own. Every part is skipped when it is already there, so a second run adds what
|
|
243
|
+
# the first missed and never resets a suite.
|
|
244
|
+
function testing_configure_craftcms() {
|
|
245
|
+
local project_path="$1";
|
|
246
|
+
craftcms_is_project "${project_path}" || return 0 ;
|
|
247
|
+
if [ ! -f "${project_path}/cucumber.js" ] || [ ! -f "${project_path}/package.json" ] ; then
|
|
248
|
+
echo " Craft CMS: cucumber.js is not here yet — run the testing setup again once webship-js is scaffolded." ;
|
|
249
|
+
return 1 ;
|
|
250
|
+
fi
|
|
251
|
+
|
|
252
|
+
echo "Adding the Craft CMS step pack (${CRAFT_STEPS_PACKAGE} ${CRAFT_STEPS_VERSION}).";
|
|
253
|
+
set_craftcms_users ;
|
|
254
|
+
local registry="" user user_name user_password handle ;
|
|
255
|
+
for user in "${users[@]}" ; do
|
|
256
|
+
user_name="user_${user}_name"; user_password="user_${user}_password";
|
|
257
|
+
# The pack's features call the admin "admin".
|
|
258
|
+
handle="${user}" ; [ "${user}" == 'administrator' ] && handle="admin" ;
|
|
259
|
+
registry="${registry}${handle}|${!user_name}|${!user_password}"$'\n' ;
|
|
260
|
+
done
|
|
261
|
+
|
|
262
|
+
# The pack reads ADMIN_USER and ADMIN_PASSWORD, with nothing in front: the registry keeps its names.
|
|
263
|
+
python3 - "${project_path}" "${CRAFT_STEPS_PACKAGE}" "${CRAFT_STEPS_VERSION}" '' 'PASSWORD' "${registry}" <<'PYEOF' || return 1
|
|
264
|
+
import json, re, sys
|
|
265
|
+
|
|
266
|
+
project, pack, version, prefix, secret, registry = sys.argv[1:7]
|
|
267
|
+
|
|
268
|
+
# package.json: the pack as a dev dependency, at the release line this plugin was proven on.
|
|
269
|
+
pkg_file = project + '/package.json'
|
|
270
|
+
pkg = json.load(open(pkg_file))
|
|
271
|
+
if pack not in pkg.get('dependencies', {}) and pack not in pkg.get('devDependencies', {}):
|
|
272
|
+
pkg.setdefault('devDependencies', {})[pack] = version
|
|
273
|
+
open(pkg_file, 'w').write(json.dumps(pkg, indent=2) + '\n')
|
|
274
|
+
print(' package.json: %s %s' % (pack, version))
|
|
275
|
+
|
|
276
|
+
# cucumber.js: the pack's step definitions after webship-js's own, and the users registry.
|
|
277
|
+
cucumber_file = project + '/cucumber.js'
|
|
278
|
+
src = open(cucumber_file).read()
|
|
279
|
+
before = src
|
|
280
|
+
|
|
281
|
+
if ('node_modules/%s/' % pack) not in src:
|
|
282
|
+
line = "'node_modules/%s/tests/step-definitions/**/*.js'," % pack
|
|
283
|
+
core = re.search(r"^([ \t]*)'node_modules/webship-js/tests/step-definitions/[^']*',.*$", src, re.M)
|
|
284
|
+
opening = re.search(r"^([ \t]*)require:[ \t]*\[[ \t]*$", src, re.M)
|
|
285
|
+
if core:
|
|
286
|
+
src = src[:core.end()] + '\n' + core.group(1) + line + src[core.end():]
|
|
287
|
+
elif opening:
|
|
288
|
+
src = src[:opening.end()] + '\n' + opening.group(1) + ' ' + line + src[opening.end():]
|
|
289
|
+
else:
|
|
290
|
+
sys.exit(" cucumber.js has no require list this can add to. Add this line to it:\n " + line)
|
|
291
|
+
print(' cucumber.js: the step definitions of %s' % pack)
|
|
292
|
+
|
|
293
|
+
if not re.search(r"^[ \t]*users:[ \t]*\{", src, re.M):
|
|
294
|
+
world = re.search(r"^([ \t]*)worldParameters:[ \t]*\{[ \t]*$", src, re.M)
|
|
295
|
+
if not world:
|
|
296
|
+
sys.exit(" cucumber.js has no worldParameters block to add the users registry to.")
|
|
297
|
+
pad = world.group(1) + ' '
|
|
298
|
+
lead = '%s_' % prefix if prefix else ''
|
|
299
|
+
rows = [r.split('|') for r in registry.splitlines() if r.strip()]
|
|
300
|
+
block = [
|
|
301
|
+
pad + "// The users registry: a handle a scenario reads, mapped to an account of this site (the default",
|
|
302
|
+
pad + "// accounts: cmd-tools-add-users.sh). Override one with %s<HANDLE>_USER and %s<HANDLE>_%s." % (lead, lead, secret),
|
|
303
|
+
pad + "users: {",
|
|
304
|
+
]
|
|
305
|
+
for handle, name, password in rows:
|
|
306
|
+
env = ('%s_' % prefix if prefix else '') + handle.upper()
|
|
307
|
+
block.append(pad + " %s: { username: process.env.%s_USER || '%s', password: process.env.%s_%s || '%s' }," % (handle, env, name, env, secret, password))
|
|
308
|
+
block.append(pad + "},")
|
|
309
|
+
src = src[:world.end()] + '\n' + '\n'.join(block) + src[world.end():]
|
|
310
|
+
print(' cucumber.js: the users registry (%s)' % ', '.join(r[0] for r in rows))
|
|
311
|
+
|
|
312
|
+
if src != before:
|
|
313
|
+
open(cucumber_file, 'w').write(src)
|
|
314
|
+
PYEOF
|
|
315
|
+
|
|
316
|
+
# A first feature, when the project has none for the site yet: the front page, the login form,
|
|
317
|
+
# the admin account.
|
|
318
|
+
local feature="${WORKSPACE_SCRIPTS}/plugins/craft-cms/site.feature" ;
|
|
319
|
+
if [ -f "${feature}" ] && [ ! -f "${project_path}/tests/features/site.feature" ] ; then
|
|
320
|
+
mkdir -p "${project_path}/tests/features" && cp "${feature}" "${project_path}/tests/features/site.feature" \
|
|
321
|
+
&& echo " tests/features/site.feature: a first feature for the site" ;
|
|
322
|
+
fi
|
|
323
|
+
|
|
324
|
+
# The scenarios log in as the default account. A site has one account: say when it is another.
|
|
325
|
+
if craftcms_is_installed "${project_path}" ; then
|
|
326
|
+
if craftcms_user_exists "${user_administrator_name}" ; then
|
|
327
|
+
echo " the default account is the site's account (${user_administrator_name})" ;
|
|
328
|
+
else
|
|
329
|
+
echo " The site's one account is not the default account (${user_administrator_name}): the free Solo edition has no room for a second." ;
|
|
330
|
+
echo " Give a run the site's own account with ADMIN_USER and ADMIN_PASSWORD in its environment, or build the site again with --install --add-users." ;
|
|
331
|
+
fi
|
|
332
|
+
fi
|
|
333
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Feature: The site answers and its account works
|
|
2
|
+
As the owner of the site
|
|
3
|
+
I want the front page, the login form and the admin account to work
|
|
4
|
+
So that a build that came out broken is caught before anything else is tested
|
|
5
|
+
|
|
6
|
+
# Placed by the workspace's testing setup as a starting point: it is yours to change.
|
|
7
|
+
# The site is on the free edition, which has one account, an admin: the scenarios log in with
|
|
8
|
+
# it by the handle "admin" of the users registry in cucumber.js, so no password is written here.
|
|
9
|
+
|
|
10
|
+
@critical
|
|
11
|
+
Scenario: The front page is served
|
|
12
|
+
Given I am an anonymous user
|
|
13
|
+
And I am on the homepage
|
|
14
|
+
Then the response status code should be 200
|
|
15
|
+
And the page should have a title
|
|
16
|
+
|
|
17
|
+
@critical
|
|
18
|
+
Scenario: A visitor is sent to the login form
|
|
19
|
+
Given I am an anonymous user
|
|
20
|
+
When I go to "/admin/content/entries"
|
|
21
|
+
Then I should see the control panel login form
|
|
22
|
+
And I should not be logged in to the control panel
|
|
23
|
+
|
|
24
|
+
Scenario: The admin logs in
|
|
25
|
+
Given I am logged in to the control panel as "admin"
|
|
26
|
+
Then I should be logged in to the control panel as "admin"
|
|
27
|
+
And the control panel heading should be "Dashboard"
|
|
28
|
+
|
|
29
|
+
Scenario: The admin may open the pages of an admin
|
|
30
|
+
Given I am logged in to the control panel as "admin"
|
|
31
|
+
Then I should be allowed to open the control panel page "entries"
|
|
32
|
+
And I should be allowed to open the control panel page "settings"
|
|
33
|
+
And I should be allowed to open the control panel page "utilities"
|
|
34
|
+
|
|
35
|
+
Scenario: Logging out ends the session
|
|
36
|
+
Given I am logged in to the control panel as "admin"
|
|
37
|
+
When I log out of the control panel
|
|
38
|
+
Then I should not be logged in to the control panel
|
|
39
|
+
And I should see the control panel login form
|