Workshop Building Automated Tests with WordPress Playground
This repository contains the code and instructions for the workshop "Building Automated Tests with WordPress Playground" for WordCamp EU 2025.
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/bgrgicak/playground-testing-demo/archive/refs/heads/main.zipReadme
Building Automated Tests with WordPress Playground
This repository contains the code and instructions for the workshop "Building Automated Tests with WordPress Playground" for WordCamp EU 2025.
Workshop description:
The goal of this workshop is to show how easy it is to start testing WordPress projects and enable participants to implement tests in their own projects. In the workshop we will write integration and end-to-end tests for a typical WordPress plugin. We will run tests using WordPress Playground, so they can run inside the WordPress context, each test can run on a differently configured site, and we can test the project using both PHP and HTTP requests. To start we will fork a plugin from GitHub and learn how to run it locally using the Playground CLI. After that, we will implement integration and end-to-end tests for our plugin using Playground. Once we have all tests working we will add a GitHub action to run these tests on every commit in GitHub.
If you want to see the final result, you can check the main branch, or you can check the start branch, which is the starting point for the workshop.
Requirements:
You will need Node.js 20.18.3 with npm 11.2.0 or higher on your machine.
It's possible to install it using nvm (Node Version Manager) or install Node.js from Node.js website.
Optionally Git, but if you don't want to use Git, you can download the project as a zip file, or from a USB drive that will be provided during the workshop.
Development setup:
- Clone the repository:
git clone -b start https://github.com/bgrgicak/playground-testing-demo
- Setup the Node.js environment:
nvm install
nvm use
- Install the dependencies:
npm ci
3.1 Install Playwright:
npx playwright install --with-deps
- Run the WordPress site
npx @wp-playground/cli server --mount=.:/wordpress/wp-content/plugins/playground-testing-demo
- Run the tests:
npm run test
5.1 Run end-to-end tests:
npm run test:e2e
5.2 Run integration tests:
npm run test:integration
What are we building?
Local development server
- [ ] Run the local development server using Playground CLI
- [ ] Mount the plugin code in the WordPress site
- [ ] Configure the WordPress site using a Blueprint
End-to-end tests
- [ ] Admin page
- [ ] Check if
/wp-admin/admin.php?page=workshop-testspage loads - [ ] Check if the message is displayed after submitting the form
- [ ] Check if the message is persisted after a page reload
- [ ] Check if
Integration tests
- [ ] Check if the plugin is active
- [ ] Rest API endpoint
POST/wp-json/PTD/v1/message- [ ] Confirm the API endpoint fails when not authenticated
- [ ] Confirm the API endpoint returns expected response when authenticated
- [ ] Confirm the API endpoint saves the message to the database
GitHub Actions
- [ ] Run tests on every commit