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
32 changes: 32 additions & 0 deletions features/behat-steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
31 changes: 31 additions & 0 deletions src/Context/GivenStepDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading