Added support for one of WordPress most useful features in WPBrowser.
Since WordPress 3.9
It’s been quite some time WordPress introduced support for symbolically linked plugins and themes and I’ve used the features extensively in my local setup.
In an effort to make that possibility easy to use in the tests too I’ve pushed version 1.10.10 of WPBrowser to GitHub.
Copying the readme text below.
Symlinker
The tad\WPBrowser\Extension\Symlinker
extension provides an automation to have the Codeception root directory symbolically linked in a WordPress local installation.
Since version 3.9
WordPress supports this feature (with some precautions) and the extension takes charge of:
- symbolically linking a plugin or theme folder in the specified destination before any suite boots up
- unlinking that symbolic link after all of the suites did run
It’s the equivalent of doing something like this from the command line (on a Mac):
ln -s /my/central/plugin/folder/my-plugin /my/local/wordpress/installation/wp-content/plugins/my-plugin
/my/central/plugin/folder/my-plugin/vendor/bin/codecept run
rm -rf /my/local/wordpress/installation/wp-content/plugins/my-plugin
The extension needs small configuration in the codeception.yml
file:
extensions:
enabled:
- tad\WPBrowser\Extension\Symlinker
config:
tad\WPBrowser\Extension\Symlinker:
mode: plugin
destination: /my/local/wordpress/installation/wp-content/plugins
The arguments are:
mode
- can beplugin
ortheme
and indicates whether the current Codeception root folder being symlinked is a plugin or a theme onedestination
- the absolute path to the WordPress local installation plugins or themes folder; to take the never-ending variety of possible setups into account the extension will make no checks on the nature of the destination: could be any folder.
Symlinker extension and environments
As of Codeception version 2.1.8
enabling and disabling extensions on an environment base is not possible; this means the code below will not work (but sure it would be nice):
# Codeception Test Suite Configuration
# suite for WordPress acceptance tests.
# perform tests in browser using WPBrowser or WPWebDriver modules.
class_name: AcceptanceTester
modules:
enabled:
- WPBrowser
- WPDb
- \Helper\Acceptance
env:
single:
modules:
config:
WPBrowser:
url: 'http://wp.dev'
extensions:
config:
tad\WPBrowser\Extension\Symlinker:
mode: plugin
destination: /Users/Luca/Sites/wp/wp-content/plugins
multisite:
modules:
config:
WPBrowser:
url: 'http://mu.dev'
extensions:
config:
tad\WPBrowser\Extension\Symlinker:
mode: plugin
destination: /Users/Luca/Sites/mu/wp-content/plugins
Next
I will work on some alternate syntax waiting for environment nested extension configuration to happen.