Overview

WordHat provides WordPress-specific functionality for common testing scenarios that are specific to WordPress sites. We do this by providing a range of Behat contexts that provide useful step definitions.

For convenience, our behat.yml.dist configuration template loads all of our contexts by default, though Behat does support more complex configuration for advanced use cases.

To find out which step definitions are available for your tests, run vendor/bin/behat -dl in your terminal.

Drivers

The Given and When steps in a Behat Scenario configure a WordPress into a known state for reliable testing. WordHat abstracts this communication between WordPress and itself into a drivers system. Two drivers are currently provided: WP-CLI (the default), and WP-PHP.

Drivers

WordHat only uses a driver to configure a WordPress into a known state.

Your actual tests are run in a web browser, via Mink.

To configure WordHat to use a specific driver, set default_driver in your behat.yml.

WP-CLI

The WP-CLI driver uses WP-CLI to connect to WordPress. This is the default and recommended driver, and allows you to run your tests and your WordPress site on different servers.

WP-PHP

The WP-PHP driver loads WordPress by bootstrapping it directly. This approach was taken from WordPress’ PHPUnit integration test framework. You have to run your tests directly on your WordPress server.

Contexts

Under development

Step definitions are not fully implemented – yet. More are added with each release of WordHat.

Content

The ContentContext context provides a range of step definitions for managing post types, taxonomy terms, and comments.

Debug

The DebugContext context provides step definitions to help debug Scenarios during development.

Site

The SiteContext context provides step definitions for activating/deactivating plugins, switching themes, and clearing the object cache.

TinyMCE

The EditPost context provides step definitions to manage editing and creating content within wp-admin.

Toolbar

The ToolbarContext context provides step definitions to interact with the WordPress Toolbar.

User

The UserContext context provides a range of step definitions for managing users.

Widget

The WidgetContext context provides step definitions to add/remove widgets from sidebars.

wp-admin

The Dashboard context provides a range of step definitions for generally interacting with, and navigating around, the WordPress administration screens (i.e. wp-admin).