Skip to content

daxitude/wordpress-plugin-tests

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 

Repository files navigation

WordPress Plugin Tests

A Travis CI compatible unit testing architecture for WordPress plugins that utilizes 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)
  • Downloads the WordPress unit testing framework if it doesn't already exist in the tests/wordpress-tests directory as a submodule
  • 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 all.php, 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. Activate Travis CI for your plugin
  5. Add tests to the tests/ folder following the instructions below

Running the tests locally

First, set up the WP testing framework: http://make.wordpress.org/core/handbook/automated-testing/#installation

Then, add the environment variables to your .bashrc file:

export WP_TESTS_DIR=~/wordpress-tests
export WP_CORE_DIR=~/path/to/wordpress-core

Finally, 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.sh 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

  • 9/15/2012 - Removed wordpress-tests submodule in favor of core's SVN
  • 4/16/2012 - Initial commit of skelton based off of (legacy) core testing framework
  • 6/30/2012 - Complete rewrite to rely on newer wordpress-tests framework and better PHPUnit integration

Roadmap/todo

  • Include git-based core testing framework as submodule when there's an official git version
  • Ability to integrate with plugins as a submodule to allow for update
  • Ability to customize configuration as pulled down from setup.sh

Contributors

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published