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.
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.
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
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.
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.
Step definitions are not fully implemented – yet. More are added with each release of WordHat.
ContentContext context provides a range of step definitions for managing post types, taxonomy terms, and comments.
DebugContext context provides step definitions to help debug Scenarios during development.
SiteContext context provides step definitions for activating/deactivating plugins, switching themes, and clearing the object cache.
EditPost context provides step definitions to manage editing and creating content within wp-admin.
ToolbarContext context provides step definitions to interact with the WordPress Toolbar.
UserContext context provides a range of step definitions for managing users.
WidgetContext context provides step definitions to add/remove widgets from sidebars.
Dashboard context provides a range of step definitions for generally interacting with, and navigating around, the WordPress administration screens (i.e. wp-admin).