wp-browser provides easy acceptance, functional, integration and unit testing for WordPress plugins, themes and whole sites using Codeception.
Find out more in the documentation.
Using Composer require wp-browser
as a development dependency:
cd my-wordrpess-project
composer require --dev lucatume/wp-browser
vendor/bin/codecept init wpbrowser
Answer the questions and you will be ready to test your project. Find out more about the setup in the project documentation.
Codeception version 4.0
, while still being compatible with PHP 5.6
and wp-browser, did break its structure into discrete modules.
If you want to use wp-browser with Codeception version 4.0+
you will need to make sure you've got all the required packages.
Add the following requirements in your composer.json
file, in the require-dev
section:
{
"require-dev": {
"lucatume/wp-browser": "^3.0",
"codeception/module-asserts": "^1.0",
"codeception/module-phpbrowser": "^1.0",
"codeception/module-webdriver": "^1.0",
"codeception/module-db": "^1.0",
"codeception/module-filesystem": "^1.0",
"codeception/module-cli": "^1.0",
"codeception/util-universalframework": "^1.0"
}
}
You might not need all of them depending on the modules you use in your suites, but this will cover all the modules for this project.
The project provides a number of modules to ease the testing of WordPress projects; you can find out more in the
modules section of the documentation.
Here's a quick example acceptance test you can write:
// tests/acceptance/PrivatePostsCept.php
$I->haveManyPostsInDatabase(3, ['post_title' => 'Test post {{n}}', 'post_status' => 'private']);
$I->loginAs('subscriber', 'secret');
$I->amOnPage('/');
$I->see('Nothing found');
$I->loginAs('editor', 'secret');
$I->amOnPage('/');
$I->see('Test post 0');
$I->see('Test post 1');
$I->see('Test post 2');
This is just a bite though, find out more in the documentation.
My sincere thanks to my sponsors: you make maintaining this project easier.