/wordpress-plugin-tests

A Travis CI compatible unit testing for WordPress plugins that utilizes the WordPress core unit testing framework and PHPUnit

Primary LanguagePHP

WordPress Plugin Tests

A Travis CI compatible unit testing architecture for WordPress plugins that use WordPress core's official unit-testing framework and PHPUnit

Build Status

How it Works

  • Automatically fires after every commit (or you can specificy certain branches)
  • Downloads and sets up multiple versions of WordPress and PHP (as many as you want to specify)
  • Runs all the tests and e-mails you on failure

Assumptions

  • You have a WordPress plugin in GitHub (and thus a GitHub account)
  • You posses basic knowledge of how to add and edit files using git

How to integrate with your plugin

  1. Place .travis.yml file in your plugin's root folder (you may want to customize your build settings here)
  2. Create a subfolder of your plugin called tests/ and copy over the bootstrap.php and phpunit.xml files from this repo's test/ folder
  3. Customize the newly coppied /tests/bootstrap.php with the path to your plugin file
  4. Set up the tests library as a submodule: git submodule add git://github.com/scribu/wp-tests-lib.git tests/lib
  5. Activate Travis CI for your plugin
  6. Add tests to the tests/ folder following the instructions below

Running the tests locally

All you need to do is set up a wp-tests-config.php file inside the tests directory. (sample)

Then, run the tests:

cd /path/to/your-plugin/tests
phpunit

The Tests

  • Each test file should live in the tests/ folder and should be named in the format of test_{name_of_test}.php.
  • Each test file should contain a single class named in the form of WP_Test_{name_of_test} that extends WP_UnitTestCase.
  • Example Tests: WP Document Revisions

Note

There's a separate branch setup which contains setup and config files which are pulled down on the fly when testing.

How to Contribute

  1. Fork the project to your account, make changes, and submit a pull request
  2. Integrate with your plugin and open issues / feature requests as you see fit

Changelog

  • 2013-01-19 - Mandate plugins have wp-tests-lib as a submodule.
  • 2012-09-15 - Removed wordpress-tests submodule in favor of core's SVN.
  • 2012-04-16 - Initial commit of skelton based off of (legacy) core testing framework.
  • 2012-06-30 - Complete rewrite to rely on newer wordpress-tests framework and better PHPUnit integration.

Contributors

Special thanks to @johnpbloch and @scribu for doing much of the legwork on the rewrite.