PHP Class Codeception\Module\WPLoader

Loads a WordPress installation for testing purposes. The class is a Codeception adaptation of WordPress automated testing suite, see here, and takes care of configuring and installing a WordPress installation. To work properly the \WP_UnitTestCase should be used to run the tests in a PHPUnit-like behaviour.
Inheritance: extends Codeception\Module
Show file Open project: lucatume/wp-browser

Public Properties

Property Type Description
$excludeActions
$includeInheritedActions
$onlyActions

Protected Properties

Property Type Description
$config array All of the fields have a correspondant in the standard wp-tests-config.php file found in WordPress automated testing suite. isolatedInstall - bool, def. true, whether the WP installation should happen in an isolated process(core like) or not (previous wp-browser method). wpDebug - bool, def. true, the WP_DEBUG global value. multisite - bool, def. false, if set to true will create a multisite installation, the WP_TESTS_MULTISITE global value. dbCharset - string, def. utf8, the DB_CHARSET global value. dbCollate - string, def. , the DB_COLLATE global value. tablePrefix - string, def. wptests_, the WP_TESTS_TABLE_PREFIX value. domain - string, def. example.org, the root URL of the site, the WP_TESTS_DOMAIN global value. adminEmail - string, def. [email protected], the admin email, the WP_TEST_EMAIL global value. title - string, def. Test Blog, the blog title, the WP_TESTS_TITLE global value. phpBinary - string, def. php, the php bin command, the WP_PHP_BINARY global value. language - string, def. , the installation language, the WPLANG global value. configFile - string or array, def. , the path, or an array of paths, to custom config file(s) relative to the wpRootFolder folder, no leading slash needed; this is the place where custom wp_tests_options could be set. pluginsFolder - string, def. , the relative path to the plugins folder in respect to the WP root folder plugins - array, def. [], a list of plugins that should be loaded before any test case runs and after mu-plugins have been loaded; these should be defined in the folder/plugin-file.php format. activatePlugins - array, def. [], a list of plugins that should be activated calling the activate_{$plugin} before any test case runs and after mu-plugins have been loaded; these should be defined in the folder/plugin-file.php format. bootstrapActions - array, def. [], a list of actions that should be called after before any test case runs.
$pluginsFolder The absolute path to the plugins folder
$requiredFields array wpRootFolder - the absolute path to the root folder of the WordPress installation to use for testing, the ABSPATH global value. dbNAme - the name of the database to use for the tests, will be trashed during tests so take care, will be the DB_NAME global. dbHost - the host the database can be found at, will be the DB_HOST global. dbUser - the database privileged user, should GRANT ALL on the database, will be the DB_USER global. dbPassword - the password for the user, will be the DB_PASSWORD global.
$wpBootstrapFile string The path to the modified tests bootstrap file.
$wpRootFolder The absolute path to WP root folder (ABSPATH).

Public Methods

Method Description
__construct ( Codeception\Lib\ModuleContainer $moduleContainer, $config, tad\WPBrowser\Adapters\WP $wp = null )
_initialize ( ) : void The function that will initialize the module.
_setActiveTheme ( ) Sets the active template and stylesheet according to the theme configuration parameter.
_switch_theme ( )
activatePlugins ( )
bootstrapActions ( ) Calls a list of user-defined actions needed in tests.
ensureDbModuleCompat ( )
loadPlugins ( ) Loads the plugins required by the test.

Protected Methods

Method Description
defineGlobals ( ) : void Defines the globals needed by WordPress to run to user set values.
getPluginsFolder ( ) : string
getWpRootFolder ( ) : string
initialize ( )
loadConfigFile ( string $folder = null )
loadWordPress ( ) : void Loads WordPress calling the bootstrap file
requiresIsolatedInstallation ( ) : boolean | mixed
setActivePlugins ( )

Private Methods

Method Description
ensureWPRoot ( string $wpRootFolder )

Method Details

__construct() public method

public __construct ( Codeception\Lib\ModuleContainer $moduleContainer, $config, tad\WPBrowser\Adapters\WP $wp = null )
$moduleContainer Codeception\Lib\ModuleContainer
$wp tad\WPBrowser\Adapters\WP

_initialize() public method

