| | 1032 | |
| | 1033 | /** |
| | 1034 | * @group group_types |
| | 1035 | */ |
| | 1036 | public function test_group_type_single_value() { |
| | 1037 | $g1 = $this->factory->group->create(); |
| | 1038 | $g2 = $this->factory->group->create(); |
| | 1039 | bp_groups_register_group_type( 'foo' ); |
| | 1040 | bp_groups_register_group_type( 'bar' ); |
| | 1041 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1042 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1043 | |
| | 1044 | $groups = BP_Groups_Group::get( array( |
| | 1045 | 'group_type' => 'foo', |
| | 1046 | ) ); |
| | 1047 | |
| | 1048 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1049 | $this->assertEquals( array( $g1 ), $found ); |
| | 1050 | } |
| | 1051 | |
| | 1052 | /** |
| | 1053 | * @group group_types |
| | 1054 | */ |
| | 1055 | public function test_group_type_array_with_single_value() { |
| | 1056 | $g1 = $this->factory->group->create(); |
| | 1057 | $g2 = $this->factory->group->create(); |
| | 1058 | bp_groups_register_group_type( 'foo' ); |
| | 1059 | bp_groups_register_group_type( 'bar' ); |
| | 1060 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1061 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1062 | |
| | 1063 | $groups = BP_Groups_Group::get( array( |
| | 1064 | 'group_type' => array( 'foo' ), |
| | 1065 | ) ); |
| | 1066 | |
| | 1067 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1068 | $this->assertEquals( array( $g1 ), $found ); |
| | 1069 | } |
| | 1070 | |
| | 1071 | /** |
| | 1072 | * @group group_types |
| | 1073 | */ |
| | 1074 | public function test_group_type_with_comma_separated_list() { |
| | 1075 | $g1 = $this->factory->group->create(); |
| | 1076 | $g2 = $this->factory->group->create(); |
| | 1077 | bp_groups_register_group_type( 'foo' ); |
| | 1078 | bp_groups_register_group_type( 'bar' ); |
| | 1079 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1080 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1081 | |
| | 1082 | $groups = BP_Groups_Group::get( array( |
| | 1083 | 'group_type' => 'foo, bar', |
| | 1084 | ) ); |
| | 1085 | |
| | 1086 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1087 | $this->assertEqualSets( array( $g1, $g2 ), $found ); |
| | 1088 | } |
| | 1089 | |
| | 1090 | /** |
| | 1091 | * @group group_types |
| | 1092 | */ |
| | 1093 | public function test_group_type_array_with_multiple_values() { |
| | 1094 | $g1 = $this->factory->group->create(); |
| | 1095 | $g2 = $this->factory->group->create(); |
| | 1096 | bp_groups_register_group_type( 'foo' ); |
| | 1097 | bp_groups_register_group_type( 'bar' ); |
| | 1098 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1099 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1100 | |
| | 1101 | $groups = BP_Groups_Group::get( array( |
| | 1102 | 'group_type' => array( 'foo', 'bar' ), |
| | 1103 | ) ); |
| | 1104 | |
| | 1105 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1106 | $this->assertEqualSets( array( $g1, $g2 ), $found ); |
| | 1107 | } |
| | 1108 | |
| | 1109 | /** |
| | 1110 | * @group group_types |
| | 1111 | */ |
| | 1112 | public function test_group_type_should_discart_non_existing_types_in_comma_separated_value() { |
| | 1113 | $g1 = $this->factory->group->create(); |
| | 1114 | $g2 = $this->factory->group->create(); |
| | 1115 | bp_groups_register_group_type( 'foo' ); |
| | 1116 | bp_groups_register_group_type( 'bar' ); |
| | 1117 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1118 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1119 | |
| | 1120 | $groups = BP_Groups_Group::get( array( |
| | 1121 | 'group_type' => 'foo, baz', |
| | 1122 | ) ); |
| | 1123 | |
| | 1124 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1125 | $this->assertEquals( array( $g1 ), $found ); |
| | 1126 | } |
| | 1127 | |
| | 1128 | /** |
| | 1129 | * @group group_types |
| | 1130 | */ |
| | 1131 | public function test_group_type_should_return_empty_when_no_groups_match_specified_types() { |
| | 1132 | $g1 = $this->factory->group->create(); |
| | 1133 | $g2 = $this->factory->group->create(); |
| | 1134 | |
| | 1135 | $groups = BP_Groups_Group::get( array( |
| | 1136 | 'group_type' => 'foo, baz', |
| | 1137 | ) ); |
| | 1138 | |
| | 1139 | $this->assertEmpty( $groups['groups'] ); |
| | 1140 | } |
| | 1141 | |
| | 1142 | /** |
| | 1143 | * @group group_types |
| | 1144 | */ |
| | 1145 | public function test_group_type__in_single_value() { |
| | 1146 | $g1 = $this->factory->group->create(); |
| | 1147 | $g2 = $this->factory->group->create(); |
| | 1148 | bp_groups_register_group_type( 'foo' ); |
| | 1149 | bp_groups_register_group_type( 'bar' ); |
| | 1150 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1151 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1152 | |
| | 1153 | $groups = BP_Groups_Group::get( array( |
| | 1154 | 'group_type__in' => 'bar', |
| | 1155 | ) ); |
| | 1156 | |
| | 1157 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1158 | $this->assertEquals( array( $g2 ), $found ); |
| | 1159 | } |
| | 1160 | |
| | 1161 | /** |
| | 1162 | * @group group_types |
| | 1163 | */ |
| | 1164 | public function test_group_type__in_comma_separated_values() { |
| | 1165 | $g1 = $this->factory->group->create(); |
| | 1166 | $g2 = $this->factory->group->create(); |
| | 1167 | bp_groups_register_group_type( 'foo' ); |
| | 1168 | bp_groups_register_group_type( 'bar' ); |
| | 1169 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1170 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1171 | |
| | 1172 | $groups = BP_Groups_Group::get( array( |
| | 1173 | 'group_type__in' => 'foo, bar', |
| | 1174 | ) ); |
| | 1175 | |
| | 1176 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1177 | $this->assertEqualSets( array( $g1, $g2 ), $found ); |
| | 1178 | } |
| | 1179 | |
| | 1180 | /** |
| | 1181 | * @group group_types |
| | 1182 | */ |
| | 1183 | public function test_group_type__in_array_multiple_values() { |
| | 1184 | $g1 = $this->factory->group->create(); |
| | 1185 | $g2 = $this->factory->group->create(); |
| | 1186 | bp_groups_register_group_type( 'foo' ); |
| | 1187 | bp_groups_register_group_type( 'bar' ); |
| | 1188 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1189 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1190 | |
| | 1191 | $groups = BP_Groups_Group::get( array( |
| | 1192 | 'group_type__in' => array( 'foo', 'bar' ), |
| | 1193 | ) ); |
| | 1194 | |
| | 1195 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1196 | $this->assertEqualSets( array( $g1, $g2 ), $found ); |
| | 1197 | } |
| | 1198 | |
| | 1199 | /** |
| | 1200 | * @group group_types |
| | 1201 | */ |
| | 1202 | public function test_group_type__in_array_with_single_value() { |
| | 1203 | $g1 = $this->factory->group->create(); |
| | 1204 | $g2 = $this->factory->group->create(); |
| | 1205 | bp_groups_register_group_type( 'foo' ); |
| | 1206 | bp_groups_register_group_type( 'bar' ); |
| | 1207 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1208 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1209 | |
| | 1210 | $groups = BP_Groups_Group::get( array( |
| | 1211 | 'group_type__in' => array( 'foo' ), |
| | 1212 | ) ); |
| | 1213 | |
| | 1214 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1215 | $this->assertEquals( array( $g1 ), $found ); |
| | 1216 | } |
| | 1217 | |
| | 1218 | /** |
| | 1219 | * @group group_types |
| | 1220 | */ |
| | 1221 | public function test_group_type__in_should_discart_non_existing_types_in_comma_separated_value() { |
| | 1222 | $g1 = $this->factory->group->create(); |
| | 1223 | $g2 = $this->factory->group->create(); |
| | 1224 | bp_groups_register_group_type( 'foo' ); |
| | 1225 | bp_groups_register_group_type( 'bar' ); |
| | 1226 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1227 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1228 | |
| | 1229 | $groups = BP_Groups_Group::get( array( |
| | 1230 | 'group_type__in' => 'foo, baz', |
| | 1231 | ) ); |
| | 1232 | |
| | 1233 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1234 | $this->assertEquals( array( $g1 ), $found ); |
| | 1235 | } |
| | 1236 | |
| | 1237 | /** |
| | 1238 | * @group group_types |
| | 1239 | */ |
| | 1240 | public function test_group_type__in_should_return_empty_when_no_groups_match_specified_types() { |
| | 1241 | $g1 = $this->factory->group->create(); |
| | 1242 | $g2 = $this->factory->group->create(); |
| | 1243 | |
| | 1244 | $groups = BP_Groups_Group::get( array( |
| | 1245 | 'group_type__in' => 'foo, baz', |
| | 1246 | ) ); |
| | 1247 | |
| | 1248 | $this->assertEmpty( $groups['groups'] ); |
| | 1249 | } |
| | 1250 | |
| | 1251 | /** |
| | 1252 | * @group group_types |
| | 1253 | */ |
| | 1254 | public function test_group_type_should_take_precedence_over_group_type__in() { |
| | 1255 | $g1 = $this->factory->group->create(); |
| | 1256 | $g2 = $this->factory->group->create(); |
| | 1257 | bp_groups_register_group_type( 'foo' ); |
| | 1258 | bp_groups_register_group_type( 'bar' ); |
| | 1259 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1260 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1261 | |
| | 1262 | $groups = BP_Groups_Group::get( array( |
| | 1263 | 'group_type__in' => 'foo', |
| | 1264 | 'group_type' => 'bar', |
| | 1265 | ) ); |
| | 1266 | |
| | 1267 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1268 | $this->assertEquals( array( $g2 ), $found ); |
| | 1269 | } |
| | 1270 | |
| | 1271 | /** |
| | 1272 | * @group group_types |
| | 1273 | */ |
| | 1274 | public function test_group_type__not_in_should_return_groups_with_types_and_without_types() { |
| | 1275 | $g1 = $this->factory->group->create(); |
| | 1276 | $g2 = $this->factory->group->create(); |
| | 1277 | $g3 = $this->factory->group->create(); |
| | 1278 | bp_groups_register_group_type( 'foo' ); |
| | 1279 | bp_groups_register_group_type( 'bar' ); |
| | 1280 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1281 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1282 | |
| | 1283 | $groups = BP_Groups_Group::get( array( |
| | 1284 | 'group_type__not_in' => 'foo', |
| | 1285 | ) ); |
| | 1286 | |
| | 1287 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1288 | $this->assertEquals( array( $g2, $g3 ), $found ); |
| | 1289 | } |
| | 1290 | |
| | 1291 | /** |
| | 1292 | * @group group_types |
| | 1293 | */ |
| | 1294 | public function test_group_type__not_in_comma_separated_values() { |
| | 1295 | $g1 = $this->factory->group->create(); |
| | 1296 | $g2 = $this->factory->group->create(); |
| | 1297 | $g3 = $this->factory->group->create(); |
| | 1298 | bp_groups_register_group_type( 'foo' ); |
| | 1299 | bp_groups_register_group_type( 'bar' ); |
| | 1300 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1301 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1302 | bp_groups_set_group_type( $g3, 'baz' ); |
| | 1303 | |
| | 1304 | $groups = BP_Groups_Group::get( array( |
| | 1305 | 'group_type__not_in' => 'foo, bar', |
| | 1306 | ) ); |
| | 1307 | |
| | 1308 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1309 | $this->assertEquals( array( $g3 ), $found ); |
| | 1310 | } |
| | 1311 | |
| | 1312 | /** |
| | 1313 | * @group group_types |
| | 1314 | */ |
| | 1315 | public function test_group_type__not_array_with_multiple_values() { |
| | 1316 | $g1 = $this->factory->group->create(); |
| | 1317 | $g2 = $this->factory->group->create(); |
| | 1318 | $g3 = $this->factory->group->create(); |
| | 1319 | bp_groups_register_group_type( 'foo' ); |
| | 1320 | bp_groups_register_group_type( 'bar' ); |
| | 1321 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1322 | bp_groups_set_group_type( $g2, 'bar' ); |
| | 1323 | bp_groups_set_group_type( $g3, 'baz' ); |
| | 1324 | |
| | 1325 | $groups = BP_Groups_Group::get( array( |
| | 1326 | 'group_type__not_in' => array( 'foo', 'bar' ), |
| | 1327 | ) ); |
| | 1328 | |
| | 1329 | $found = wp_list_pluck( $groups['groups'], 'id' ); |
| | 1330 | $this->assertEquals( array( $g3 ), $found ); |
| | 1331 | } |
| | 1332 | |
| | 1333 | /** |
| | 1334 | * @group group_types |
| | 1335 | */ |
| | 1336 | public function test_group_type__not_in_should_return_no_results_when_all_groups_mathc_sepecified_type() { |
| | 1337 | $g1 = $this->factory->group->create(); |
| | 1338 | $g2 = $this->factory->group->create(); |
| | 1339 | $g3 = $this->factory->group->create(); |
| | 1340 | bp_groups_register_group_type( 'foo' ); |
| | 1341 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1342 | bp_groups_set_group_type( $g2, 'foo' ); |
| | 1343 | bp_groups_set_group_type( $g3, 'foo' ); |
| | 1344 | |
| | 1345 | $groups = BP_Groups_Group::get( array( |
| | 1346 | 'group_type__not_in' => 'foo', |
| | 1347 | ) ); |
| | 1348 | |
| | 1349 | $this->assertEmpty( $groups['groups'] ); |
| | 1350 | } |
| | 1351 | |
| | 1352 | /** |
| | 1353 | * @group group_types |
| | 1354 | */ |
| | 1355 | public function test_group_type__not_in_takes_precedence_over_group_type() { |
| | 1356 | $g1 = $this->factory->group->create(); |
| | 1357 | $g2 = $this->factory->group->create(); |
| | 1358 | $g3 = $this->factory->group->create(); |
| | 1359 | bp_groups_register_group_type( 'foo' ); |
| | 1360 | bp_groups_set_group_type( $g1, 'foo' ); |
| | 1361 | bp_groups_set_group_type( $g2, 'foo' ); |
| | 1362 | bp_groups_set_group_type( $g3, 'foo' ); |
| | 1363 | |
| | 1364 | $groups = BP_Groups_Group::get( array( |
| | 1365 | 'group_type' => 'foo', |
| | 1366 | 'group_type__not_in' => 'foo', |
| | 1367 | ) ); |
| | 1368 | |
| | 1369 | $this->assertEmpty( $groups['groups'] ); |
| | 1370 | } |