Writing test cases for a WordPress Plugin that has translations

If all that you want to test is that the translation files exist, then this is probably the simplest approach, since you’ll probably already be using PHPUnit to run unit/integration tests on the plugin code. However, just checking whether the files exist doesn’t tell you much. It doesn’t tell you whether those languages are actually … Read more

PHP unit testing WordPress?

There is nothing stopping you from writing your own unit testing for themes/plugins using PHPUnit or some other testing platform. As for WordPress, it has an official Unit Tests here: http://unit-tests.svn.wordpress.org/trunk/ https://github.com/kurtpayne/wordpress-unit-tests (github mirror) There are several build scripts that can automate unit testing found here, including WP-CLI that have built in unit testing, though … Read more

Unit tests – Dealing with dependencies

Is object injection really necessary? To be fully testable in isolation, code should avoid to instantiate classes directly, and inject any object that is needed inside objects. However, there are at least two exceptions to this rule: The class is a language class, e.g. ArrayObject The class is a proper “value object”. No need to … Read more

Vagrant script to setup all the common PHP / WordPress version combinations

On the WordPress side of things, Basic WordPress Vagrant Environment is ready to work with any WordPress version (with a little help). You would still need to find a way to configure the PHP but there is a hint in https://github.com/ideasonpurpose/basic-wordpress-box/blob/master/ansible/roles/php/tasks/php.yml. To use it out of the box; Download or clone the project to wplatest-php55.dev/ … Read more

Show different theme for admin?

I just wrote this quick plugin and it seems to work. Let me know if there is a better way. <?php /* Plugin Name: Theme Switch if Admin Description: Display different theme to user if logged in as admin Author: Kyle Barber */ add_filter(‘template’, ‘change_theme’); add_filter(‘option_template’, ‘change_theme’); add_filter(‘option_stylesheet’, ‘change_theme’); function change_theme($theme) { if ( current_user_can(‘manage_options’) … Read more

Developing, Testing and Releasing

There is a bit of personal philosophy that goes into a deployment workflow. It’s not an easy question to answer outright without knowing your experience with servers and version control, your operating system, hosting, client’s experience and tech culture, etc… Here’s a similar question that has a lot of explanation. For content deployment, you can … Read more

Unit testing in the WordPress backend (is_admin() is true)

According to this test, you use set_current_screen() to navigate to one of these in the setUp method. Alas, none of this is apparent if you look at the tremendously-helpful reference page for get_current_screen()… Example: <?php class AxisSetupTest extends WP_UnitTestCase { /** * @covers AxisWP::__construct */ function test_constructor() { // Assert // Admin $this->assertInternalType(‘integer’, has_action( ‘admin_enqueue_scripts’, … Read more