Skip to content

Commit

Permalink
Modified files to respond to @ernilambar’s feedback.
Browse files Browse the repository at this point in the history
Signed-off-by: Saul Baizman <[email protected]>
  • Loading branch information
baizmandesign committed May 8, 2024
1 parent 58db5c9 commit 3c853c9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
40 changes: 19 additions & 21 deletions features/theme-list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,30 @@ Feature: List WordPress themes
Scenario: Refresh update_themes transient when listing themes with --force-check flag
Given a WP install
And I run `wp theme delete --all --force`
And I run `wp theme install --force twentytwentyfour --version=1.1`
And I run `wp theme install --force twentytwelve --version=4.2`
And a update-transient.php file:
"""
<?php
$transient = get_site_transient( 'update_themes' );
$transient->response['twentytwentyfour'] = (object) array(
'theme' => 'twentytwentyfour',
$transient->response['twentytwelve'] = (object) array(
'theme' => 'twentytwelve',
'new_version' => '100.0.0',
'url' => 'https://wordpress.org/themes/twentytwentyfour/',
'package' => 'https://downloads.wordpress.org/theme/twentytwentyfour.100.zip',
'requires' => '6.4',
'requires_php' => '7.0'
'url' => 'https://wordpress.org/themes/twentytwelve/',
'package' => 'https://downloads.wordpress.org/theme/twentytwelve.100.zip'
);
$transient->checked = array(
'twentytwentyfour' => '1.1',
'twentytwelve' => '4.2',
);
unset( $transient->no_update['twentytwentyfour'] );
unset( $transient->no_update['twentytwelve'] );
set_site_transient( 'update_themes', $transient );
WP_CLI::success( 'Transient updated.' );
"""

# Populates the initial transient in the database
When I run `wp theme list --fields=name,status,update`
When I run `wp theme list --fields=name,update`
Then STDOUT should be a table containing rows:
| name | status | update |
| twentytwentyfour | active | none |
| name | update |
| twentytwelve | none |

# Modify the transient in the database to simulate an update
When I run `wp eval-file update-transient.php`
Expand All @@ -38,22 +36,22 @@ Feature: List WordPress themes
"""

# Verify the fake transient value produces the expected output
When I run `wp theme list --fields=name,status,update`
When I run `wp theme list --fields=name,update`
Then STDOUT should be a table containing rows:
| name | status | update |
| twentytwentyfour | active | available |
| name | update |
| twentytwelve | available |

# Repeating the same command again should produce the same results
When I run `wp theme list --fields=name,status,update`
When I run the previous command again
Then STDOUT should be a table containing rows:
| name | status | update |
| twentytwentyfour | active | available |
| name | update |
| twentytwelve | available |

# Using the --force-check flag should refresh the transient back to the original value
When I run `wp theme list --fields=name,status,update --force-check`
When I run `wp theme list --fields=name,update --force-check`
Then STDOUT should be a table containing rows:
| name | status | update |
| twentytwentyfour | active | none |
| name | update |
| twentytwelve | none |

When I try `wp theme list --skip-update-check --force-check`
Then STDERR should contain:
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ public function delete( $args, $assoc_args = array() ) {
*
* [--force-check]
* : Bypass the transient cache and force a fresh update check.
*
*
* [--recently-active]
* : If set, only recently active plugins will be shown and the status filter will be ignored.
*
Expand Down
4 changes: 2 additions & 2 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ static function ( $result ) {
protected function _list( $_, $assoc_args ) {

// If `--force-check` and `--skip-update-check` flags are both present, abort.
if ( true === (bool) Utils\get_flag_value( $assoc_args, 'force-check', false ) and true === (bool) Utils\get_flag_value( $assoc_args, 'skip-update-check', false ) ) {
WP_CLI::error("{$this->item_type} updates cannot be both force-checked and skipped. Choose one.");
if ( true === (bool) Utils\get_flag_value( $assoc_args, 'force-check', false ) && true === (bool) Utils\get_flag_value( $assoc_args, 'skip-update-check', false ) ) {
WP_CLI::error( "{$this->item_type} updates cannot be both force-checked and skipped. Choose one." );
}

// If `--force-check` flag is present, delete the upgrade transient.
Expand Down

0 comments on commit 3c853c9

Please sign in to comment.