diff --git a/features/behat-steps.feature b/features/behat-steps.feature index 1e95872f..fd32cd45 100644 --- a/features/behat-steps.feature +++ b/features/behat-steps.feature @@ -601,6 +601,45 @@ Feature: Test that WP-CLI Behat steps work as expected 'WP_CLI_TEST_CONSTANT', 'a value' """ + @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 @@ -612,6 +651,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 @@ -658,6 +699,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 diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index 9b0e2265..08246a5b 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -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 @@ -1932,6 +1932,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*/ ); } @@ -2284,6 +2288,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 { diff --git a/src/Context/GivenStepDefinitions.php b/src/Context/GivenStepDefinitions.php index c8553456..0c606820 100644 --- a/src/Context/GivenStepDefinitions.php +++ b/src/Context/GivenStepDefinitions.php @@ -552,6 +552,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';