I’ve just finished writing a WordPress plugin implementing shortcode tag based autocompletion based on values retrieved from a database given an id set on a cookie.
The plugin has a variety of combinations of possible scenarios, based on parameters such as:
whether or not to display matched fields
whether to limit (matched or not) fields to be displayed to a certain maximum
whether to show a particular set of fields under any circumstances, if matched
As simple as it seems it’s giving me a considerable headache (and taking a considerable amount of time) to test all scenarios after every revision. My contractor is also a little pissed off of the constant regressions and missed bugs he is finding on my code as the project gets bigger.
So, my question is quite simple: What would be the best approach for designing PHP unit tests for a plugin implementing shortcode tags in WordPress?
My best idea is to write a set of posts containing the test cases and use file_get_contents($posturl) to compare the expected content output with the actual output but there has to be a better way. Any ideas?
If you haven’t studied up on WordPress’s own unit testing tools and how to use them with plugins, I’d recommend that you do that. Here’s a tutorial I wrote, to get you started: http://codesymphony.co/writing-wordpress-plugin-unit-test
I wrote a tutorial on setting up a PHPUnit Test fixture for WordPress plugin development. Have a look at http://mdwpmerchant.com.au/building-testable-phpunit-wordpress-plugin/