Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions features/behat-steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,45 @@ Feature: Test that WP-CLI Behat steps work as expected
When I launch in the background `wp eval 'sleep(2); echo "done";'`
# Background process should not block, continuing immediately

@require-wp
Scenario: Use the plugin and theme directories of a WP installation
Given a WP installation
Then the {PLUGIN_DIR}/akismet directory should exist
And the {THEME_DIR} directory should exist

# Skipped on Windows because WordPress mixes path separators in these paths there.
@require-wp @skip-windows
Scenario: Plugin and theme directory variables match the WordPress constants
Given a WP installation
When I run `wp eval 'echo WP_PLUGIN_DIR;'`
Then STDOUT should be:
"""
{PLUGIN_DIR}
"""

When I run `wp eval 'echo get_theme_root();'`
Then STDOUT should be:
"""
{THEME_DIR}
"""

# Skipped on Windows because WordPress mixes path separators in these paths there.
@require-wp @skip-windows
Scenario: Plugin and theme directory variables follow a custom wp-content directory
Given a WP installation
And a custom wp-content directory
When I run `wp eval 'echo WP_PLUGIN_DIR;'`
Then STDOUT should be:
"""
{PLUGIN_DIR}
"""

When I run `wp eval 'echo get_theme_root();'`
Then STDOUT should be:
"""
{THEME_DIR}
"""

@require-wp
Scenario: Test custom wp-content directory
Given a WP installation
Expand All @@ -479,6 +518,8 @@ Feature: Test that WP-CLI Behat steps work as expected
"""
WP_CONTENT_DIR
"""
And the {PLUGIN_DIR} directory should exist
And the {THEME_DIR} directory should exist

@require-wp
Scenario: Test WP multisite installation
Expand Down Expand Up @@ -525,6 +566,18 @@ Feature: Test that WP-CLI Behat steps work as expected
When I run `wp core version`
Then STDOUT should not be empty

When I run `wp eval 'echo WP_PLUGIN_DIR;'`
Then STDOUT should be:
"""
{PLUGIN_DIR}
"""

When I run `wp eval 'echo get_theme_root();'`
Then STDOUT should be:
"""
{THEME_DIR}
"""

# Skipped on Windows because of curl getaddrinfo() errors.
@require-wp @require-composer @skip-windows
Scenario: Test WP installation with Composer and custom vendor directory
Expand Down
21 changes: 20 additions & 1 deletion src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class FeatureContext implements Context {

/**
* Array of variables available as {VARIABLE_NAME}. Some are always set: CORE_CONFIG_SETTINGS, DB_USER, DB_PASSWORD, DB_HOST, SRC_DIR, CACHE_DIR, WP_VERSION-version-latest.
* Some are step-dependent: RUN_DIR, SUITE_CACHE_DIR, COMPOSER_LOCAL_REPOSITORY, PHAR_PATH. One is set on use: INVOKE_WP_CLI_WITH_PHP_ARGS-args.
* Some are step-dependent: RUN_DIR, SUITE_CACHE_DIR, COMPOSER_LOCAL_REPOSITORY, PHAR_PATH, and PLUGIN_DIR and THEME_DIR for the WordPress files in RUN_DIR. One is set on use: INVOKE_WP_CLI_WITH_PHP_ARGS-args.
* Scenarios can define their own variables using "Given save" steps. Variables are reset for each scenario.
*
* @var array<string, string>
Expand Down Expand Up @@ -1849,6 +1849,10 @@ public function download_wp( $subdir = '', $version = '' ): void {

self::copy_dir( self::$cache_dir, $dest_dir );

if ( ! $subdir ) {
$this->set_content_dir_variables( $dest_dir . '/wp-content' );
}

if ( ! is_dir( $dest_dir . '/wp-content/mu-plugins' ) ) {
mkdir( $dest_dir . '/wp-content/mu-plugins', 0777, true /*recursive*/ );
}
Expand Down Expand Up @@ -2048,6 +2052,21 @@ public function install_wp_with_composer( $vendor_directory = 'vendor' ): void {
}

$this->proc( 'wp core install', $install_args )->run_check();

$this->set_content_dir_variables( $this->variables['RUN_DIR'] . '/WordPress/wp-content' );
}

/**
* Expose the plugins and themes directories as {PLUGIN_DIR} and {THEME_DIR}.
*
* Matches the output of `wp plugin path` and `wp theme path`.
*
* @param string $content_dir
* @param string $plugin_dir Defaults to the plugins directory inside $content_dir.
*/
public function set_content_dir_variables( $content_dir, $plugin_dir = '' ): void {
$this->variables['PLUGIN_DIR'] = $plugin_dir ?: $content_dir . '/plugins';
$this->variables['THEME_DIR'] = $content_dir . '/themes';
}

public function composer_add_wp_cli_local_repository(): void {
Expand Down
2 changes: 2 additions & 0 deletions src/Context/GivenStepDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ public function given_a_custom_wp_directory(): void {

file_put_contents( $wp_config_path, $wp_config_code );

$this->set_content_dir_variables( $this->variables['RUN_DIR'] . '/my-content', $this->variables['RUN_DIR'] . '/my-plugins' );

if ( 'sqlite' === self::$db_type ) {
$db_dropin = $this->variables['RUN_DIR'] . '/my-content/db.php';

Expand Down
Loading