This document outlines the steps required to run unit tests for the DocumentCloud WordPress plugin. The testing suite includes both PHP unit tests for server-side functionality and JavaScript unit tests for the Gutenberg block component.
To run the unit tests for this plugin, ensure you have the following software installed:
-
Git
-
Composer
-
Node.js
-
npm
-
PHP
-
PHPUnit (matching your PHP version)
-
MySQL or MariaDB
-
Subversion (
svn)
The PHP unit tests use the WordPress PHPUnit Test Suite.
From the root directory of the plugin, run:
composer installThis will install all PHP dependencies, including PHPUnit and test configuration.
The WordPress test suite is already included in the repository via the script at bin/install-wp-tests.sh.
chmod +x bin/install-wp-tests.sh./bin/install-wp-tests.sh <db-name> <db-user> <db-pass> [db-host] [wp-version]-
Replace
<db-name>,<db-user>,<db-pass>with your local database credentials. -
⚠️ Note: Ensure thatsvnis installed on your system, as the script uses Subversion to fetch the WordPress core files.
After successful setup:
phpunitTo run with code coverage output:
phpunit --coverage-text📌 Ensure you are running this from the plugin root and have phpunit.xml.dist properly configured.
If you are using Docker for your development environment, follow these steps to run PHPUnit tests inside the Docker container:
docker compose up --builddocker exec -it Testing bash./bin/install-wp-tests.sh test root password db latest./vendor/bin/phpunitThe Gutenberg block of this plugin is tested using Jest and React Testing Library.
cd blocks/npm installnpm run testor
npx jest-
__tests__/– Contains all Jest test files. -
__mocks__/– Includes mocks for WordPress-specific packages. -
__snapshots__/– Stores Jest snapshot tests, for thesavecomponent of the block.
save function renders content, delete existing snapshots to regenerate them:
rm -rf __snapshots__/