Skip to content

Commit bb17c69

Browse files
committed
update post 'create/update'
fix tests
1 parent e077559 commit bb17c69

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

features/post.feature

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,28 @@ Feature: Manage WordPress posts
4444
Success: Updated post {POST_ID}.
4545
"""
4646

47-
When I run `wp post update {POST_ID} --post_category=test --porcelain`
48-
Then STDOUT should be:
47+
When I try `wp post update {POST_ID} --post_category=test`
48+
Then STDERR should be:
4949
"""
5050
Warning: Unable to set test as post category
51+
"""
52+
And STDOUT should be:
53+
"""
5154
Success: Updated post {POST_ID}.
5255
"""
5356

57+
When I try `wp post create --post_title="Test category two" --post_category={SECOND_TERM_ID},Test --porcelain`
58+
Then STDOUT should be a number
59+
And save STDOUT as {POST_ID_TWO}
60+
Then STDERR should be:
61+
"""
62+
Warning: Unable to set Test as post category
63+
"""
64+
And STDOUT should be:
65+
"""
66+
{POST_ID_TWO}
67+
"""
68+
5469
Scenario: Creating/getting/editing posts
5570
Given a content.html file:
5671
"""

src/Post_Command.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -759,14 +759,17 @@ private function get_category_ids( $arg ) {
759759
$categoires = explode( ',', $arg );
760760

761761
foreach ( $categoires as $post_category ) {
762-
$post_category = ( true === is_numeric( $post_category ) ) ? intval( $post_category ) : $post_category;
762+
if ( trim( $post_category ) !== '' ) {
763+
$post_category = ( true === is_numeric( $post_category ) ) ? intval( $post_category ) : $post_category;
763764

764-
$category_id = category_exists( $post_category );
765-
if ( null === $category_id ) {
766-
$category_ids[] = $post_category;
767-
WP_CLI::warning( "Unable to set $post_category as post category" );
768-
} else {
769-
$category_ids[] = $category_id;
765+
$category_id = category_exists( $post_category );
766+
767+
if ( null === $category_id ) {
768+
$category_ids[] = $post_category;
769+
WP_CLI::warning( "Unable to set $post_category as post category" );
770+
} else {
771+
$category_ids[] = $category_id;
772+
}
770773
}
771774
}
772775
return $category_ids;

0 commit comments

Comments
 (0)