Skip to content

Commit 73abc92

Browse files
Copilotswissspidy
andcommitted
Show success message only for summary format and add tests with actual updates
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent e0157bf commit 73abc92

File tree

4 files changed

+124
-13
lines changed

4 files changed

+124
-13
lines changed

features/language-core.feature

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,4 +495,7 @@ Feature: Manage core translation files for a WordPress install
495495

496496
When I run `wp language core update --format=summary`
497497
Then STDOUT should be empty
498-
And STDERR should be empty
498+
And STDERR should contain:
499+
"""
500+
Success: Translations are up to date.
501+
"""

features/language-plugin.feature

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,57 @@ Feature: Manage plugin translation files for a WordPress install
465465

466466
When I run `wp language plugin update --all --format=summary`
467467
Then STDOUT should be empty
468+
And STDERR should contain:
469+
"""
470+
Success: Translations are up to date.
471+
"""
472+
473+
@require-wp-4.0
474+
Scenario: Plugin translation update with format flag and actual updates
475+
Given a WP install
476+
And an empty cache
477+
478+
When I run `wp plugin install akismet --version=3.2 --force`
479+
Then STDERR should be empty
480+
481+
When I run `wp language plugin install akismet de_DE`
482+
Then STDERR should be empty
483+
484+
When I run `wp plugin install akismet --version=4.0 --force`
485+
And I run `wp language plugin list akismet --fields=plugin,language,update,status`
486+
Then STDOUT should be a table containing rows:
487+
| plugin | language | update | status |
488+
| akismet | de_DE | available | installed |
489+
490+
When I run `wp language plugin update akismet --format=json`
491+
Then STDOUT should be JSON containing:
492+
"""
493+
[{"slug":"akismet","language":"de_DE","status":"updated"}]
494+
"""
468495
And STDERR should be empty
496+
497+
When I run `wp plugin install akismet --version=3.2 --force`
498+
And I run `wp language plugin install akismet de_DE --force`
499+
And I run `wp plugin install akismet --version=4.0 --force`
500+
501+
When I run `wp language plugin update akismet --format=csv`
502+
Then STDOUT should contain:
503+
"""
504+
slug,language,status
505+
"""
506+
And STDOUT should contain:
507+
"""
508+
akismet,de_DE,updated
509+
"""
510+
And STDERR should be empty
511+
512+
When I run `wp plugin install akismet --version=3.2 --force`
513+
And I run `wp language plugin install akismet de_DE --force`
514+
And I run `wp plugin install akismet --version=4.0 --force`
515+
516+
When I run `wp language plugin update akismet --format=summary`
517+
Then STDOUT should be empty
518+
And STDERR should contain:
519+
"""
520+
Success: Updated 1/1 translation.
521+
"""

features/language-theme.feature

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,57 @@ Feature: Manage theme translation files for a WordPress install
349349

350350
When I run `wp language theme update --all --format=summary`
351351
Then STDOUT should be empty
352+
And STDERR should contain:
353+
"""
354+
Success: Translations are up to date.
355+
"""
356+
357+
@require-wp-4.0
358+
Scenario: Theme translation update with format flag and actual updates
359+
Given a WP install
360+
And an empty cache
361+
362+
When I run `wp theme install twentyfifteen --version=2.0 --force`
363+
Then STDERR should be empty
364+
365+
When I run `wp language theme install twentyfifteen de_DE`
366+
Then STDERR should be empty
367+
368+
When I run `wp theme install twentyfifteen --version=2.5 --force`
369+
And I run `wp language theme list twentyfifteen --fields=theme,language,update,status`
370+
Then STDOUT should be a table containing rows:
371+
| theme | language | update | status |
372+
| twentyfifteen | de_DE | available | installed |
373+
374+
When I run `wp language theme update twentyfifteen --format=json`
375+
Then STDOUT should be JSON containing:
376+
"""
377+
[{"slug":"twentyfifteen","language":"de_DE","status":"updated"}]
378+
"""
379+
And STDERR should be empty
380+
381+
When I run `wp theme install twentyfifteen --version=2.0 --force`
382+
And I run `wp language theme install twentyfifteen de_DE --force`
383+
And I run `wp theme install twentyfifteen --version=2.5 --force`
384+
385+
When I run `wp language theme update twentyfifteen --format=csv`
386+
Then STDOUT should contain:
387+
"""
388+
slug,language,status
389+
"""
390+
And STDOUT should contain:
391+
"""
392+
twentyfifteen,de_DE,updated
393+
"""
352394
And STDERR should be empty
395+
396+
When I run `wp theme install twentyfifteen --version=2.0 --force`
397+
And I run `wp language theme install twentyfifteen de_DE --force`
398+
And I run `wp theme install twentyfifteen --version=2.5 --force`
399+
400+
When I run `wp language theme update twentyfifteen --format=summary`
401+
Then STDOUT should be empty
402+
And STDERR should contain:
403+
"""
404+
Success: Updated 1/1 translation.
405+
"""

src/WP_CLI/CommandWithTranslation.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public function update( $args, $assoc_args ) {
3333
$format = Utils\get_flag_value( $assoc_args, 'format' );
3434

3535
if ( empty( $updates ) ) {
36-
if ( $format ) {
37-
if ( in_array( $format, array( 'json', 'csv' ), true ) ) {
38-
Utils\format_items( $format, array(), array() );
39-
}
40-
} else {
36+
if ( $format && in_array( $format, array( 'json', 'csv' ), true ) ) {
37+
Utils\format_items( $format, array(), array() );
38+
}
39+
40+
if ( ! $format || 'summary' === $format ) {
4141
WP_CLI::success( 'Translations are up to date.' );
4242
}
4343

@@ -174,14 +174,16 @@ public function update( $args, $assoc_args ) {
174174
Utils\format_items( $format, $results_data, array( $slug_key, 'language', 'status' ) );
175175
}
176176

177-
$line = sprintf( "Updated $num_updated/$num_to_update %s.", WP_CLI\Utils\pluralize( 'translation', $num_updated ) );
177+
if ( ! $format || 'summary' === $format ) {
178+
$line = sprintf( "Updated $num_updated/$num_to_update %s.", WP_CLI\Utils\pluralize( 'translation', $num_updated ) );
178179

179-
if ( $num_to_update === $num_updated ) {
180-
WP_CLI::success( $line );
181-
} elseif ( $num_updated > 0 ) {
182-
WP_CLI::warning( $line );
183-
} else {
184-
WP_CLI::error( $line );
180+
if ( $num_to_update === $num_updated ) {
181+
WP_CLI::success( $line );
182+
} elseif ( $num_updated > 0 ) {
183+
WP_CLI::warning( $line );
184+
} else {
185+
WP_CLI::error( $line );
186+
}
185187
}
186188
}
187189

0 commit comments

Comments
 (0)