@@ -936,3 +936,283 @@ Feature: Manage sites in a multisite installation
936936 """
937937 1
938938 """
939+
940+ Scenario : Filter the site list by columns of the sites table
941+ Given a WP multisite install
942+
943+ When I run `wp site create --slug=first --porcelain`
944+ Then STDOUT should be a number
945+ And save STDOUT as {FIRST_ID}
946+
947+ When I run `wp site create --slug=second --porcelain`
948+ Then STDOUT should be a number
949+ And save STDOUT as {SECOND_ID}
950+
951+ # Give the two new sites contrasting statuses, so each filter below has
952+ # something to discriminate on and cannot pass by matching every site.
953+ When I run `wp site archive {FIRST_ID}`
954+ Then STDOUT should contain:
955+ """
956+ Success:
957+ """
958+
959+ When I run `wp site private {SECOND_ID}`
960+ Then STDOUT should contain:
961+ """
962+ Success:
963+ """
964+
965+ When I run `wp site spam {SECOND_ID}`
966+ Then STDOUT should contain:
967+ """
968+ Success:
969+ """
970+
971+ When I run `wp site list --format=count`
972+ Then STDOUT should be:
973+ """
974+ 3
975+ """
976+
977+ When I run `wp site list --archived=1 --field=blog_id`
978+ Then STDOUT should be:
979+ """
980+ {FIRST_ID}
981+ """
982+
983+ When I run `wp site list --archived=0 --format=count`
984+ Then STDOUT should be:
985+ """
986+ 2
987+ """
988+
989+ When I run `wp site list --public=0 --field=blog_id`
990+ Then STDOUT should be:
991+ """
992+ {SECOND_ID}
993+ """
994+
995+ When I run `wp site list --public=1 --format=count`
996+ Then STDOUT should be:
997+ """
998+ 2
999+ """
1000+
1001+ When I run `wp site list --spam=1 --field=blog_id`
1002+ Then STDOUT should be:
1003+ """
1004+ {SECOND_ID}
1005+ """
1006+
1007+ When I run `wp site list --spam=0 --format=count`
1008+ Then STDOUT should be:
1009+ """
1010+ 2
1011+ """
1012+
1013+ When I run `wp site list --deleted=0 --format=count`
1014+ Then STDOUT should be:
1015+ """
1016+ 3
1017+ """
1018+
1019+ When I run `wp site list --blog_id={FIRST_ID} --field=blog_id`
1020+ Then STDOUT should be:
1021+ """
1022+ {FIRST_ID}
1023+ """
1024+
1025+ # site_id is the ID of the network the site belongs to, not the site's own ID.
1026+ When I run `wp site list --site_id=1 --format=count`
1027+ Then STDOUT should be:
1028+ """
1029+ 3
1030+ """
1031+
1032+ When I run `wp site list --site_id=2 --format=count`
1033+ Then STDOUT should be:
1034+ """
1035+ 0
1036+ """
1037+
1038+ # --network is an alias for site_id and takes precedence over it.
1039+ When I run `wp site list --site_id=2 --network=1 --format=count`
1040+ Then STDOUT should be:
1041+ """
1042+ 3
1043+ """
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