Skip to:
Content

BuddyPress.org

Ticket #6784: 6784.tests.diff

File 6784.tests.diff, 19.4 KB (added by Mamaduka, 9 years ago)
  • tests/phpunit/testcases/groups/class-bp-groups-group.php

    diff --git tests/phpunit/testcases/groups/class-bp-groups-group.php tests/phpunit/testcases/groups/class-bp-groups-group.php
    index 489fd3c..ebaa63d 100644
    class BP_Tests_BP_Groups_Group_TestCases extends BP_UnitTestCase { 
    10291029
    10301030                $this->set_current_user( $old_user );
    10311031        }
     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        }
    10321371}
    10331372
    10341373/**
  • new file tests/phpunit/testcases/groups/types.php

    diff --git tests/phpunit/testcases/groups/types.php tests/phpunit/testcases/groups/types.php
    new file mode 100644
    index 0000000..a745f32
    - +  
     1<?php
     2
     3/**
     4 * @group groups
     5 * @group group_types
     6 */
     7class BP_Tests_Groups_Types extends BP_UnitTestCase {
     8        protected $u1 = null;
     9
     10        public function setUp() {
     11                parent::setUp();
     12
     13                buddypress()->groups->types = array();
     14
     15                $this->u1 = $this->factory->user->create();
     16        }
     17
     18        public function test_groups_register_type_should_fail_for_existing_group_type() {
     19                bp_groups_register_group_type( 'foo' );
     20                $this->assertWPError( bp_groups_register_group_type( 'foo' ) );
     21        }
     22
     23        /**
     24         * @dataProvider illegal_names
     25         */
     26        public function test_illegal_names( $name ) {
     27                $this->assertWPError( bp_groups_register_group_type( $name ) );
     28        }
     29
     30        public function illegal_names() {
     31                return array(
     32                        array( 'any' ),
     33                        array( 'null' ),
     34                        array( '_none' ),
     35                );
     36        }
     37
     38        public function test_groups_register_type_should_sanitize_group_type_key() {
     39                $key = 'F//oo% -Bar';
     40                $sanitized_key = 'foo-bar';
     41
     42                $object = bp_groups_register_group_type( $key );
     43                $this->assertSame( $sanitized_key, $object->name );
     44        }
     45
     46        public function test_groups_register_type_should_store_group_type_string_as_name_property() {
     47                $object = bp_groups_register_group_type( 'foo' );
     48                $this->assertSame( 'foo', $object->name );
     49        }
     50
     51        public function test_groups_register_type_should_fill_missing_labels_with_ucfirst_group_type() {
     52                $object = bp_groups_register_group_type( 'foo' );
     53                foreach ( $object->labels as $label ) {
     54                        $this->assertSame( 'Foo', $label );
     55                }
     56        }
     57
     58        public function test_groups_register_type_should_respect_custom_name_labels() {
     59                $object = bp_groups_register_group_type( 'foo', array(
     60                        'labels' => array(
     61                                'name' => 'Bar',
     62                        ),
     63                ) );
     64
     65                $this->assertSame( 'Bar', $object->labels['name'] );
     66                $this->assertSame( 'Bar', $object->labels['singular_name'] );
     67        }
     68
     69        public function test_groups_register_type_should_respect_custom_singular_name_labels() {
     70                $object = bp_groups_register_group_type( 'foo', array(
     71                        'labels' => array(
     72                                'singular_name' => 'Bar',
     73                        ),
     74                ) );
     75
     76                $this->assertSame( 'Foo', $object->labels['name'] );
     77                $this->assertSame( 'Bar', $object->labels['singular_name'] );
     78        }
     79
     80        public function test_groups_register_type_has_directory_should_default_to_true() {
     81                $object = bp_groups_register_group_type( 'foo' );
     82
     83                $this->assertTrue( $object->has_directory );
     84                $this->assertSame( 'foo', $object->directory_slug );
     85        }
     86
     87        public function test_groups_register_type_has_directory_true() {
     88                $object = bp_groups_register_group_type( 'foo', array(
     89                        'has_directory' => true,
     90                ) );
     91
     92                $this->assertTrue( $object->has_directory );
     93                $this->assertSame( 'foo', $object->directory_slug );
     94        }
     95
     96        public function test_groups_register_type_has_directory_false() {
     97                $object = bp_groups_register_group_type( 'foo', array(
     98                        'has_directory' => false,
     99                ) );
     100
     101                $this->assertFalse( $object->has_directory );
     102                $this->assertSame( '', $object->directory_slug );
     103        }
     104
     105        public function test_groups_register_type_should_store_has_directory_string() {
     106                $object = bp_groups_register_group_type( 'foo', array(
     107                        'has_directory' => 'foos',
     108                ) );
     109
     110                $this->assertTrue( $object->has_directory );
     111                $this->assertSame( 'foos', $object->directory_slug );
     112        }
     113
     114        public function test_groups_get_type_object_should_return_null_for_non_existing_group_type() {
     115                $this->assertSame( null, bp_groups_get_group_type_object( 'foo' ) );
     116        }
     117
     118        public function test_groups_get_type_object_should_return_type_object() {
     119                bp_groups_register_group_type( 'foo' );
     120                $this->assertInternalType( 'object', bp_groups_register_group_type( 'foo' ) );
     121        }
     122
     123        public function test_groups_set_type_should_return_false_for_invalid_group_type() {
     124                $this->assertFalse( bp_groups_set_group_type( 1, 'foo' ) );
     125        }
     126
     127        public function test_groups_set_type_success() {
     128                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     129                bp_groups_register_group_type( 'foo' );
     130
     131                $this->assertNotEmpty( bp_groups_set_group_type( $g, 'foo' ) );
     132        }
     133
     134        public function test_groups_set_type_should_remove_type_when_passing_an_empty_value() {
     135                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     136                bp_groups_register_group_type( 'foo' );
     137                bp_groups_set_group_type( $g, 'foo' );
     138
     139                // Make sure group type is set.
     140                $this->assertSame( 'foo', bp_groups_get_group_type( $g ) );
     141
     142                $this->assertSame( array(), bp_groups_set_group_type( $g, '' ) );
     143                $this->assertFalse( bp_groups_get_group_type( $g ) );
     144        }
     145
     146        public function test_groups_get_type_with_default_value_for_single() {
     147                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     148                bp_groups_register_group_type( 'foo' );
     149                bp_groups_register_group_type( 'bar' );
     150                bp_groups_set_group_type( $g, 'foo' );
     151                bp_groups_set_group_type( $g, 'bar', true );
     152
     153                $this->assertSame( 'foo', bp_groups_get_group_type( $g ) );
     154        }
     155
     156        public function test_groups_get_type_with_single_true() {
     157                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     158                bp_groups_register_group_type( 'foo' );
     159                bp_groups_register_group_type( 'bar' );
     160                bp_groups_set_group_type( $g, 'foo' );
     161                bp_groups_set_group_type( $g, 'bar', true );
     162
     163                $this->assertSame( 'foo', bp_groups_get_group_type( $g, true ) );
     164        }
     165
     166        public function test_groups_get_type_with_single_false() {
     167                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     168                bp_groups_register_group_type( 'foo' );
     169                bp_groups_register_group_type( 'bar' );
     170                bp_groups_set_group_type( $g, 'foo' );
     171                bp_groups_set_group_type( $g, 'bar', true );
     172
     173                $this->assertEqualSets( array( 'foo', 'bar' ), bp_groups_get_group_type( $g, false ) );
     174        }
     175
     176        public function test_groups_get_type_should_return_false_when_no_value_is_found() {
     177                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     178                bp_groups_register_group_type( 'foo' );
     179
     180                $this->assertFalse( bp_groups_get_group_type( $g ) );
     181        }
     182
     183        public function test_groups_remove_type_should_return_false_when_group_type_is_empty() {
     184                $this->assertFalse( bp_groups_remove_group_type( 9, '' ) );
     185        }
     186
     187        public function test_groups_remove_type_should_return_false_when_group_type_is_invalid() {
     188                $this->assertFalse( bp_groups_remove_group_type( 9, 'foo' ) );
     189        }
     190
     191        public function test_groups_remove_type_should_return_false_when_group_is_not_of_provided_type() {
     192                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     193                bp_groups_register_group_type( 'foo' );
     194                bp_groups_register_group_type( 'bar' );
     195                bp_groups_set_group_type( $g, 'foo' );
     196
     197                $this->assertFalse( bp_groups_remove_group_type( $g, 'bar' ) );
     198                $this->assertEquals( array( 'foo' ), bp_groups_get_group_type( $g, false ) );
     199        }
     200
     201        public function tests_groups_remove_type_should_return_true_on_successful_deletion() {
     202                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     203                bp_groups_register_group_type( 'foo' );
     204                bp_groups_register_group_type( 'bar' );
     205                bp_groups_set_group_type( $g, 'foo' );
     206                bp_groups_set_group_type( $g, 'bar', true );
     207
     208                $this->assertTrue( bp_groups_remove_group_type( $g, 'foo' ) );
     209                $this->assertEquals( array( 'bar' ), bp_groups_get_group_type( $g, false ) );
     210        }
     211
     212        public function test_groups_has_type_should_return_false_when_group_type_is_empty() {
     213                $this->assertFalse( bp_groups_has_group_type( 9, '' ) );
     214        }
     215
     216        public function test_groups_has_type_should_return_false_when_group_type_is_invalid() {
     217                $this->assertFalse( bp_groups_has_group_type( 9, 'foo' ) );
     218        }
     219
     220        public function test_groups_has_type_should_return_false_when_group_id_is_empty() {
     221                bp_groups_register_group_type( 'foo' );
     222
     223                $this->assertFalse( bp_groups_has_group_type( '', 'foo' ) );
     224        }
     225
     226        public function test_groups_has_type_should_return_false_when_group_is_not_of_provided_type() {
     227                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     228                bp_groups_register_group_type( 'foo' );
     229                bp_groups_register_group_type( 'bar' );
     230                bp_groups_set_group_type( $g, 'foo' );
     231
     232                $this->assertFalse( bp_groups_has_group_type( $g, 'bar' ) );
     233        }
     234
     235        public function test_groups_has_type_should_return_true_on_success() {
     236                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     237                bp_groups_register_group_type( 'foo' );
     238                bp_groups_register_group_type( 'bar' );
     239                bp_groups_set_group_type( $g, 'foo' );
     240                bp_groups_set_group_type( $g, 'bar', true );
     241
     242                $this->assertTrue( bp_groups_has_group_type( $g, 'foo' ) );
     243                $this->assertEqualSets( array( 'bar', 'foo' ), bp_groups_get_group_type( $g, false ) );
     244        }
     245
     246        /**
     247         * @group cache
     248         */
     249        public function test_groups_get_type_should_hit_cache() {
     250                $g = $this->factory->group->create( array( 'creator_id' => $this->u1 ) );
     251                bp_groups_register_group_type( 'foo' );
     252                bp_groups_set_group_type( $g, 'foo' );
     253
     254                global $wpdb;
     255
     256                // Initial query. Should hit DB.
     257                bp_groups_get_group_type( $g );
     258                $num_queries = $wpdb->num_queries;
     259
     260                // Next query should hit cache
     261                bp_groups_get_group_type( $g );
     262                $this->assertSame( $num_queries, $wpdb->num_queries );
     263        }
     264}
     265 No newline at end of file