Skip to content

Testing Plugins And Themes

scribu edited this page Jun 25, 2012 · 1 revision

Besides running WordPress Core tests, this framework can also be used for testing plugins and themes.

First thing you need to do is create a bootstrap.php file, which will look something like this:

<?php

$GLOBALS['wp_tests_options'] = array(
    'active_plugins' => array( 'hello/hello.php' ),
    'template' => 'twentyeleven',
    'stylesheet' => 'twentytest',
);

require '/path/to/wp-tests/init.php';

In general, any key that you set in the 'wp_tests_options' global represents an option from the wp_options table that will be overwritten when running the test.

Next, write some tests in a file; let's call it test_hello.php:

<?php

class WP_Test_Hello_Dolly extends WP_UnitTestCase {

	function test_hello_dolly() {
		ob_start();
		hello_dolly();
		$hello_dolly_output = ob_get_clean();
		$this->assertContains( "id='dolly'", $hello_dolly_output );
	}
}

Finally, run the tests, using the bootstrap:

phpunit --bootstrap bootstrap.php test_hello.php
Clone this wiki locally