Skip to content

Commit 0b52cb5

Browse files
committed
update post 'create/update'
update code according to review and modify tests
1 parent bb17c69 commit 0b52cb5

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

features/post.feature

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,13 @@ Feature: Manage WordPress posts
4747
When I try `wp post update {POST_ID} --post_category=test`
4848
Then STDERR should be:
4949
"""
50-
Warning: Unable to set test as post category
51-
"""
52-
And STDOUT should be:
53-
"""
54-
Success: Updated post {POST_ID}.
50+
Error: No such post category 'test'.
5551
"""
5652

5753
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}
6054
Then STDERR should be:
6155
"""
62-
Warning: Unable to set Test as post category
63-
"""
64-
And STDOUT should be:
65-
"""
66-
{POST_ID_TWO}
56+
Error: No such post category 'Test'.
6757
"""
6858

6959
Scenario: Creating/getting/editing posts

src/Post_Command.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,13 +760,14 @@ private function get_category_ids( $arg ) {
760760

761761
foreach ( $categoires as $post_category ) {
762762
if ( trim( $post_category ) !== '' ) {
763-
$post_category = ( true === is_numeric( $post_category ) ) ? intval( $post_category ) : $post_category;
764-
765-
$category_id = category_exists( $post_category );
766-
767-
if ( null === $category_id ) {
763+
if ( is_numeric( $post_category ) && (int) $post_category ) {
764+
$category_id = category_exists( (int) $post_category );
765+
} else {
766+
$category_id = category_exists( $post_category );
767+
}
768+
if ( ! $category_id ) {
768769
$category_ids[] = $post_category;
769-
WP_CLI::warning( "Unable to set $post_category as post category" );
770+
WP_CLI::error( "No such post category '$post_category'." );
770771
} else {
771772
$category_ids[] = $category_id;
772773
}

0 commit comments

Comments
 (0)