Skip to content

Commit

Permalink
332 Check for destination
Browse files Browse the repository at this point in the history
  • Loading branch information
elenachavdarovasg committed Mar 17, 2023
1 parent 43d5cf8 commit f9fc458
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions features/updatepo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,41 @@ Feature: Update existing PO files from a POT file
msgid "Another new string"
msgstr ""
"""
Scenario: Return error in case of incorrect destination set
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.pot file:
"""
# Copyright (C) 2018 Foo Plugin
# This file is distributed under the same license as the Foo Plugin package.
msgid ""
msgstr ""
"Project-Id-Version: Foo Plugin\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2018-05-02T22:06:24+00:00\n"
"PO-Revision-Date: 2018-05-02T22:06:24+00:00\n"
"X-Domain: foo-plugin\n"
#. translators: New Comment.
#: foo-plugin.php:1
msgid "Some string"
msgstr ""
#: foo-plugin.php:15
msgid "Another new string"
msgstr ""
#: foo-plugin.php:30
msgid "You have %d new message"
msgid_plural "You have %d new messages"
"""
When I run `wp i18n update-po foo-plugin/foo-plugin.pot foo-plugin/test`
Then STDERR should contain:
"""
Error: Destination file/folder does not exist!
"""
And the return code should be 1
4 changes: 4 additions & 0 deletions src/UpdatePoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function __invoke( $args, $assoc_args ) {
$destination = $args[1];
}

if ( ! is_file( $destination ) && ! is_dir( $destination ) ) {
WP_CLI::error( 'Destination file/folder does not exist!' );
}

if ( is_file( $destination ) ) {
$files = [ new SplFileInfo( $destination ) ];
} else {
Expand Down

0 comments on commit f9fc458

Please sign in to comment.