Skip to content

Commit 68cb95c

Browse files
committed
Fix tests
1 parent 0f4b688 commit 68cb95c

File tree

4 files changed

+57
-107
lines changed

4 files changed

+57
-107
lines changed

features/plugin-check-update.feature

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,28 @@ Feature: Check for plugin updates
77
When I run `wp plugin install wordpress-importer --activate`
88
Then STDOUT should not be empty
99

10-
When I run `wp plugin check-update`
10+
When I run `wp plugin check-update --all`
1111
Then STDOUT should contain:
1212
"""
1313
Success: All plugins are up to date.
1414
"""
15-
And the return code should be 0
1615

17-
@require-wp-5.2
18-
Scenario: Check for plugin updates with updates available
19-
Given a WP install
16+
When I run `wp plugin check-update wordpress-importer`
17+
Then STDOUT should contain:
18+
"""
19+
Success: All plugins are up to date.
20+
"""
2021

21-
When I run `wp plugin install wordpress-importer --version=0.5 --activate`
22-
Then STDOUT should not be empty
22+
Scenario: Check for plugin updates should throw an error unless --all given
23+
Given a WP install
2324

24-
When I run `wp plugin check-update`
25-
Then STDOUT should be a table containing rows:
26-
| name | status | version |
27-
| wordpress-importer | active | 0.5 |
28-
And STDOUT should contain:
25+
When I try `wp plugin check-update`
26+
Then the return code should be 1
27+
And STDERR should be:
2928
"""
30-
update_version
29+
Error: Please specify one or more plugins, or use --all.
3130
"""
32-
And the return code should be 0
31+
And STDOUT should be empty
3332

3433
@require-wp-5.2
3534
Scenario: Check for specific plugin updates
@@ -38,18 +37,11 @@ Feature: Check for plugin updates
3837
When I run `wp plugin install wordpress-importer --version=0.5`
3938
Then STDOUT should not be empty
4039

41-
When I run `wp plugin install akismet`
42-
Then STDOUT should not be empty
43-
44-
When I run `wp plugin check-update wordpress-importer`
45-
Then STDOUT should be a table containing rows:
46-
| name | status | version |
47-
| wordpress-importer | inactive | 0.5 |
48-
And STDOUT should contain:
40+
When I run `wp plugin check-update wordpress-importer --format=csv`
41+
Then STDOUT should contain:
4942
"""
50-
update_version
43+
wordpress-importer,inactive,0.5,
5144
"""
52-
And the return code should be 0
5345

5446
@require-wp-5.2
5547
Scenario: Check for all plugin updates with --all flag
@@ -58,15 +50,11 @@ Feature: Check for plugin updates
5850
When I run `wp plugin install wordpress-importer --version=0.5 --activate`
5951
Then STDOUT should not be empty
6052

61-
When I run `wp plugin check-update --all`
62-
Then STDOUT should be a table containing rows:
63-
| name | status | version |
64-
| wordpress-importer | active | 0.5 |
65-
And STDOUT should contain:
53+
When I run `wp plugin check-update --all --format=csv`
54+
Then STDOUT should contain:
6655
"""
67-
update_version
56+
wordpress-importer,active,0.5,
6857
"""
69-
And the return code should be 0
7058

7159
@require-wp-5.2
7260
Scenario: Check for plugin updates in different output formats
@@ -75,14 +63,13 @@ Feature: Check for plugin updates
7563
When I run `wp plugin install wordpress-importer --version=0.5`
7664
Then STDOUT should not be empty
7765

78-
When I run `wp plugin check-update --format=json`
66+
When I run `wp plugin check-update wordpress-importer --format=json`
7967
Then STDOUT should be JSON containing:
8068
"""
8169
[{"name":"wordpress-importer","status":"inactive","version":"0.5"}]
8270
"""
83-
And the return code should be 0
8471

