@@ -1157,3 +1157,99 @@ Feature: Manage WordPress posts
11571157 2021-02-02
11581158 """
11591159 And STDOUT should not be empty
1160+
1161+ Scenario : List more posts than are loaded from the database at a time
1162+ Given a WP install
1163+ And I run `wp post generate --count=1200 --post_date="2020-01-01 00:00:00" `
1164+ And I run `wp post list --post_status=publish --orderby=ID --order=asc --format=ids`
1165+ And save STDOUT as {IDS}
1166+
1167+ When I run `wp post list --post_status=publish --orderby=ID --order=asc --field=ID | tr '\n ' ' ' | sed 's/ $//' `
1168+ Then STDOUT should be:
1169+ """
1170+ {IDS}
1171+ """
1172+
1173+ When I run `wp post list --post_status=publish --orderby=ID --order=asc --fields=ID,post_title --format=csv | wc -l`
1174+ Then STDOUT should contain:
1175+ """
1176+ 1202
1177+ """
1178+
1179+ When I run `wp post list --post_status=publish --orderby=ID --order=desc --posts_per_page=2 --fields=ID,url --format=csv`
1180+ Then STDOUT should match /^ID,url\n(\d+),https?:\/\/example\.com\/\?p=\1\n(\d+),https?:\/\/example\.com\/\?p=\2$/
1181+
1182+ # An offset that spans more than one chunk must only be applied once.
1183+ When I run `wp post list --post_status=publish --orderby=ID --order=asc --posts_per_page=600 --offset=450 --format=ids`
1184+ Then save STDOUT as {OFFSET_IDS}
1185+
1186+ When I run `wp post list --post_status=publish --orderby=ID --order=asc --posts_per_page=600 --offset=450 --field=ID | tr '\n ' ' ' | sed 's/ $//' `
1187+ Then STDOUT should be:
1188+ """
1189+ {OFFSET_IDS}
1190+ """
1191+
1192+ When I run `wp post list --post_status=publish --orderby=ID --order=asc --posts_per_page=600 --offset=450 --field=ID | wc -l`
1193+ Then STDOUT should contain:
1194+ """
1195+ 600
1196+ """
1197+
1198+ When I run `wp post list --post_status=publish --orderby=ID --order=asc --posts_per_page=600 --paged=2 --format=ids`
1199+ Then save STDOUT as {PAGED_IDS}
1200+
1201+ When I run `wp post list --post_status=publish --orderby=ID --order=asc --posts_per_page=600 --paged=2 --field=ID | tr '\n ' ' ' | sed 's/ $//' `
1202+ Then STDOUT should be:
1203+ """
1204+ {PAGED_IDS}
1205+ """
1206+
1207+ When I run `wp post list --post_status=publish --orderby=ID --order=asc --posts_per_page=600 --paged=2 --field=ID | wc -l`
1208+ Then STDOUT should contain:
1209+ """
1210+ 600
1211+ """
1212+
1213+ Scenario : Sticky posts are not prepended to the post list
1214+ Given a WP install
1215+ And I run `wp post create --post_title=Sticky --post_status=publish --post_date="2020-01-01 00:00:00" --porcelain`
1216+ And save STDOUT as {STICKY}
1217+ And I run `wp option update sticky_posts '[{STICKY}]' --format=json`
1218+ And I run `wp post create --post_title=Draft --post_status=draft --porcelain`
1219+ And save STDOUT as {DRAFT}
1220+ And I run `wp post create --post_title=Latest --post_status=publish --porcelain`
1221+ And save STDOUT as {LATEST}
1222+
1223+ When I run `wp post list --post_status=draft --field=ID`
1224+ Then STDOUT should be:
1225+ """
1226+ {DRAFT}
1227+ """
1228+
1229+ When I run `wp post list --post_status=publish --orderby=ID --order=desc --posts_per_page=1 --field=ID`
1230+ Then STDOUT should be:
1231+ """
1232+ {LATEST}
1233+ """
1234+
1235+ Scenario : List post meta as a field for some posts only
1236+ Given a WP install
1237+ And I run `wp post create --post_title=First --post_status=publish --porcelain`
1238+ And save STDOUT as {FIRST}
1239+ And I run `wp post create --post_title=Second --post_status=publish --porcelain`
1240+ And save STDOUT as {SECOND}
1241+ And I run `wp post meta add {SECOND} batch_meta second-value`
1242+
1243+ When I run `wp post list --post__in={FIRST},{SECOND} --orderby=ID --order=asc --fields=ID,batch_meta --format=csv`
1244+ Then STDOUT should be:
1245+ """
1246+ ID,batch_meta
1247+ {FIRST},
1248+ {SECOND},second-value
1249+ """
1250+
1251+ When I try `wp post list --post__in={FIRST},{SECOND} --fields=ID,missing_meta --format=csv`
1252+ Then STDERR should be:
1253+ """
1254+ Warning: Field not found in any item: missing_meta.
1255+ """
0 commit comments