Files
wp-plugin-starter-template-…/.wiki/Playground-Testing.md

3.7 KiB

WordPress Playground Testing

This document explains how to use WordPress Playground for testing our plugin.

What is WordPress Playground?

WordPress Playground is a project that runs WordPress entirely in the browser using WebAssembly. This means:

  • No server required - WordPress runs in the browser
  • Fast startup times
  • Isolated testing environment
  • Works well with CI/CD pipelines

Using WordPress Playground Online

The easiest way to test our plugin with WordPress Playground is to use the online version:

  1. Single site testing: Open in WordPress Playground

  2. Multisite testing: Open in WordPress Playground

These links will automatically set up WordPress with multisite enabled and the Hello Dolly plugin network-activated.

Plugin Activation in Multisite

In a WordPress multisite environment, there are two ways to activate plugins:

  1. Network Activation: Activates a plugin for all sites in the network

    • In the WordPress admin, go to Network Admin > Plugins
    • Click "Network Activate" under the plugin
    • Or use WP-CLI: wp plugin activate plugin-name --network
  2. Per-Site Activation: Activates a plugin for a specific site

    • In the WordPress admin, go to the specific site's admin area
    • Go to Plugins and activate the plugin for that site only
    • Or use WP-CLI: wp plugin activate plugin-name --url=site-url

Our multisite blueprint uses network activation for the Hello Dolly plugin as an example.

Running Tests with WordPress Playground

We have two blueprints for testing:

  1. playground/blueprint.json - For single site testing
  2. playground/multisite-blueprint.json - For multisite testing

To run tests with WordPress Playground:

  1. Open the appropriate WordPress Playground link:

  2. Test the plugin manually in the browser

Local Testing with HTML Files

We've also included HTML files that embed WordPress Playground:

  1. Open playground/index.html in your browser for single site testing
  2. Open playground/multisite.html in your browser for multisite testing

You can serve these files locally with a simple HTTP server:

# Using Python
python -m http.server 8888 --directory playground

# Then open http://localhost:8888/index.html in your browser

Customizing Blueprints

You can customize the blueprints to suit your testing needs. See the WordPress Playground Blueprints documentation for more information.

CI/CD Integration

We have a GitHub Actions workflow that uses WordPress Playground for testing. See .github/workflows/playground-tests.yml for more information.

Performance Testing

We also use the WP Performance Tests GitHub Action for performance testing. This action tests our plugin against various WordPress versions and PHP versions to ensure it performs well in different environments.