WordPress / WordPress/accessibility-lab
[Feature]: Set up automated testing infrastructure (PHPUnit & Jest)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11
- Forks
- 3
- Avg merge
- 16h 15m
- Merged PRs (30d)
- 3
Description
Which area does this relate to?
Other / not sure
Is your feature request related to a problem?
Currently, WordPress/accessibility-lab has established excellent static analysis and linting tooling (composer lint, composer phpstan, npm run lint:js, npm run lint:css). However, the repository currently lacks an automated unit and integration testing harness for both backend PHP and frontend JavaScript:
- Backend Gap: There is no
composer testor PHPUnit test suite. As new block validation checks, REST controllers (/wp-validation/v1/checks), and module registry features are added, there is no automated regression safety net to verify check key derivation, namespace normalization, and level override persistence. - Frontend Gap: In
src/, editor block validation filters (e.g.heading.ts,image.ts) and DataViews utility functions (e.g.transform.ts) have no test runner configured inpackage.json.
Describe the solution you'd like
To keep tooling, developer experience, and test infrastructure consistent across official plugins under the WordPress/ GitHub organization, we propose establishing the automated testing architecture by directly mirroring the proven pattern used in WordPress/ai:
1. PHP Testing Infrastructure (Mirroring WordPress/ai):
In WordPress/ai, PHP testing is configured cleanly using wp-phpunit and yoast/phpunit-polyfills alongside wp-env. We propose adopting the exact same setup:
-
Composer Dependencies (
composer.json):
Add torequire-dev:"phpunit/phpunit": "^9.6""wp-phpunit/wp-phpunit": "^7.1""yoast/phpunit-polyfills": "^4.0""autoload-dev"with PSR-4 mapping:"AccessibilityLab\\Tests\\": "tests/"
-
Configuration & Bootstrap:
- Add
phpunit.xml.distconfigured for strict coverage and notices. - Add
tests/bootstrap.phpthat conditionally loads Composer dependencies, detects the WordPress test suite (viaWP_TESTS_DIR,WP_DEVELOP_DIR, orwp-env), and bootsaccessibility-lab.phpviatests_add_filter('muplugins_loaded', ...).
- Add
-
Composer Scripts:
- Add
"test": "phpunit --colors=always"tocomposer.json.
- Add
-
Initial Unit Test Suite:
Create dedicated unit tests for decoupled, critical business logic:tests/Unit/Modules/Experiments/BlockValidation/CheckKeyTest.php: Exhaustive test ofCheck_Key::from_check()andfrom_context()across all scopes (block,meta,editor), verifying delimiter safety (__) and segment derivation.tests/Unit/Modules/Experiments/BlockValidation/CheckRegistryTest.php: Testingregister_namespace(),resolve_plugin_title(), check normalization (titlefallback toname, default level assignment,configurableflag preservation), andnamespaces()retrieval.tests/Unit/CreditsTest.php: Testing attribution value object initialization and getters.
-
GitHub Actions CI:
Update.github/workflows/ci.ymlunder thephpjob matrix to runcomposer testacross PHP 8.1, 8.2, 8.3, and 8.4.
2. JavaScript / Editor Validation Testing (via @wordpress/scripts):
The repository already depends on @wordpress/scripts: 32.6.0, which comes with Jest, Babel, TypeScript, and JSDOM pre-configured.
-
NPM Script (
package.json):
Add"test:unit": "wp-scripts test-unit-js"(requiring 0 new npm dependencies). -
Initial Unit Test Suite:
src/validation-settings/utils/__tests__/transform.test.ts: Unit tests for pure DataViews transformation functions:checksToRows(): Verifying payload flattening, level override resolution, and filtering ofconfigurable: falsechecks.rowsToOverrides(): Verifying mapping of user-modified rows back to clean server override maps.
src/editor/core-block-rules/__tests__/heading.test.ts: Verifying heading level hierarchy validation (e.g. flagging skipped heading levels H1 -> H3).
-
GitHub Actions CI:
Add anpm run test:unitstep under thejsjob in.github/workflows/ci.yml.
Describe alternatives you've considered
Relying solely on PHPStan and manual testing in wp-env, which cannot guarantee runtime regression safety as more block validation rules, third-party namespaces, and UI settings are added.
Additional context
In WordPress/ai, this dual architecture enables fast, isolated unit and integration testing locally and in CI without introducing complex custom tooling. Adopting this established WordPress Core tooling pattern here will make testing consistent, reliable, and familiar for all contributors across the WordPress ecosystem.
I would be happy to submit a clean, modular pull request implementing this setup along with the initial unit test suites if the maintainers agree with this approach!
Checklist
- I have searched existing issues to make sure this isn't a duplicate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review composer.json, package.json, and .github/workflows/ci.yml, then compare the corresponding setup in WordPress/ai. Implement the requested PHP and JavaScript test configuration and initial tests under tests/ and src/**/tests/. Done means composer test and npm run test:unit run successfully, including in the CI jobs and PHP version matrix described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, php, typescript
- Domain
- backend, build-system, ci-cd, frontend, testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100