Implement phpunit testing on a plugin

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:

Read More

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?

Related posts

2 comments

Comments are closed.