Skip to content

This repository contains the code and instructions for the workshop "Building Automated Tests with WordPress Playground" for WordCamp EU 2025.

Notifications You must be signed in to change notification settings

silaskoehler/playground-testing-demo

 
 

Repository files navigation

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:

  1. Clone the repository:
git clone -b start https://github.com/bgrgicak/playground-testing-demo
  1. Setup the Node.js environment:
nvm install
nvm use
  1. Install the dependencies:
npm ci

3.1 Install Playwright:

npx playwright install --with-deps
  1. Run the WordPress site
npx @wp-playground/cli server --mount=.:/wordpress/wp-content/plugins/
  1. 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?

  • Run the local development server using Playground CLI
    • Mount the plugin code in the WordPress site
    • Configure the WordPress site using a Blueprint
  • Admin page
    • Check if /wp-admin/admin.php?page=workshop-tests page loads
    • Check if the message is displayed after submitting the form
    • Check if the message is persisted after a page reload
  • 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

About

This repository contains the code and instructions for the workshop "Building Automated Tests with WordPress Playground" for WordCamp EU 2025.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 75.1%
  • TypeScript 24.9%