@@ -29,6 +29,7 @@ Feature: Manage WordPress posts
2929 When I try the previous command again
3030 Then the return code should be 1
3131
32+ Scenario : Setting post categories
3233 When I run `wp term create category "First Category" --porcelain`
3334 And save STDOUT as {TERM_ID}
3435 And I run `wp term create category "Second Category" --porcelain`
@@ -38,19 +39,109 @@ Feature: Manage WordPress posts
3839 Then STDOUT should be a number
3940 And save STDOUT as {POST_ID}
4041
42+ When I run `wp post term list {POST_ID} category --field=term_id`
43+ Then STDOUT should be:
44+ """
45+ {TERM_ID}
46+ """
47+
4148 When I run `wp post update {POST_ID} --post_category={SECOND_TERM_ID}`
4249 Then STDOUT should be:
4350 """
4451 Success: Updated post {POST_ID}.
4552 """
4653
54+ When I run `wp post term list {POST_ID} category --field=term_id`
55+ Then STDOUT should be:
56+ """
57+ {SECOND_TERM_ID}
58+ """
59+
60+ When I run `wp post update {POST_ID} --post_category='Uncategorized,{TERM_ID},Second Category' `
61+ Then STDOUT should be:
62+ """
63+ Success: Updated post {POST_ID}.
64+ """
65+
66+ When I run `wp post term list {POST_ID} category --field=term_id`
67+ And save STDOUT as {MULTI_CATEGORIES_STDOUT}
68+ Then STDOUT should contain:
69+ """
70+ {TERM_ID}
71+ """
72+ And STDOUT should contain:
73+ """
74+ {SECOND_TERM_ID}
75+ """
76+ And STDOUT should contain:
77+ """
78+ 1
79+ """
80+
81+ # Blank categories with non-blank ignored.
82+ When I run `wp post update {POST_ID} --post_category='Uncategorized, ,{TERM_ID},Second Category,' `
83+ Then STDOUT should be:
84+ """
85+ Success: Updated post {POST_ID}.
86+ """
87+
88+ When I run `wp post term list {POST_ID} category --field=term_id`
89+ Then STDOUT should be:
90+ """
91+ {MULTI_CATEGORIES_STDOUT}
92+ """
93+
94+ # Zero category same as default Uncategorized (1) category.
95+ When I try `wp post update {POST_ID} --post_category=0`
96+ Then STDOUT should be:
97+ """
98+ Success: Updated post {POST_ID}.
99+ """
100+
101+ When I run `wp post term list {POST_ID} category --field=term_id`
102+ Then STDOUT should be:
103+ """
104+ 1
105+ """
106+
107+ # Blank category/categories same as default Uncategorized (1) category.
108+ When I try `wp post update {POST_ID} --post_category=,`
109+ Then STDOUT should be:
110+ """
111+ Success: Updated post {POST_ID}.
112+ """
113+
114+ When I run `wp post term list {POST_ID} category --field=term_id`
115+ Then STDOUT should be:
116+ """
117+ 1
118+ """
119+
120+ # Null category same as no categories.
121+ When I try `wp post update {POST_ID} --post_category=' ' `
122+ Then STDOUT should be:
123+ """
124+ Success: Updated post {POST_ID}.
125+ """
126+
127+ When I run `wp post term list {POST_ID} category --field=term_id`
128+ Then STDOUT should be empty
129+
130+ # Non-existent category.
47131 When I try `wp post update {POST_ID} --post_category=test`
48132 Then STDERR should be:
49133 """
50134 Error: No such post category 'test'.
51135 """
52136
53- When I try `wp post create --post_title="Test category two" --post_category={SECOND_TERM_ID},Test --porcelain`
137+ When I try `wp post create --post_title="Non-existent Category" --post_category={SECOND_TERM_ID},Test --porcelain`
138+ Then STDERR should be:
139+ """
140+ Error: No such post category 'Test'.
141+ """
142+
143+ # Error on first non-existent category found.
144+ When I try `wp post create --post_title="More than one non-existent Category" --post_category={SECOND_TERM_ID},Test,Bad --porcelain`
54145 Then STDERR should be:
55146 """
56147 Error: No such post category 'Test'.
0 commit comments