@@ -29,6 +29,124 @@ 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
33+ When I run `wp term create category "First Category" --porcelain`
34+ And save STDOUT as {TERM_ID}
35+ And I run `wp term create category "Second Category" --porcelain`
36+ And save STDOUT as {SECOND_TERM_ID}
37+
38+ When I run `wp post create --post_title="Test category" --post_category="First Category" --porcelain`
39+ Then STDOUT should be a number
40+ And save STDOUT as {POST_ID}
41+
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+
48+ When I run `wp post update {POST_ID} --post_category={SECOND_TERM_ID}`
49+ Then STDOUT should be:
50+ """
51+ Success: Updated post {POST_ID}.
52+ """
53+
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.
131+ When I try `wp post update {POST_ID} --post_category=test`
132+ Then STDERR should be:
133+ """
134+ Error: No such post category 'test'.
135+ """
136+
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`
145+ Then STDERR should be:
146+ """
147+ Error: No such post category 'Test'.
148+ """
149+
32150 Scenario : Creating/getting/editing posts
33151 Given a content.html file:
34152 """
0 commit comments