From 961689b8f44700f9426f2cc54861b5be47d032cf Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 30 Oct 2026 20:40:17 +0100 Subject: [PATCH 1/2] Add a step for scenarios that need a specific set of themes Co-Authored-By: Claude Opus 5.5 --- features/behat-steps.feature | 32 ++++++++++++++++++++++++++++ src/Context/FeatureContext.php | 17 +++++++++++++++ src/Context/GivenStepDefinitions.php | 31 +++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/features/behat-steps.feature b/features/behat-steps.feature index 09856fc0..b8adf635 100644 --- a/features/behat-steps.feature +++ b/features/behat-steps.feature @@ -542,6 +542,38 @@ Feature: Test that WP-CLI Behat steps work as expected And the wp-content/themes/oceanly-green/style.css file should exist And the wp-content/themes/oceanly/style.css file should exist + @require-wp + Scenario: Keep only the listed themes + Given a WP installation + And only these installed themes: + """ + twentysixteen + twentyseventeen + """ + + When I run `wp theme list --format=count` + Then STDOUT should be: + """ + 2 + """ + And the wp-content/themes/twentysixteen/style.css file should exist + And the wp-content/themes/twentyseventeen/style.css file should exist + + @require-wp + Scenario: Keep only the listed theme and activate it + Given a WP installation + And only these installed and active themes: + """ + twentysixteen + """ + + When I run `wp theme list --fields=name,status --format=csv` + Then STDOUT should be: + """ + name,status + twentysixteen,active + """ + @require-wp Scenario: Test custom wp-content directory Given a WP installation diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index 14785b3b..75bd4e30 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -1934,6 +1934,23 @@ public function install_extensions( $type, array $lines, $activate ): void { } } + /** + * Remove every installed theme, like `wp theme delete --all --force` does. + */ + public function remove_all_themes(): void { + $themes_dir = $this->get_extension_dir( 'theme' ); + if ( null === $themes_dir ) { + throw new RuntimeException( 'Could not find the themes directory.' ); + } + + $entries = scandir( $themes_dir ); + foreach ( false === $entries ? [] : $entries as $entry ) { + if ( '.' !== $entry[0] && is_dir( "$themes_dir/$entry" ) ) { + self::remove_dir( "$themes_dir/$entry" ); + } + } + } + /** * Get the directory plugins or themes are installed into, or null if it is not known. * diff --git a/src/Context/GivenStepDefinitions.php b/src/Context/GivenStepDefinitions.php index 21d51e09..987b34e8 100644 --- a/src/Context/GivenStepDefinitions.php +++ b/src/Context/GivenStepDefinitions.php @@ -404,6 +404,37 @@ public function given_a_wp_multisite_installation( $type = 'subdirectory' ): voi )->run_check(); } + /** + * Removes all themes and installs, and optionally activates, the listed ones instead. + * + * Takes the same lines as `Given these installed themes:`. This replaces running + * `wp theme delete --all --force` followed by one or more `wp theme install` commands. + * + * ``` + * Scenario: My example scenario + * Given a WP installation + * And only these installed themes: + * """ + * twentysixteen + * twentyseventeen + * """ + * ``` + * + * @access public + * + * @Given /^only these installed (themes|and active themes):$/ + * + * @param string $kind Either 'themes' or 'and active themes'. + * @param PyStringNode $stream + */ + public function given_only_these_installed_themes( $kind, PyStringNode $stream ): void { + $lines = array_filter( array_map( 'trim', explode( "\n", $this->replace_variables( (string) $stream ) ) ) ); + $activate = 'and active themes' === $kind; + + $this->remove_all_themes(); + $this->install_extensions( 'theme', $lines, $activate ); + } + /** * Installs and optionally activates one or more plugins or themes. * From b2edc3cf17f4dbdee01881ac8d3a4aa381214a40 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sat, 31 Oct 2026 04:03:44 +0100 Subject: [PATCH 2/2] Run the checks again with the current workflows Co-Authored-By: Claude Opus 5.5