85-
When I run `wp plugin check-update --format=csv`
72+
When I run `wp plugin check-update wordpress-importer --format=csv`
8673
Then STDOUT should contain:
8774
"""
8875
name,status,version,update_version
@@ -91,7 +78,6 @@ Feature: Check for plugin updates
9178
"""
9279
wordpress-importer,inactive,0.5
9380
"""
94-
And the return code should be 0
9581

9682
@require-wp-5.2
9783
Scenario: Check for plugin updates with custom fields
@@ -100,22 +86,7 @@ Feature: Check for plugin updates
10086
When I run `wp plugin install wordpress-importer --version=0.5`
10187
Then STDOUT should not be empty
10288

103-
When I run `wp plugin check-update --fields=name,version`
89+
When I run `wp plugin check-update wordpress-importer --fields=name,version`
10490
Then STDOUT should be a table containing rows:
10591
| name | version |
10692
| wordpress-importer | 0.5 |
107-
And the return code should be 0
108-
109-
@require-wp-5.2
110-
Scenario: Check for plugin updates when no specific plugin has updates
111-
Given a WP install
112-
113-
When I run `wp plugin install wordpress-importer`
114-
Then STDOUT should not be empty
115-
116-
When I run `wp plugin check-update wordpress-importer`
117-
Then STDOUT should contain:
118-
"""
119-
Success: All plugins are up to date.
120-
"""
121-
And the return code should be 0

features/theme-check-update.feature

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ Feature: Check for theme updates
66
When I run `wp theme install twentytwelve`
77
Then STDOUT should not be empty
88

9-
When I run `wp theme check-update`
9+
When I run `wp theme check-update --all`
1010
Then STDOUT should contain:
1111
"""
1212
Success: All themes are up to date.
1313
"""
14-
And the return code should be 0
1514

16-
Scenario: Check for theme updates with updates available
17-
Given a WP install
15+
When I run `wp theme check-update twentytwelve`
16+
Then STDOUT should contain:
17+
"""
18+
Success: All themes are up to date.
19+
"""
1820

19-
When I run `wp theme install twentyfourteen --version=1.0`
20-
Then STDOUT should not be empty
21+
Scenario: Check for theme updates should throw an error unless --all given
22+
Given a WP install
2123

22-
When I run `wp theme check-update`
23-
Then STDOUT should be a table containing rows:
24-
| name | status | version |
25-
| twentyfourteen | inactive | 1.0 |
26-
And STDOUT should contain:
24+
When I try `wp theme check-update`
25+
Then the return code should be 1
26+
And STDERR should be:
2727
"""
28-
update_version
28+
Error: Please specify one or more themes, or use --all.
2929
"""
30-
And the return code should be 0
30+
And STDOUT should be empty
3131

3232
Scenario: Check for specific theme updates
3333
Given a WP install
@@ -38,46 +38,37 @@ Feature: Check for theme updates
3838
When I run `wp theme install twentytwelve`
3939
Then STDOUT should not be empty
4040

41-
When I run `wp theme check-update twentyfourteen`
42-
Then STDOUT should be a table containing rows:
43-
| name | status | version |
44-
| twentyfourteen | inactive | 1.0 |
45-
And STDOUT should contain:
41+
When I run `wp theme check-update twentyfourteen --format=csv`
42+
Then STDOUT should contain:
4643
"""
47-
update_version
44+
twentyfourteen,inactive,1.0,
4845
"""
49-
And the return code should be 0
5046

5147
Scenario: Check for all theme updates with --all flag
5248
Given a WP install
5349

5450
When I run `wp theme install twentyfourteen --version=1.0`
5551
Then STDOUT should not be empty
5652

57-
When I run `wp theme check-update --all`
58-
Then STDOUT should be a table containing rows:
59-
| name | status | version |
60-
| twentyfourteen | inactive | 1.0 |
61-
And STDOUT should contain:
53+
When I run `wp theme check-update --all --format=csv`
54+
Then STDOUT should contain:
6255
"""
63-
update_version
56+
twentyfourteen,inactive,1.0,
6457
"""
65-
And the return code should be 0
6658

6759
Scenario: Check for theme updates in different output formats
6860
Given a WP install
6961

7062
When I run `wp theme install twentyfourteen --version=1.0`
7163
Then STDOUT should not be empty
7264

73-
When I run `wp theme check-update --format=json`
65+
When I run `wp theme check-update twentyfourteen --format=json`
7466
Then STDOUT should be JSON containing:
7567
"""
7668
[{"name":"twentyfourteen","status":"inactive","version":"1.0"}]
7769
"""
78-
And the return code should be 0
7970

80-
When I run `wp theme check-update --format=csv`
71+
When I run `wp theme check-update twentyfourteen --format=csv`
8172
Then STDOUT should contain:
8273
"""
8374
name,status,version,update_version
@@ -86,29 +77,14 @@ Feature: Check for theme updates
8677
"""
8778
twentyfourteen,inactive,1.0
8879
"""
89-
And the return code should be 0
9080

9181
Scenario: Check for theme updates with custom fields
9282
Given a WP install
9383

9484
When I run `wp theme install twentyfourteen --version=1.0`
9585
Then STDOUT should not be empty
9686

97-
When I run `wp theme check-update --fields=name,version`
87+
When I run `wp theme check-update twentyfourteen --fields=name,version`
9888
Then STDOUT should be a table containing rows:
9989
| name | version |
10090
| twentyfourteen | 1.0 |
101-
And the return code should be 0
102-
103-
Scenario: Check for theme updates when no specific theme has updates
104-
Given a WP install
105-
106-
When I run `wp theme install twentytwelve`
107-
Then STDOUT should not be empty
108-
109-
When I run `wp theme check-update twentytwelve`
110-
Then STDOUT should contain:
111-
"""
112-
Success: All themes are up to date.
113-
"""
114-
And the return code should be 0

src/Plugin_Command.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ public function status( $args ) {
162162
* @subcommand check-update
163163
*/
164164
public function check_update( $args, $assoc_args ) {
165+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
166+
167+
$args = $this->check_optional_args_and_all( $args, $all );
168+
if ( ! $args ) {
169+
return;
170+
}
171+
165172
// Force WordPress to check for updates.
166173
call_user_func( $this->upgrade_refresh );
167174

src/Theme_Command.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,16 @@ public function status( $args ) {
155155
* @subcommand check-update
156156
*/
157157
public function check_update( $args, $assoc_args ) {
158-
// Force WordPress to check for updates.
159-
call_user_func( $this->upgrade_refresh );
160-
161158
$all = Utils\get_flag_value( $assoc_args, 'all', false );
162159

163-
if ( $all ) {
164-
$args = array_map(
165-
function ( $theme ) {
166-
return $theme->get_stylesheet();
167-
},
168-
$this->get_all_themes()
169-
);
160+
$args = $this->check_optional_args_and_all( $args, $all );
161+
if ( ! $args ) {
162+
return;
170163
}
171164

165+
// Force WordPress to check for updates.
166+
call_user_func( $this->upgrade_refresh );
167+
172168
$items = $this->get_item_list();
173169

174170
// Filter to only themes with available updates

0 commit comments

Comments
 (0)