Skip to content
This repository was archived by the owner on Jul 23, 2023. It is now read-only.
johnbintz edited this page Sep 13, 2010 · 11 revisions

What is it?

MockPress is a helper library that makes setting up automated tests for WordPress plugins and themes simple. It simulates as many of the core WordPress functions as possible, allowing you to set up PHPUnit or SimpleTest test suites against your plugin without needing to load in WordPress.

What is it not?

It doesn’t provide mocked versions of actual WordPress objects. Both PHPUnit and SimpleTest allow you to create mock objects easily. This library handles the global functions that WP provides and through which you’ll be doing most of your interaction with WordPress.

How do I install it?

The recommended method is using PEAR. I don’t have a PEAR channel set up for MockPress yet so you’ll have to use a slightly more complicated installation procedure beyond the normal one. The PEAR builds are at http://www.coswellproductions.com/mockpress/pear/ and the latest build is always linked to latest.tgz.

Installation & Upgrading

pear upgrade -f http://www.coswellproductions.com/mockpress/pear/latest.tgz

Uninstalling

pear uninstall __uri/MockPress

How do I use it?

See Using MockPress to Test Your Plugin or Theme.

What does it simulate?

The most important functions for working with:

  • Blog options
  • Strings & i18n
  • Categories
  • Tags
  • Posts
  • Hooks (setting only)
  • Admin UI
  • Plugin API
  • Nonces
  • Theme API
  • Query strings
  • Pre-WordPress 2.8 and WP 2.8 Widgets
  • Template tags
  • Theme state
  • Media attachments
  • Users
  • User metadata

And it includes an XPath test suite for checking XML and XHTML output from functions.

Take a look at the automatically generated PHPDocumentor documentation for more information.

What do I need?

  • PHP 5 or better for SimpleXML support
  • A unit testing framework (PHPUnit or SimpleTest)

How can I help?

If you’ve run into a bug or need a function mocked up:

  • Fork the project on GitHub, add your code, and send me a Pull Request. I’ll pull them into the main codebase.
  • Mail me with a patch or the working mock function and I’ll insert it into the main codebase.