@webship-js/codeigniter-steps 0.0.0-stage → 2.0.1
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 +21 -0
- package/README.md +448 -2
- package/package.json +62 -4
- package/tests/features/README.md +24 -0
- package/tests/features/access.feature +52 -0
- package/tests/features/accessibility.feature +32 -0
- package/tests/features/development.feature +59 -0
- package/tests/features/forgery.feature +36 -0
- package/tests/features/framework-pages.feature +42 -0
- package/tests/features/login-link.feature +43 -0
- package/tests/features/registration.feature +65 -0
- package/tests/features/session.feature +104 -0
- package/tests/step-definitions/README.md +37 -0
- package/tests/step-definitions/codeigniter-access.steps.js +122 -0
- package/tests/step-definitions/codeigniter-forms.steps.js +217 -0
- package/tests/step-definitions/codeigniter-helpers.js +702 -0
- package/tests/step-definitions/codeigniter-mail.steps.js +117 -0
- package/tests/step-definitions/codeigniter-pages.steps.js +209 -0
- package/tests/step-definitions/codeigniter-session.steps.js +277 -0
- package/tests/step-definitions/codeigniter-toolbar.steps.js +154 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Webship.co
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,449 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/webship/codeigniter-steps/2.0.x/assets/logo.svg" alt="CodeIgniter logo" width="96"></p>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# codeigniter-steps
|
|
4
|
+
|
|
5
|
+
Cucumber step definitions for testing CodeIgniter apps with
|
|
6
|
+
[webship-js](https://webship.co/docs/webship-js/2.0.x), a BDD browser automation
|
|
7
|
+
harness built on Playwright and Cucumber-js.
|
|
8
|
+
|
|
9
|
+
A framework ships no fixed pages, so `@webship-js/codeigniter-steps` targets the
|
|
10
|
+
pages most real apps start from: the ones the official app starter and the
|
|
11
|
+
official auth library (Shield) give every new app, and the ones the framework
|
|
12
|
+
itself answers with. That is the session (logging in and out, a banned
|
|
13
|
+
account, a session that expires and a login that is remembered past it), the
|
|
14
|
+
login link the app mails, registration (through its refusals), groups and
|
|
15
|
+
permissions (who may open a page), the error and success messages of a page,
|
|
16
|
+
a form sent from another site or with an out-of-date security token, the
|
|
17
|
+
welcome page and the environment the app says it runs in, the 404 and 500
|
|
18
|
+
pages, the check that a live app shows no debug information, and, while the
|
|
19
|
+
app runs in development, the debug toolbar and the debug page. The steps are
|
|
20
|
+
proven on an app made from the app starter 4.7 with the auth library 1.4.
|
|
21
|
+
|
|
22
|
+
No step phrase names the framework or a library: a scenario reads `Given I am a
|
|
23
|
+
logged in user with the "admin" user` and `Then I should have access to
|
|
24
|
+
"/admin"`.
|
|
25
|
+
|
|
26
|
+
CI builds a real app with [DDEV](https://ddev.com) on the runner, the way the
|
|
27
|
+
app starter's documentation makes it, on two PHP versions, and runs the whole
|
|
28
|
+
suite against each, twice, on every push and pull request, then the assertions
|
|
29
|
+
that must fail and the development lane; see
|
|
30
|
+
[`.github/workflows/test.yml`](.github/workflows/test.yml).
|
|
31
|
+
|
|
32
|
+
## From nothing to a green run
|
|
33
|
+
|
|
34
|
+
What the machine needs: Docker, [DDEV](https://ddev.com), git, python3, and Node.js 24 or later with npm. PHP, Composer and the database run in DDEV's containers.
|
|
35
|
+
|
|
36
|
+
**1. The app.** The pack's own build script (the one CI runs) makes a new app in a DDEV project (type `php`, docroot `public`) with Composer: the app starter (`composer create-project codeigniter4/appstarter`), then the auth library (`composer require codeigniter4/shield` and its own `spark shield:setup`). It turns on CSRF protection for every form, adds four pages (see [A test app](#a-test-app)), creates the accounts of [Test users](#test-users), and runs the app as a live app runs (`CI_ENVIRONMENT = production`). It takes about a minute.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
git clone https://github.com/webship/codeigniter-steps.git
|
|
40
|
+
SITE_DIR="$PWD/codeigniter-app" codeigniter-steps/.github/scripts/build-ddev-site.sh
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The app answers at `https://codeignitersteps.ddev.site` and its mailbox at `https://codeignitersteps.ddev.site:8026`.
|
|
44
|
+
|
|
45
|
+
In the [Webship Workspace](https://github.com/webship/workspace), its CodeIgniter plugin builds the app instead, with the same app starter and auth library, in a sites folder of the workspace (`test/` here; `dev/`, `sandboxes/` and `demos/` work the same):
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
bash core/scripts/plugins.sh --require codeigniter --with-needs
|
|
49
|
+
bash core/scripts/plugins.sh --activate codeigniter --with-needs
|
|
50
|
+
bash core/scripts/plugins.sh --install codeigniter
|
|
51
|
+
bash test/cmd-codeigniter-project.sh mysite --install --add-users --shield --production
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
That app answers at `https://mysite.ddev.site` and its mailbox at `https://mysite.ddev.site:8026`. `--shield` adds the auth library with CSRF protection on, and `--production` runs the app as the script's app runs (the plain error pages and no debug toolbar). Its accounts are the plugin's: `admin`, `developer`, `user` and `banned`, the same names, groups and addresses as the script's, with the workspace's shared password `dD.123123ddd` (step 3 names them). It has none of the four pages the script adds, which the features of [`tests/features/`](tests/features/) open (the account page, the admin area, the site settings and an error nothing catches); this adds them, from the workspace folder:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/webship/codeigniter-steps.git
|
|
58
|
+
cp codeigniter-steps/site/TestFixtures.php test/mysite/app/Controllers/TestFixtures.php
|
|
59
|
+
cp codeigniter-steps/site/test_fixtures.php test/mysite/app/Views/test_fixtures.php
|
|
60
|
+
cat codeigniter-steps/site/routes.php >> test/mysite/app/Config/Routes.php
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
With them, the features of [`tests/features/`](tests/features/) pass there as they pass on the script's app.
|
|
64
|
+
|
|
65
|
+
**2. A test project.**
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
mkdir codeigniter-tests && cd codeigniter-tests
|
|
69
|
+
npm init -y
|
|
70
|
+
npm install --save-dev webship-js @webship-js/codeigniter-steps
|
|
71
|
+
npx init-webship-js
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`npx init-webship-js` writes `cucumber.js`, `playwright.config.ts`, the `tests/` folders with a first feature and the `npm test` scripts, and installs Chromium. npm usually runs it already when it installs webship-js; a second run changes nothing.
|
|
75
|
+
|
|
76
|
+
**3. `cucumber.js`.** Replace the file with the wiring of the pack: the step files of webship-js and of the pack, the tags that keep the lanes out of a normal run, the address of the app and of its mailbox, and the accounts (the JSON of [Test users](#test-users)).
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
module.exports = {
|
|
80
|
+
default: {
|
|
81
|
+
requireModule: ['tsx/cjs'],
|
|
82
|
+
require: [
|
|
83
|
+
'node_modules/webship-js/tests/step-definitions/**/*.js',
|
|
84
|
+
'node_modules/@webship-js/codeigniter-steps/tests/step-definitions/*.js',
|
|
85
|
+
'tests/step-definitions/**/*.js',
|
|
86
|
+
],
|
|
87
|
+
paths: ['tests/features/**/*.feature'],
|
|
88
|
+
// Work in progress, the assertions that must fail, and the lane that needs the app in the
|
|
89
|
+
// development environment (@development) stay out of a normal run.
|
|
90
|
+
tags: 'not @wip and not @must-fail and not @development',
|
|
91
|
+
format: ['@cucumber/pretty-formatter', 'json:tests/reports/cucumber_report.json'],
|
|
92
|
+
worldParameters: {
|
|
93
|
+
launchUrl: process.env.LAUNCH_URL || 'https://codeignitersteps.ddev.site',
|
|
94
|
+
mailUrl: (process.env.LAUNCH_URL || 'https://codeignitersteps.ddev.site') + ':8026',
|
|
95
|
+
// A page that names the signed-in account (the test app adds /account).
|
|
96
|
+
accountPath: '/account',
|
|
97
|
+
reuseSessions: true,
|
|
98
|
+
// The browser logs every error page as "Failed to load resource: the server responded with a
|
|
99
|
+
// status of 404" (403, 500): not a fault of the app. The scenarios that open an error page
|
|
100
|
+
// carry @js-off, so the warning mode below stays on for every other page.
|
|
101
|
+
javascript: { mode: 'warn', levels: ['error'] },
|
|
102
|
+
// The waits webship-js adds around each page, scenario and step (milliseconds).
|
|
103
|
+
minWaitTime: { page: 3000, before_scenario: 0, after_scenario: 0, before_step: 0, after_step: 0 },
|
|
104
|
+
users: {
|
|
105
|
+
admin: { email: 'admin@example.com', username: 'admin', password: 'Account-Pass-2026!' },
|
|
106
|
+
developer: { email: 'developer@example.com', username: 'developer', password: 'Account-Pass-2026!' },
|
|
107
|
+
user: { email: 'user@example.com', username: 'user', password: 'Account-Pass-2026!' },
|
|
108
|
+
banned: { email: 'banned@example.com', username: 'banned', password: 'Account-Pass-2026!' },
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
On an app from the Webship Workspace (step 1), the accounts are the plugin's: the same four, each with the password `dD.123123ddd` (`admin: { email: 'admin@example.com', username: 'admin', password: 'dD.123123ddd' }`, and so on), and `mailUrl` follows `LAUNCH_URL`. Its address goes in `LAUNCH_URL` (step 5).
|
|
116
|
+
|
|
117
|
+
**4. A first feature**, `tests/features/first-run.feature`:
|
|
118
|
+
|
|
119
|
+
```gherkin
|
|
120
|
+
Feature: First run
|
|
121
|
+
Scenario: An account logs in
|
|
122
|
+
Given I am a logged in user with the "user" user
|
|
123
|
+
Then I should be logged in
|
|
124
|
+
|
|
125
|
+
@js-off
|
|
126
|
+
Scenario: An address the app does not have answers with the 404 page
|
|
127
|
+
Given I am an anonymous user
|
|
128
|
+
When I go to "/no-such-page-of-the-app"
|
|
129
|
+
Then I should see the 404 error page
|
|
130
|
+
And the page should not show debug information
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**5. Run it.** Set `LAUNCH_URL` to the address of the app: `https://codeignitersteps.ddev.site` for the build script's app, `https://mysite.ddev.site` for the Workspace's.
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
LAUNCH_URL=https://codeignitersteps.ddev.site npm test
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
A green first run prints every step, then the summary (the starter feature of `npx init-webship-js` and the two scenarios above, passed) and the HTML report it wrote:
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
3 scenarios (3 passed)
|
|
143
|
+
8 steps (8 passed)
|
|
144
|
+
0m04.314s (executing steps: 0m04.283s)
|
|
145
|
+
[webship-js] HTML report → …/codeigniter-tests/tests/reports/cucumber_report.html
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
From there, copy the features of [`tests/features/`](tests/features/) (they also ship in the package, under `node_modules/@webship-js/codeigniter-steps/tests/features/`): together they use every step of the pack. They read no file of their own; they open the four pages of [A test app](#a-test-app).
|
|
149
|
+
|
|
150
|
+
### What the suite tests
|
|
151
|
+
|
|
152
|
+
The features of this repository run every step of the pack against the test app, twice in a row in CI on every change, then the assertions that must fail, then a lane with the app in development: logging in with the form, a wrong password, an address with no account, an address the browser takes and the app refuses, a banned account, an empty password, a page that needs a session (and back to it after the login), the session through a reload, the login page of a signed-in account, logging out, a remembered login that outlives the session and is ended by a logout, a login that was not remembered; the login link from the request to the mail, the link and the login, a link used twice, an address with no account; registration refused for an address or a user name that is taken, a confirmation that differs, a short or a common password, an empty user name; who may open the admin area (a group), the site settings (a permission) and the account page; a login form sent from another site, and a login and a registration form whose security token is out of date; the welcome page and the production environment, no debug toolbar on a live app, the 404 and 500 pages with no debug information; an accessibility audit of the auth pages, the account page and the welcome page; and in development (`@development`) the debug toolbar and its panels, the debug page, the 404 page that tells how it was routed and the 403 debug page of an out-of-date form.
|
|
153
|
+
|
|
154
|
+
Not tested: completing a registration (the suite never creates an account), the email activation and two-factor actions of the auth library (off on a new app, and an account left half way through either would break every later login), the limit on requests to the auth pages (the `auth-rates` filter the library recommends: the whole suite runs from one address), the access tokens and the API authenticators, and the pages an app adds of its own.
|
|
155
|
+
|
|
156
|
+
## Requirements
|
|
157
|
+
|
|
158
|
+
- Node.js 24 or later
|
|
159
|
+
- A webship-js 2.0 test project (webship-js 2.0.16 or later)
|
|
160
|
+
- An app made from the official app starter with the official auth library, and accounts on it for the suite
|
|
161
|
+
|
|
162
|
+
## Install
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
npm install --save-dev @webship-js/codeigniter-steps
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Quick start
|
|
169
|
+
|
|
170
|
+
1. Add the step files to the `require` list of your webship-js `cucumber.js`:
|
|
171
|
+
|
|
172
|
+
```javascript
|
|
173
|
+
require: [
|
|
174
|
+
'node_modules/webship-js/tests/step-definitions/**/*.js',
|
|
175
|
+
'node_modules/@webship-js/codeigniter-steps/tests/step-definitions/*.js',
|
|
176
|
+
'tests/step-definitions/**/*.js',
|
|
177
|
+
],
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
2. Point `launchUrl` at the app and name the accounts the suite logs in with
|
|
181
|
+
(see [Accounts](#accounts)):
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
worldParameters: {
|
|
185
|
+
launchUrl: process.env.LAUNCH_URL || 'https://your-app.ddev.site',
|
|
186
|
+
loginPath: '/login', // the login page
|
|
187
|
+
logoutPath: '/logout', // the address that ends a session, for a page with no "Log out" link
|
|
188
|
+
loginLinkPath: '/login/magic-link', // the page that mails a login link
|
|
189
|
+
accountPath: '/account', // a page that names the signed-in account
|
|
190
|
+
mailUrl: 'https://your-app.ddev.site:8026', // the mailbox of the app (Mailpit), for the mail steps
|
|
191
|
+
users: {
|
|
192
|
+
admin: { email: 'admin@example.com', username: 'admin', password: process.env.ADMIN_PASSWORD },
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
3. Copy a feature file from [`tests/features/`](tests/features/) into your
|
|
198
|
+
project and replace the addresses, names and texts with those of your app.
|
|
199
|
+
|
|
200
|
+
```gherkin
|
|
201
|
+
Feature: Groups and permissions
|
|
202
|
+
|
|
203
|
+
Scenario: The admin area is open to the admin group only
|
|
204
|
+
Then the access to "/admin" should be:
|
|
205
|
+
| account | access |
|
|
206
|
+
| admin | allowed |
|
|
207
|
+
| developer | denied |
|
|
208
|
+
| user | denied |
|
|
209
|
+
| visitor | login |
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## What is included
|
|
213
|
+
|
|
214
|
+
| File | Steps | Covers |
|
|
215
|
+
| --- | --- | --- |
|
|
216
|
+
| `codeigniter-session.steps.js` | 9 | Login by a handle of the users registry (a session taken over when the account already has one), login through the form (remembered or not), login with an address and a password, logout, who is signed in, the login form, a session that expires, the login link asked for by mail. |
|
|
217
|
+
| `codeigniter-mail.steps.js` | 4 | The mail the app sends (subject, text, no mail), a link of a mail opened as a person does. |
|
|
218
|
+
| `codeigniter-forms.steps.js` | 6 | A field filled with the address, user name or password of an account of the registry, a field that holds them, the error, success, warning and information messages of a page (or none), a field the browser refuses as empty, a form whose security token is out of date. |
|
|
219
|
+
| `codeigniter-access.steps.js` | 2 | A page an account may open or not, and a table of who may open a page. |
|
|
220
|
+
| `codeigniter-pages.steps.js` | 5 | The error page of a status, the debug information a live app must not show, a login form sent from another site, the welcome page, the environment the page says. |
|
|
221
|
+
| `codeigniter-toolbar.steps.js` | 3 | The debug toolbar (or none), a panel of it opened, what a panel shows. |
|
|
222
|
+
| `codeigniter-helpers.js` | | Shared plumbing for the files above and for your own steps: the wait budget, the answers on the way to a page, friendly errors, the users registry, the session cache and the login, fields, the messages of a page, the mailbox, the status of the page. It registers no step. |
|
|
223
|
+
|
|
224
|
+
Text, links, the plain filling of fields, buttons, cookies, the status code of
|
|
225
|
+
a page and the accessibility audit are webship-js's own steps (`I should see
|
|
226
|
+
"..."`, `I fill in "..." with "..."`, `I click the "..." button`, `a cookie with
|
|
227
|
+
the name "remember" should exist`, `the response status code should be 404`,
|
|
228
|
+
`the page should have no serious accessibility violations`): this pack adds
|
|
229
|
+
only what the app decides.
|
|
230
|
+
|
|
231
|
+
## How the steps find things and wait
|
|
232
|
+
|
|
233
|
+
- **By what a person reads.** A field is found by its label, else its name; a
|
|
234
|
+
message by its text and its kind; a tab of the debug toolbar by the word of
|
|
235
|
+
its label; a link of a mail by the text of its button. The stable hooks of
|
|
236
|
+
the pages are the fallback: the `name` of a field, `role="alert"` and the
|
|
237
|
+
contextual classes of a message box (`alert-danger` holds errors,
|
|
238
|
+
`alert-success` successes), the ids of the debug toolbar (`#debug-icon`,
|
|
239
|
+
`#debug-bar`, `data-tab`).
|
|
240
|
+
- **Messages line by line.** A refused form shows its errors in one box, one
|
|
241
|
+
per line; `I should see the error message "..."` reads each line.
|
|
242
|
+
- **Who may open a page.** The app guards a page with a filter of its auth
|
|
243
|
+
library (a session, a group, a permission). The access steps open the page
|
|
244
|
+
and read what the app did with it: the page itself (allowed), the login form
|
|
245
|
+
(a visitor), or a redirect away or HTTP 401 or 403 (denied). A new app turns
|
|
246
|
+
a refused account away to its home page with no message, so the steps read
|
|
247
|
+
the redirect, not a text.
|
|
248
|
+
- **Who is signed in.** The app sends a signed-in account away from its login
|
|
249
|
+
page and shows the form to a visitor: `I should be logged in` reads that.
|
|
250
|
+
`I should be logged in as "..."` reads a page that names the account
|
|
251
|
+
(`worldParameters.accountPath`).
|
|
252
|
+
- **No fixed sleeps.** The steps wait on the page's own signals: the
|
|
253
|
+
navigation a form or a link starts and the page it ends on, the requests of
|
|
254
|
+
the page, the message that appears.
|
|
255
|
+
- **Failures say what was found.** `Expected access to /admin, but it turned
|
|
256
|
+
the browser away to / (a redirect (HTTP 302) to /).` with a hint on where to
|
|
257
|
+
look.
|
|
258
|
+
|
|
259
|
+
## Accounts
|
|
260
|
+
|
|
261
|
+
The suite never creates or deletes a user. Accounts are configuration: list
|
|
262
|
+
the ones the app has in `worldParameters.users`, by a handle the scenarios
|
|
263
|
+
use, each with its `email`, `username` and `password`.
|
|
264
|
+
|
|
265
|
+
```javascript
|
|
266
|
+
users: {
|
|
267
|
+
admin: { email: 'admin@example.com', username: 'admin', password: process.env.ADMIN_PASSWORD },
|
|
268
|
+
user: { email: 'user@example.com', username: 'user', password: process.env.USER_PASSWORD },
|
|
269
|
+
},
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
An account that logged in once keeps its session for the rest of the run: a
|
|
273
|
+
later scenario that logs in as the same handle takes the session over instead
|
|
274
|
+
of filling in the login form again. That is quicker. If the app limits the
|
|
275
|
+
requests to its auth pages (the auth library's `auth-rates` filter), a login
|
|
276
|
+
that meets the limit waits the time the app gives, once.
|
|
277
|
+
`reuseSessions: false` in `worldParameters` turns the reuse off.
|
|
278
|
+
|
|
279
|
+
## Test users
|
|
280
|
+
|
|
281
|
+
The accounts this repository's suite logs in as, exactly as `cucumber.js`
|
|
282
|
+
lists them in `worldParameters.users` (the default values; the `*_EMAIL`,
|
|
283
|
+
`*_USERNAME` and `*_PASSWORD` variables replace them).
|
|
284
|
+
[`.github/scripts/build-ddev-site.sh`](.github/scripts/build-ddev-site.sh)
|
|
285
|
+
creates them on the local test app, and CI does the same on the runner. They are
|
|
286
|
+
placeholder credentials of that throwaway app, not of any real one.
|
|
287
|
+
|
|
288
|
+
```json
|
|
289
|
+
{
|
|
290
|
+
"admin": { "email": "admin@example.com", "username": "admin", "password": "Account-Pass-2026!" },
|
|
291
|
+
"developer": { "email": "developer@example.com", "username": "developer", "password": "Account-Pass-2026!" },
|
|
292
|
+
"user": { "email": "user@example.com", "username": "user", "password": "Account-Pass-2026!" },
|
|
293
|
+
"banned": { "email": "banned@example.com", "username": "banned", "password": "Account-Pass-2026!" }
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
`admin` is in the "admin" group, `developer` in the "developer" group (which
|
|
298
|
+
has the "admin.settings" permission and the "admin" group has not), `user` in
|
|
299
|
+
the "user" group a new account gets, and `banned` in the "user" group, banned:
|
|
300
|
+
the app refuses its login.
|
|
301
|
+
|
|
302
|
+
## A test app
|
|
303
|
+
|
|
304
|
+
[`.github/scripts/build-ddev-site.sh`](.github/scripts/build-ddev-site.sh)
|
|
305
|
+
builds the app the suite of this repository runs against, the documented way:
|
|
306
|
+
a DDEV project of type `php` with the `public` docroot (DDEV has no project type
|
|
307
|
+
of its own for the framework) and Node.js 24, the app starter made with
|
|
308
|
+
Composer in the web container, its `.env` (the address, the database DDEV gives
|
|
309
|
+
the project, the sender of its mail), the auth library set up by its own
|
|
310
|
+
`spark shield:setup`. The app sends its mail through the sendmail of the web
|
|
311
|
+
container, which DDEV hands to its mail catcher. Then:
|
|
312
|
+
|
|
313
|
+
- CSRF protection for every form: the `csrf` filter that the app starter ships
|
|
314
|
+
commented out in `app/Config/Filters.php`, turned on;
|
|
315
|
+
- four pages ([`site/`](site/)), guarded the way the auth library's guide
|
|
316
|
+
guards an app's pages: `/account` (any signed-in account, filter `session`),
|
|
317
|
+
`/admin` (filter `group:admin,superadmin`), `/settings` (filter
|
|
318
|
+
`permission:admin.settings`), and `/test-fixtures/server-error`, an error
|
|
319
|
+
nothing catches (a new app has no page that needs a session, no page for a
|
|
320
|
+
group or a permission, and no page that fails, and the suite must see each);
|
|
321
|
+
- the accounts of [Test users](#test-users), written through the app's own user
|
|
322
|
+
model by a seeder ([`site/TestAccounts.php`](site/TestAccounts.php));
|
|
323
|
+
- `CI_ENVIRONMENT = production` (`spark env production`), as a live app runs:
|
|
324
|
+
an error renders the plain error page, never the debug page, and the pages
|
|
325
|
+
carry no debug toolbar.
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
SITE_DIR="$PWD/../codeigniter-app" .github/scripts/build-ddev-site.sh
|
|
329
|
+
npm test
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Nothing is installed that the app starter and the auth library do not bring:
|
|
333
|
+
no paid package, no trial, no sign-in to any service.
|
|
334
|
+
|
|
335
|
+
## Steps
|
|
336
|
+
|
|
337
|
+
One example of each step; the JSDoc block above each definition holds five.
|
|
338
|
+
|
|
339
|
+
### `codeigniter-session.steps.js` (9)
|
|
340
|
+
|
|
341
|
+
- `Given I am a logged in user with the "admin" user`
|
|
342
|
+
- `When I log in as "user" with the login form and ask to be remembered`
|
|
343
|
+
- `When I log in with the email "user@example.com" and the password "wrong-password"`
|
|
344
|
+
- `When I log out`
|
|
345
|
+
- `Then I should be logged in`
|
|
346
|
+
- `Then I should be logged in as "user"`
|
|
347
|
+
- `Then I should see the login form`
|
|
348
|
+
- `When my session expires`
|
|
349
|
+
- `When I ask for a login link for "user"`
|
|
350
|
+
|
|
351
|
+
### `codeigniter-mail.steps.js` (4)
|
|
352
|
+
|
|
353
|
+
- `Then an email with the subject "Your Login Link" should be sent to "user"`
|
|
354
|
+
- `Then no email should be sent to "nobody@example.com"`
|
|
355
|
+
- `Then the email with the subject "Your Login Link" to "user" should contain "Username: user"`
|
|
356
|
+
- `When I open the "Login" link of the email to "user"`
|
|
357
|
+
|
|
358
|
+
### `codeigniter-forms.steps.js` (6)
|
|
359
|
+
|
|
360
|
+
- `When I fill in "Password" with the password of "user"`
|
|
361
|
+
- `Then the "Email Address" field should hold the email of "user"`
|
|
362
|
+
- `Then I should see the error message "Unable to log you in. Please check your password."`
|
|
363
|
+
- `Then I should not see any error message`
|
|
364
|
+
- `Then the "Username" field should block submission as required`
|
|
365
|
+
- `When the security token of the form expires`
|
|
366
|
+
|
|
367
|
+
### `codeigniter-access.steps.js` (2)
|
|
368
|
+
|
|
369
|
+
- `Then I should have access to "/admin"`
|
|
370
|
+
- `Then the access to "/admin" should be:` (a table of `account` and `access`)
|
|
371
|
+
|
|
372
|
+
### `codeigniter-pages.steps.js` (5)
|
|
373
|
+
|
|
374
|
+
- `Then I should see the 404 error page`
|
|
375
|
+
- `Then the page should not show debug information`
|
|
376
|
+
- `When a page of another site sends the login form of "user" to "/login"`
|
|
377
|
+
- `Then I should see the welcome page`
|
|
378
|
+
- `Then the page should say it runs in the "production" environment`
|
|
379
|
+
|
|
380
|
+
### `codeigniter-toolbar.steps.js` (3)
|
|
381
|
+
|
|
382
|
+
- `Then I should see the debug toolbar`
|
|
383
|
+
- `When I open the "Routes" panel of the debug toolbar`
|
|
384
|
+
- `Then the "Routes" panel of the debug toolbar should show "TestFixtures::account"`
|
|
385
|
+
|
|
386
|
+
## Testing this package
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
npm install
|
|
390
|
+
SITE_DIR="$PWD/../codeigniter-app" .github/scripts/build-ddev-site.sh
|
|
391
|
+
npm run test:examples # the examples and the features against the step patterns
|
|
392
|
+
npm run test:paths # a feature or a scenario named on the command line runs alone
|
|
393
|
+
npx cucumber-js --dry-run # no undefined and no ambiguous step
|
|
394
|
+
npm test # the suite, against the app
|
|
395
|
+
npm run test:must-fail # assertions that must fail, each with its message
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
The development lane needs the app in the development environment, and puts
|
|
399
|
+
it back:
|
|
400
|
+
|
|
401
|
+
```bash
|
|
402
|
+
(cd ../codeigniter-app && ddev exec php spark env development)
|
|
403
|
+
npm run test:development # the debug toolbar, the debug page
|
|
404
|
+
MUST_FAIL_TAGS="@must-fail and @development" npm run test:must-fail
|
|
405
|
+
(cd ../codeigniter-app && ddev exec php spark env production)
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
`LAUNCH_URL` points the suite at another app; `npx cucumber-js
|
|
409
|
+
tests/features/session.feature` runs one feature and `npx cucumber-js
|
|
410
|
+
tests/features/session.feature:<line>` one scenario (the line of its
|
|
411
|
+
`Scenario:`; the paths of `cucumber.js` are left out when the command line
|
|
412
|
+
names any); `FEATURES` runs a subset too
|
|
413
|
+
(`FEATURES=tests/features/session.feature npm test`); `CUCUMBER_TAGS=@critical`
|
|
414
|
+
runs the smoke lane; `HEADLESS=false` shows the browser.
|
|
415
|
+
|
|
416
|
+
`tests/must-fail/` holds scenarios that assert something that is not true on
|
|
417
|
+
the test app. `npm run test:must-fail` runs them and checks that each one
|
|
418
|
+
fails at its last step, with the message it announces and a hint: a step that
|
|
419
|
+
cannot fail proves nothing.
|
|
420
|
+
|
|
421
|
+
The suite leaves the app as it found it: it changes no account, completes no
|
|
422
|
+
registration, and every login link a scenario asks for is the scenario's own.
|
|
423
|
+
A run stopped half way changes nothing either; the build script gives the
|
|
424
|
+
accounts back their name, address, password, groups and state without
|
|
425
|
+
building anything:
|
|
426
|
+
|
|
427
|
+
```bash
|
|
428
|
+
ACCOUNTS_ONLY=1 SITE_DIR="$PWD/../codeigniter-app" .github/scripts/build-ddev-site.sh
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## How the steps were written
|
|
432
|
+
|
|
433
|
+
Every page a step touches was opened in a real browser first, and the step was
|
|
434
|
+
written from what is there: the roles and names of the accessibility tree, the
|
|
435
|
+
stable attributes, what the page does while it loads or saves, the exact
|
|
436
|
+
messages. The steps are proven on the app starter 4.7 with the auth library
|
|
437
|
+
1.4, on PHP 8.2 and 8.4, in English, with Chromium.
|
|
438
|
+
|
|
439
|
+
Not covered: completing a registration, the email activation and two-factor
|
|
440
|
+
actions, the limit on requests to the auth pages, the access tokens and API
|
|
441
|
+
authenticators, and an app's own pages.
|
|
442
|
+
|
|
443
|
+
## License
|
|
444
|
+
|
|
445
|
+
MIT
|
|
446
|
+
|
|
447
|
+
## Logo
|
|
448
|
+
|
|
449
|
+
The CodeIgniter logo in this README comes from Simple Icons 16.37.0 (CC0-1.0), filled with the colour the set lists for the brand. The CodeIgniter name and logo are trademarks of their owner; this pack is not affiliated with or endorsed by them.
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webship-js/codeigniter-steps",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Cucumber step definitions for apps made from the official app starter with the official auth library, a plugin for webship-js (Playwright and Cucumber): the session and the login link through the mail, remembering a login, registration refusals, groups and permissions, error and success messages, the welcome page, the error pages, the CSRF refusal, and the debug toolbar and debug page checks.",
|
|
5
|
+
"main": "tests/step-definitions/codeigniter-session.steps.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"tests/step-definitions/",
|
|
8
|
+
"tests/features/",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "cucumber-js --config cucumber.js",
|
|
14
|
+
"test:dry": "cucumber-js --config cucumber.js --dry-run",
|
|
15
|
+
"test:examples": "node tests/check-examples.js",
|
|
16
|
+
"test:paths": "node tests/check-paths.js",
|
|
17
|
+
"test:must-fail": "node tests/check-must-fail.js",
|
|
18
|
+
"test:development": "CUCUMBER_TAGS=@development cucumber-js --config cucumber.js",
|
|
19
|
+
"test:chromium": "BROWSER=chromium cucumber-js --config cucumber.js",
|
|
20
|
+
"test:firefox": "BROWSER=firefox cucumber-js --config cucumber.js",
|
|
21
|
+
"test:webkit": "BROWSER=webkit cucumber-js --config cucumber.js",
|
|
22
|
+
"test:headed": "HEADLESS=false cucumber-js --config cucumber.js",
|
|
23
|
+
"generate-reports": "generate-reports"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"webship-js",
|
|
27
|
+
"codeigniter",
|
|
28
|
+
"codeigniter4",
|
|
29
|
+
"shield",
|
|
30
|
+
"cucumber",
|
|
31
|
+
"cucumber-js",
|
|
32
|
+
"playwright",
|
|
33
|
+
"bdd",
|
|
34
|
+
"testing",
|
|
35
|
+
"e2e",
|
|
36
|
+
"gherkin"
|
|
37
|
+
],
|
|
38
|
+
"author": "Webship.co",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/webship/codeigniter-steps.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/webship/codeigniter-steps/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/webship/codeigniter-steps#readme",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">= 24.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"webship-js": "^2.0.16"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"tsx": "^4.23.0",
|
|
59
|
+
"webship-js": "^2.0.16"
|
|
60
|
+
},
|
|
61
|
+
"overrides": {
|
|
62
|
+
"@cucumber/cucumber": "^12"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Features
|
|
2
|
+
|
|
3
|
+
Reference features for the test app that `.github/scripts/build-ddev-site.sh`
|
|
4
|
+
builds: a new app made from the official app starter with the official auth
|
|
5
|
+
library, the pages the script adds (`/account`, `/admin`, `/settings` and
|
|
6
|
+
`/test-fixtures/server-error`), and the four accounts of `cucumber.js`
|
|
7
|
+
(`admin`, `developer`, `user`, `banned`). Copy a feature into your project and
|
|
8
|
+
replace the addresses, names and texts with those of your app.
|
|
9
|
+
|
|
10
|
+
| Feature | Covers |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| `session` | Logging in with the form, a wrong password, an address with no account, an address the app refuses, a banned account, an empty password, a page that needs a session (and back to it after the login), the session through a reload, the login page of a signed-in account, logging out, a remembered login that outlives the session, one that does not. |
|
|
13
|
+
| `login-link` | The login link by mail: the request, the mail, the link, the login; a link used twice; an address with no account; the way back to the login form. |
|
|
14
|
+
| `registration` | Registration refused: an address that is taken, a user name that is taken, a confirmation that differs, a password that is too short, a common password, an empty user name. No sign-up is completed. |
|
|
15
|
+
| `access` | Groups and permissions: who may open the admin area, the site settings and the account page; an account turned away; a visitor sent to the login form. |
|
|
16
|
+
| `forgery` | A login form sent from a page of another site; a login and a registration form whose security token is out of date. |
|
|
17
|
+
| `framework-pages` | The welcome page in production, no debug toolbar on a live app, the 404 and 500 pages with no debug information. |
|
|
18
|
+
| `accessibility` | An accessibility audit of the login, registration and login link pages, the account page and the welcome page. |
|
|
19
|
+
| `development` | `@development`, a lane of its own with the app in the development environment: the debug toolbar and its panels, the debug page, the 404 page that tells how it was routed, the 403 debug page of an out-of-date form. |
|
|
20
|
+
|
|
21
|
+
Scenarios that change something change it back: a login is ended by the
|
|
22
|
+
scenario that tests the logout, a login link a scenario asks for is the
|
|
23
|
+
scenario's own. No scenario creates or deletes a user or completes a
|
|
24
|
+
registration.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
@access
|
|
2
|
+
Feature: Groups and permissions
|
|
3
|
+
As the owner of the app
|
|
4
|
+
I want each page guarded for the groups and permissions it is meant for
|
|
5
|
+
So that an account opens only what its group may open
|
|
6
|
+
|
|
7
|
+
# The test app guards three pages with the filters of the auth library: /account (any signed-in
|
|
8
|
+
# account), /admin (the "admin" and "superadmin" groups) and /settings (the "admin.settings"
|
|
9
|
+
# permission, which the "developer" group has and the "admin" group has not).
|
|
10
|
+
|
|
11
|
+
@critical
|
|
12
|
+
Scenario: The admin area is open to the admin group only
|
|
13
|
+
Then the access to "/admin" should be:
|
|
14
|
+
| account | access |
|
|
15
|
+
| admin | allowed |
|
|
16
|
+
| developer | denied |
|
|
17
|
+
| user | denied |
|
|
18
|
+
| visitor | login |
|
|
19
|
+
|
|
20
|
+
@critical
|
|
21
|
+
Scenario: The site settings are open to the accounts with the permission, whatever their group
|
|
22
|
+
Then the access to "/settings" should be:
|
|
23
|
+
| account | access |
|
|
24
|
+
| developer | allowed |
|
|
25
|
+
| admin | denied |
|
|
26
|
+
| user | denied |
|
|
27
|
+
| visitor | login |
|
|
28
|
+
|
|
29
|
+
Scenario: The account page is open to every signed-in account
|
|
30
|
+
Then the access to "/account" should be:
|
|
31
|
+
| account | access |
|
|
32
|
+
| admin | allowed |
|
|
33
|
+
| developer | allowed |
|
|
34
|
+
| user | allowed |
|
|
35
|
+
| visitor | login |
|
|
36
|
+
|
|
37
|
+
Scenario: An account of the user group is turned away from the admin area
|
|
38
|
+
Given I am a logged in user with the "user" user
|
|
39
|
+
Then I should not have access to "/admin"
|
|
40
|
+
And I should be on the homepage
|
|
41
|
+
And I should have access to "/account"
|
|
42
|
+
|
|
43
|
+
Scenario: An account of the admin group opens the admin area
|
|
44
|
+
Given I am a logged in user with the "admin" user
|
|
45
|
+
Then I should have access to "/admin"
|
|
46
|
+
And I should see "Admin area"
|
|
47
|
+
And I should not have access to "/settings"
|
|
48
|
+
|
|
49
|
+
Scenario: A visitor is sent to the login form from a guarded page
|
|
50
|
+
Given I am an anonymous user
|
|
51
|
+
Then I should not have access to "/settings"
|
|
52
|
+
And I should see the login form
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
@accessibility
|
|
2
|
+
Feature: Accessibility of the auth pages
|
|
3
|
+
As a person who uses a keyboard, a screen reader or a high contrast
|
|
4
|
+
I want the pages that let me into my account to be accessible
|
|
5
|
+
So that nobody is locked out of their account by the way a page is built
|
|
6
|
+
|
|
7
|
+
# The welcome page of a new app has text with too little contrast (axe: color-contrast, serious):
|
|
8
|
+
# its scenario holds it to no critical violation.
|
|
9
|
+
|
|
10
|
+
Scenario Outline: The <page> has no serious accessibility violations
|
|
11
|
+
Given I am an anonymous user
|
|
12
|
+
When I go to "<path>"
|
|
13
|
+
Then the page should have no serious accessibility violations
|
|
14
|
+
And every form field should have an accessible label
|
|
15
|
+
And every button should have an accessible name
|
|
16
|
+
|
|
17
|
+
Examples:
|
|
18
|
+
| page | path |
|
|
19
|
+
| login page | /login |
|
|
20
|
+
| registration page | /register |
|
|
21
|
+
| page that sends a login link | /login/magic-link |
|
|
22
|
+
|
|
23
|
+
Scenario: The account page has no serious accessibility violations
|
|
24
|
+
Given I am a logged in user with the "user" user
|
|
25
|
+
When I go to "/account"
|
|
26
|
+
Then the page should have no serious accessibility violations
|
|
27
|
+
And every link should have an accessible name
|
|
28
|
+
|
|
29
|
+
Scenario: The welcome page has no critical accessibility violations
|
|
30
|
+
Given I am an anonymous user
|
|
31
|
+
When I go to the homepage
|
|
32
|
+
Then the page should have no critical accessibility violations
|