Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Update bootstrap.php to support themes #255

Open
kasparsd opened this issue Aug 17, 2017 · 4 comments
Open

Update bootstrap.php to support themes #255

kasparsd opened this issue Aug 17, 2017 · 4 comments

Comments

@kasparsd
Copy link
Contributor

We should update phpunit-plugin-bootstrap.php to support theme THEME_GIT_PLUGIN_DEPENDENCIES since #150 was merged. Similar to how we activate WP_TEST_ACTIVATED_PLUGINS:

function xwp_filter_active_plugins_for_phpunit( $active_plugins ) {
$forced_active_plugins = array();
if ( file_exists( WP_CONTENT_DIR . '/themes/vip/plugins/vip-init.php' ) && defined( 'WP_TEST_VIP_QUICKSTART_ACTIVATED_PLUGINS' ) ) {
$forced_active_plugins = preg_split( '/\s*,\s*/', WP_TEST_VIP_QUICKSTART_ACTIVATED_PLUGINS );
} else if ( defined( 'WP_TEST_ACTIVATED_PLUGINS' ) ) {
$forced_active_plugins = preg_split( '/\s*,\s*/', WP_TEST_ACTIVATED_PLUGINS );
}
if ( ! empty( $forced_active_plugins ) ) {
foreach ( $forced_active_plugins as $forced_active_plugin ) {
$active_plugins[] = $forced_active_plugin;
}
}
return $active_plugins;
}

@valendesigns
Copy link
Contributor

Here's the bootstrap.php file I used to test the branch. I don't think we need support for THEME_GIT_PLUGIN_DEPENDENCIES inside phpunit-plugin-bootstrap.php. However, I do think we should add a phpunit-theme-bootstrap.php file to demonstrate how it works. The WP_TEST_ACTIVATED_PLUGINS constant is pulled from the phpunit.xml.dist file, which is the same data and sort of redundant but they serve slightly different purposes and I'm fairly certain out of scope from each other.

@valendesigns
Copy link
Contributor

Also, we should add something similar to the phpunit-plugin.xml but for themes. In my version I added a WP_TEST_ACTIVATED_THEME constant that was used like so:

/**
 * Activate the theme
 */
function _manually_load_theme() {
	if ( defined( 'WP_TEST_ACTIVATED_THEME' ) ) {
		switch_theme( WP_TEST_ACTIVATED_THEME );
	}
}
tests_add_filter( 'muplugins_loaded', '_manually_load_theme' );

@kasparsd
Copy link
Contributor Author

I don't think we need support for THEME_GIT_PLUGIN_DEPENDENCIES inside phpunit-plugin-bootstrap.php.

My thinking was that a generic sample bootstrap.php file could support both plugin and theme dependancies. What are the drawbacks of this approach?

@kasparsd
Copy link
Contributor Author

I have the local theme folder named differently than the GitHub repo which is why WP_TEST_ACTIVATED_THEME doesn't work for me. I did this:

switch_theme( 'vip/' . basename( dirname( __DIR__ ) ) );

in bootstrap.php.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants