Writing A Simple WordPress Unit Test
When we unit test WordPress, the best approach is to use WP_UnitTestCase. This class extends the PHPUnit_Framework_TestCase with functions and properties which are specific to WordPress. The factory object demonstrates this. It handles many functions for you with a minimal amount of coding on your part. For example, if you desired to use factory to create a user, you would simply include the following line in your test:
$user_id = $this->factory->user->create();
So, when you need a user, a post, or some other “testable” thing upon which to work your testing ways, you can get it done quickly. This frees us to focus on writing tests rather than constructing methods to create scenarios.
Set Up
— Install WordPress onto your server
— Install my open source theme which you can get here
— Install my Amoratis CHMOD WordPress plugin which you can get here.
Now that you have WordPress with my theme and my plugin we are ready to begin. Once we launch our tests, we will – in the tests – configure a temporary WordPress install to use this theme and plugin.