WordPress extension for Behat 3
PHP Gherkin Shell
Pull request Compare This branch is 269 commits ahead of johnbillion:develop.
Latest commit 1ca1496 Feb 17, 2017 @stephenharris committed on GitHub Merge pull request #12 from davidbenton/patch-1
Correct variable for term insert error message
Failed to load latest commit information.
ci First pass at using apache server rather than php's built-in server Dec 11, 2016
features WordPress context no longer extends MinkContext Dec 20, 2016
src Correct variable for term insert error message Feb 17, 2017
.gitignore Don't version control the failed-scenarios directory (stores data cre… Oct 12, 2016
LICENSE Update license file Oct 19, 2016
behat.yml Add site_url setting to point to the site URL Dec 20, 2016
composer.json PHPUnit is required by the WordPressBehat extension Dec 21, 2016
composer.lock PHPUnit is required by the WordPressBehat extension Dec 21, 2016
couscous.yml Fix typo in description. At GitHub repo link. Dec 21, 2016


WordPress Extension for Behat 3

This is a Behat 3.0 Extension for WordPress plugin and theme development.

The Extension allows you to use WordPress functions in your context class if you include StephenHarris\WordPressBehatExtension\Context\WordPressContext (or create and include a child class of it, i.e. make your FeatureContext ).

It also provides other contexts.

Version: 0.4.0 . This project follows SemVer.


This repository started off as a fork of:


(For 'quick start' guides, please see the Recipes).

  1. Add a composer development requirement for your WordPress theme or plugin:

        "repositories": [
                "type": "vcs",
                "url": "https://github.com/stephenharris/WordPressBehatExtension.git"
        "require-dev" : {
            "stephenharris/wordpress-behat-extension": "~0.3",
            "behat/mink-goutte-driver": "~1.1",
            "behat/mink-selenium2-driver": "~1.3.1",
            "johnpbloch/wordpress": "~4.6.1"

    You don't have to install WordPress via composer. But you shall need a path to a WordPress install below. Additionally you don't have to use the Goutte and Selenium2 drivers, but these are the most common.

  2. Add the following Behat configuration file below. You will need:

    • The path to your WordPress install (here assumed vendor/wordpress, relative to your project's root directory).
    • The database, and database username and password of your WordPress install (here assumed wordress_test, root, '')
    • The URL of your WordPress install (In this example we'll be using php's build in server)
    • A temporary directory to store e-mails that are 'sent'

              - FeatureContext
              - \StephenHarris\WordPressBehatExtension\Context\WordPressContext
              - \StephenHarris\WordPressBehatExtension\Context\Plugins\WordPressPluginContext
              # and any other contexts you need, please see the documentation
            path: '%paths.base%/vendor/wordpress'
              db: 'wordpress_test'
              username: 'root'
              password: ''
              directory: '/tmp/mail'
            base_url:    'http://localhost:8000'
            goutte: ~
            selenium2: ~

      Note the StephenHarris\WordPressBehatExtension\Context\WordPressContext context included. This will cause WordPress to be loaded, and all its functions available in your context classes.. You can also include other contexts.

  3. Install the vendors and initialize behat test suites

    composer update
    # You will need to ensure a WordPress install is available, with database credentials that
    # mach the configuration file above
    vendor/bin/behat --init
  4. Write some Behat features in your project's features directory and define any steps. The WordPressContext context will make all WordPress functions available in your context classes (but there is a better way).

    Feature: Manage plugins
        In order to manage plugins
        As an admin
        I need to enable and disable plugins
            Given I have a vanilla wordpress installation
                | name          | email                   | username | password |
                | BDD WordPress | your@email.com          | admin    | test     |
            And I am logged in as "admin" with password "test"
        Scenario: Enable the dolly plugin
            Given there are plugins
                | plugin    | status  |
                | hello.php | enabled |
            When I go to "/wp-admin/"
            Then I should see a "#dolly" element
        Scenario: Disable the dolly plugin
            Given there are plugins
                | plugin    | status   |
                | hello.php | disabled |
            When I go to "/wp-admin/"
            Then I should not see a "#dolly" element
  5. Run the tests

    In our example, since we using PHP's built-in web sever, this will need to be started so that Behat can access our site.

      php -S localhost:8000 -t vendor/wordpress -d disable_functions=mail


    Please see the Docs.


    The aim of this project is to provide a collection of context classes that allow for easy testing of WordPress' core functionality. Those contexts can then be built upon to test your site/plugin/theme-specific functionality.


    WordPressBehatExtension is open source and released under MIT license. See LICENSE file for more info.

    Health Warning

    This is not to be used on a live site. Your database will be cleared of all data.

    Currently this extension also over-rides your wp-config.php but this implementation may change in the future.

    The extension installs three mu-plugins into your install (which it assumes is at {site-path}/wp-content/mu-plugins). These plug-ins do the following:

    • wp-mail.php - over-rides wp_mail() function to store the e-mails locally
    • wp-install.php - over-rides wp_install_defaults() to prevent any default content being created, with the exception of the 'Uncategorised' category.
    • move-admin-bar-to-back.php - a workaround for #1 which prevent elements from being hidden from Selenium behind the admin menu bar.


    A changelog can be found at CHANGELOG.md.

    How to help

    This project needs a lot of love :). You can help by doing any of the following

    • Opening an issue to request a context / step definitions
    • Submitting a PR to add a context / step definition
    • Submiting a PR to add to or improve the documentation
    • Opening an issue you have questions or find any bugs
    • Just using this extension in your development / testing workflow and providing your feedback