The function will set up the WordPress testing configuration and will take care of installing and loading WordPress. The simple inclusion of the module in an test helper class will hence trigger WordPress loading, no explicit method calling on the user side is needed.
public _initialize ( ) : void
return void

_setActiveTheme() public method

Sets the active template and stylesheet according to the theme configuration parameter.
public _setActiveTheme ( )

_switch_theme() public method

public _switch_theme ( )

activatePlugins() public method

public activatePlugins ( )

bootstrapActions() public method

Calls a list of user-defined actions needed in tests.
public bootstrapActions ( )

defineGlobals() protected method

The method replaces the "wp-tests-config.php" file the original testing workflow included to allow run-time customization of the globals in a Codeception friendly way.
protected defineGlobals ( ) : void
return void

ensureDbModuleCompat() public method

getPluginsFolder() protected method

protected getPluginsFolder ( ) : string
return string

getWpRootFolder() protected method

protected getWpRootFolder ( ) : string
return string

initialize() protected method

protected initialize ( )

loadConfigFile() protected method

protected loadConfigFile ( string $folder = null )
$folder string = null The absolute path to the WordPress root installation folder.

loadPlugins() public method

Loads the plugins required by the test.
public loadPlugins ( )

loadWordPress() protected method

This method does little but wrapping preparing the global space for the original automated testing bootstrap file and taking charge of replacing the original "wp-tests-config.php" file in setting up the globals.
protected loadWordPress ( ) : void
return void

requiresIsolatedInstallation() protected method

setActivePlugins() protected method

protected setActivePlugins ( )

Property Details

$config protected property

All of the fields have a correspondant in the standard wp-tests-config.php file found in WordPress automated testing suite. isolatedInstall - bool, def. true, whether the WP installation should happen in an isolated process(core like) or not (previous wp-browser method). wpDebug - bool, def. true, the WP_DEBUG global value. multisite - bool, def. false, if set to true will create a multisite installation, the WP_TESTS_MULTISITE global value. dbCharset - string, def. utf8, the DB_CHARSET global value. dbCollate - string, def. , the DB_COLLATE global value. tablePrefix - string, def. wptests_, the WP_TESTS_TABLE_PREFIX value. domain - string, def. example.org, the root URL of the site, the WP_TESTS_DOMAIN global value. adminEmail - string, def. [email protected], the admin email, the WP_TEST_EMAIL global value. title - string, def. Test Blog, the blog title, the WP_TESTS_TITLE global value. phpBinary - string, def. php, the php bin command, the WP_PHP_BINARY global value. language - string, def. , the installation language, the WPLANG global value. configFile - string or array, def. , the path, or an array of paths, to custom config file(s) relative to the wpRootFolder folder, no leading slash needed; this is the place where custom wp_tests_options could be set. pluginsFolder - string, def. , the relative path to the plugins folder in respect to the WP root folder plugins - array, def. [], a list of plugins that should be loaded before any test case runs and after mu-plugins have been loaded; these should be defined in the folder/plugin-file.php format. activatePlugins - array, def. [], a list of plugins that should be activated calling the activate_{$plugin} before any test case runs and after mu-plugins have been loaded; these should be defined in the folder/plugin-file.php format. bootstrapActions - array, def. [], a list of actions that should be called after before any test case runs.
protected array $config
return array

$excludeActions public static property

public static $excludeActions

$includeInheritedActions public static property

public static $includeInheritedActions

$onlyActions public static property

public static $onlyActions

$pluginsFolder protected property

The absolute path to the plugins folder
protected $pluginsFolder

$requiredFields protected property

wpRootFolder - the absolute path to the root folder of the WordPress installation to use for testing, the ABSPATH global value. dbNAme - the name of the database to use for the tests, will be trashed during tests so take care, will be the DB_NAME global. dbHost - the host the database can be found at, will be the DB_HOST global. dbUser - the database privileged user, should GRANT ALL on the database, will be the DB_USER global. dbPassword - the password for the user, will be the DB_PASSWORD global.
protected array $requiredFields
return array

$wpBootstrapFile protected property

The path to the modified tests bootstrap file.
protected string $wpBootstrapFile
return string

$wpRootFolder protected property

The absolute path to WP root folder (ABSPATH).
protected $wpRootFolder