I have performed a unit testing for a plugin that works perfectly until the section where I need to activate the theme and check if the theme is supplying the right hooks data to the plugin.
Inside the plugin that I’m testing, I have apply_filters that will implement the add_filter hooks defined inside the theme functions.php.
This is my unit testing code:
function test_theme_hooks() {
//Define required plugins for testing
$requiredplugins=array( '0' => 'myplugin1/plugin1.php','1' => 'myplugin2/plugin2.php');
//Activate plugins
update_option('active_plugins',$requiredplugins);
//Activate theme
switch_theme('my_theme_to_test', 'my_theme_to_test');
//Get groups defined by the theme
$Class_My_Plugin = new Class_My_Plugin;
$groups_definedfrom_theme = $Class_My_Plugin->get_groups();
$correct_groups=array('0'=>'Some array');
$this->assertEqual($correct_groups,$groups_definedfrom_theme);
}
The problem is that, it seems that the theme functions.php is not read or executed during the test. I have manually checked that the theme has been successfully switched/enabled as well as the required plugins. But the result of $groups_definedfrom_theme is NULL which is not correct.
Any tips how to do this test correctly or how to make the unit test read the active theme functions.php as well as well as it’s filters?
Thanks for any help.