@@ -1041,3 +1041,178 @@ Feature: Manage sites in a multisite installation
10411041 """
10421042 3
10431043 """
1044+
1045+ Scenario : List sites using WP_Site_Query arguments
1046+ Given a WP multisite install
1047+
1048+ When I run `wp site create --slug=alpha --porcelain`
1049+ Then STDOUT should be a number
1050+ And save STDOUT as {ALPHA_ID}
1051+
1052+ When I run `wp site create --slug=beta --porcelain`
1053+ Then STDOUT should be a number
1054+ And save STDOUT as {BETA_ID}
1055+
1056+ # --search, --site__not_in, --number, --offset and --orderby all come from
1057+ # WP_Site_Query and were silently ignored before.
1058+ When I run `wp site list --search=alpha --field=blog_id`
1059+ Then STDOUT should be:
1060+ """
1061+ {ALPHA_ID}
1062+ """
1063+
1064+ When I run `wp site list --site__not_in={ALPHA_ID} --format=count`
1065+ Then STDOUT should be:
1066+ """
1067+ 2
1068+ """
1069+
1070+ When I run `wp site list --number=1 --format=count`
1071+ Then STDOUT should be:
1072+ """
1073+ 1
1074+ """
1075+
1076+ When I run `wp site list --number=1 --offset=1 --field=blog_id`
1077+ Then STDOUT should be:
1078+ """
1079+ {ALPHA_ID}
1080+ """
1081+
1082+ When I run `wp site list --orderby=id --order=desc --field=blog_id`
1083+ Then STDOUT should be:
1084+ """
1085+ {BETA_ID}
1086+ {ALPHA_ID}
1087+ 1
1088+ """
1089+
1090+ Scenario : Existing site list filters keep working against WP_Site_Query
1091+ Given a WP multisite install
1092+
1093+ When I run `wp site create --slug=alpha --porcelain`
1094+ Then STDOUT should be a number
1095+ And save STDOUT as {ALPHA_ID}
1096+
1097+ When I run `wp site create --slug=beta --porcelain`
1098+ Then STDOUT should be a number
1099+ And save STDOUT as {BETA_ID}
1100+
1101+ # --site__in returns rows in the order the IDs were given.
1102+ When I run `wp site list --site__in={BETA_ID},{ALPHA_ID} --field=blog_id`
1103+ Then STDOUT should be:
1104+ """
1105+ {BETA_ID}
1106+ {ALPHA_ID}
1107+ """
1108+
1109+ When I run `wp site list --blog_id={ALPHA_ID} --field=blog_id`
1110+ Then STDOUT should be:
1111+ """
1112+ {ALPHA_ID}
1113+ """
1114+
1115+ When I run `wp site list --site_id=1 --format=count`
1116+ Then STDOUT should be:
1117+ """
1118+ 3
1119+ """
1120+
1121+ When I run `wp site list --site_id=2 --format=count`
1122+ Then STDOUT should be:
1123+ """
1124+ 0
1125+ """
1126+
1127+ When I run `wp site list --site-path=/alpha/ --field=blog_id`
1128+ Then STDOUT should be:
1129+ """
1130+ {ALPHA_ID}
1131+ """
1132+
1133+ # admin belongs to every site, bobby only to the one they were created on, so the
1134+ # two counts differ and neither can pass by accident.
1135+ When I run `wp site list --site_user=admin --format=count`
1136+ Then STDOUT should be:
1137+ """
1138+ 3
1139+ """
1140+
1141+ When I run `wp user create bobby bobby@example.com --role=author --porcelain`
1142+ Then STDOUT should be a number
1143+
1144+ When I run `wp site list --site_user=bobby --field=blog_id`
1145+ Then STDOUT should be:
1146+ """
1147+ 1
1148+ """
1149+
1150+ # --site__in and --site_user narrow each other rather than one replacing the
1151+ # other, so the pair keeps only the sites satisfying both.
1152+ When I run `wp site list --site__in={ALPHA_ID} --site_user=bobby --format=count`
1153+ Then STDOUT should be:
1154+ """
1155+ 0
1156+ """
1157+
1158+ When I run `wp site list --site__in=1,{ALPHA_ID} --site_user=bobby --field=blog_id`
1159+ Then STDOUT should be:
1160+ """
1161+ 1
1162+ """
1163+
1164+ Scenario : Filter the site list by registration or update date
1165+ Given a WP multisite install
1166+
1167+ When I run `wp site create --slug=alpha --porcelain`
1168+ Then STDOUT should be a number
1169+ And save STDOUT as {ALPHA_ID}
1170+
1171+ When I run `wp site list --blog_id={ALPHA_ID} --field=registered`
1172+ Then STDOUT should not be empty
1173+ And save STDOUT as {REGISTERED}
1174+ And save STDOUT '(\d {4}-\d {2}-\d {2})' as {REGISTERED_DAY}
1175+
1176+ When I run `wp site list --registered='{REGISTERED}' --field=blog_id`
1177+ Then STDOUT should contain:
1178+ """
1179+ {ALPHA_ID}
1180+ """
1181+
1182+ # A value carrying no time of day matches every site registered that day, and
1183+ # only those - a day nothing was registered on comes back empty.
1184+ When I run `wp site list --registered={REGISTERED_DAY} --field=blog_id`
1185+ Then STDOUT should contain:
1186+ """
1187+ {ALPHA_ID}
1188+ """
1189+
1190+ When I run `wp site list --registered=1999-01-01 --format=count`
1191+ Then STDOUT should be:
1192+ """
1193+ 0
1194+ """
1195+
1196+ When I run `wp site list --registered='1999-01-01 00:00:00' --format=count`
1197+ Then STDOUT should be:
1198+ """
1199+ 0
1200+ """
1201+
1202+ When I run `wp site list --blog_id={ALPHA_ID} --field=last_updated`
1203+ Then STDOUT should not be empty
1204+ And save STDOUT as {LAST_UPDATED}
1205+
1206+ When I run `wp site list --last_updated='{LAST_UPDATED}' --field=blog_id`
1207+ Then STDOUT should contain:
1208+ """
1209+ {ALPHA_ID}
1210+ """
1211+
1212+ # Interpreting the value is left to WP_Date_Query, which resolves anything it
1213+ # cannot parse to a date no site can have registered on.
1214+ When I run `wp site list --registered=notadate --format=count`
1215+ Then STDOUT should be:
1216+ """
1217+ 0
1218+ """
0 commit comments