What areas to Unit test while building a plugin?

Types of tests First, note that “unit testing” in WordPress generally goes beyond unit testing, and is more like functional/integration testing. This is more of a technical difference, but if you understand the difference between these different things, you may sometimes be confused by how WordPress “unit” tests things. When you ask what parts of … Read more

How to create a test that calls is_front_page in phpunit?

The is_front_page() function calls wp_query::is_front_page(). If you scroll down to look at the source, you will see the code you’re looking to trigger: elseif ( ‘page’ == get_option( ‘show_on_front’) && get_option( ‘page_on_front’ ) && $this->is_page( get_option( ‘page_on_front’ ) ) ) return true; To meet that condition, you’ll just need to do this in the code … Read more

PHPUnit testing WordPress Plugin

The reason the WordPress test bootstrap is loaded at the end is precisely because it loads WordPress: // Load WordPress require_once ABSPATH . ‘/wp-settings.php’; If you don’t hook your function to load your plugin to ‘muplugins_loaded’ before including the bootstrap, your plugin won’t be loaded with WordPress. In most cases that will mean that your … Read more

How to write testable classes in WordPress

WordPress is far from having a standard conventions for unit testing extensions. Or for extension structure in general. At current time you should either: research how unit testing framework of your choice recommends to work with globals and such for PHP code in general look into WordPress-specific tools for unit testing that start to appear, … Read more