[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @group bp_user_can 5 */ 6 class BP_Tests_Groups_User_Can_Filter extends BP_UnitTestCase { 7 8 public function test_user_can_join_public_group() { 9 $g1 = $this->factory->group->create( array( 10 'status' => 'public' 11 ) ); 12 $u1 = $this->factory->user->create(); 13 14 $this->assertTrue( bp_user_can( $u1, 'groups_join_group', array( 'group_id' => $g1 ) ) ); 15 } 16 17 public function test_user_cannot_join_public_group_if_already_member() { 18 $g1 = $this->factory->group->create( array( 19 'status' => 'public' 20 ) ); 21 $u1 = $this->factory->user->create(); 22 $this->add_user_to_group( $u1, $g1 ); 23 24 $this->assertFalse( bp_user_can( $u1, 'groups_join_group', array( 'group_id' => $g1 ) ) ); 25 } 26 27 /** 28 * @ticket BP7610 29 */ 30 public function test_user_cannot_join_public_group_if_already_member_even_superadmin() { 31 if ( ! is_multisite() ) { 32 $this->markTestSkipped(); 33 } 34 35 $g1 = $this->factory->group->create( array( 36 'status' => 'public' 37 ) ); 38 $u1 = $this->factory->user->create(); 39 $this->add_user_to_group( $u1, $g1 ); 40 41 // Grant super admin status. 42 grant_super_admin( $u1 ); 43 44 $this->assertFalse( bp_user_can( $u1, 'groups_join_group', array( 'group_id' => $g1 ) ) ); 45 } 46 47 public function test_user_cannot_join_private_group() { 48 $g1 = $this->factory->group->create( array( 49 'status' => 'private' 50 ) ); 51 $u1 = $this->factory->user->create(); 52 53 $this->assertFalse( bp_user_can( $u1, 'groups_join_group', array( 'group_id' => $g1 ) ) ); 54 } 55 56 public function test_user_cannot_join_group_if_banned() { 57 $g1 = $this->factory->group->create( array( 58 'status' => 'public' 59 ) ); 60 $u1 = $this->factory->user->create(); 61 $this->add_user_to_group( $u1, $g1 ); 62 63 buddypress()->is_item_admin = true; 64 groups_ban_member( $u1, $g1 ); 65 66 $this->assertFalse( bp_user_can( $u1, 'groups_join_group', array( 'group_id' => $g1 ) ) ); 67 } 68 69 public function test_user_cannot_request_membership_in_public_group() { 70 $g1 = $this->factory->group->create( array( 71 'status' => 'public' 72 ) ); 73 $u1 = $this->factory->user->create(); 74 75 $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 76 } 77 78 public function test_user_can_request_membership_in_private_group() { 79 $g1 = $this->factory->group->create( array( 80 'status' => 'private' 81 ) ); 82 $u1 = $this->factory->user->create(); 83 84 $this->assertTrue( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 85 } 86 87 public function test_user_cannot_request_membership_in_hidden_group() { 88 $g1 = $this->factory->group->create( array( 89 'status' => 'hidden' 90 ) ); 91 $u1 = $this->factory->user->create(); 92 93 $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 94 } 95 96 public function test_user_cannot_request_membership_in_private_group_if_already_member() { 97 $g1 = $this->factory->group->create( array( 98 'status' => 'private' 99 ) ); 100 $u1 = $this->factory->user->create(); 101 $this->add_user_to_group( $u1, $g1 ); 102 103 $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 104 } 105 106 public function test_user_cannot_request_membership_in_private_group_if_already_requested() { 107 $g1 = $this->factory->group->create( array( 108 'status' => 'private' 109 ) ); 110 $u1 = $this->factory->user->create(); 111 groups_send_membership_request( array( 112 'user_id' => $u1, 113 'group_id' => $g1 114 ) ); 115 116 $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 117 } 118 119 public function test_user_cannot_request_membership_in_private_group_if_banned() { 120 $g1 = $this->factory->group->create( array( 121 'status' => 'private' 122 ) ); 123 $u1 = $this->factory->user->create(); 124 $this->add_user_to_group( $u1, $g1 ); 125 126 buddypress()->is_item_admin = true; 127 groups_ban_member( $u1, $g1 ); 128 129 $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 130 } 131 132 public function test_user_can_receive_invitation_to_private_group() { 133 $g1 = $this->factory->group->create( array( 134 'status' => 'private' 135 ) ); 136 $u1 = $this->factory->user->create(); 137 138 $this->assertTrue( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) ); 139 } 140 141 public function test_user_cannot_receive_invitation_to_private_group_if_already_member() { 142 $g1 = $this->factory->group->create( array( 143 'status' => 'private' 144 ) ); 145 $u1 = $this->factory->user->create(); 146 $this->add_user_to_group( $u1, $g1 ); 147 148 $this->assertFalse( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) ); 149 } 150 151 /** 152 * @ticket BP7610 153 */ 154 public function test_user_cannot_receive_invitation_to_private_group_if_already_member_even_superadmin() { 155 if ( ! is_multisite() ) { 156 $this->markTestSkipped(); 157 } 158 159 $g1 = $this->factory->group->create( array( 160 'status' => 'private' 161 ) ); 162 $u1 = $this->factory->user->create(); 163 $this->add_user_to_group( $u1, $g1 ); 164 165 // Grant super admin status. 166 grant_super_admin( $u1 ); 167 168 $this->assertFalse( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) ); 169 } 170 171 public function test_user_cannot_receive_invitation_to_private_group_if_banned() { 172 $g1 = $this->factory->group->create( array( 173 'status' => 'private' 174 ) ); 175 $u1 = $this->factory->user->create(); 176 $this->add_user_to_group( $u1, $g1 ); 177 178 buddypress()->is_item_admin = true; 179 groups_ban_member( $u1, $g1 ); 180 181 $this->assertFalse( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) ); 182 } 183 184 public function test_user_can_receive_invitation_to_hidden_group() { 185 $g1 = $this->factory->group->create( array( 186 'status' => 'hidden' 187 ) ); 188 $u1 = $this->factory->user->create(); 189 190 $this->assertTrue( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) ); 191 } 192 193 public function test_user_cannot_send_invitation_to_public_group_if_not_a_member() { 194 $g1 = $this->factory->group->create( array( 195 'status' => 'public' 196 ) ); 197 $u1 = $this->factory->user->create(); 198 199 $this->assertFalse( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) ); 200 } 201 202 public function test_user_cannot_send_invitation_to_private_group_if_not_a_member() { 203 $g1 = $this->factory->group->create( array( 204 'status' => 'private' 205 ) ); 206 $u1 = $this->factory->user->create(); 207 208 $this->assertFalse( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) ); 209 } 210 211 public function test_user_cannot_send_invitation_to_private_group_if_banned() { 212 $g1 = $this->factory->group->create( array( 213 'status' => 'private' 214 ) ); 215 groups_update_groupmeta( $g1, 'invite_status', 'members' ); 216 $u1 = $this->factory->user->create(); 217 $this->add_user_to_group( $u1, $g1 ); 218 219 buddypress()->is_item_admin = true; 220 groups_ban_member( $u1, $g1 ); 221 222 $this->assertFalse( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) ); 223 } 224 225 public function test_user_can_send_invitation_to_private_group_if_a_member() { 226 $g1 = $this->factory->group->create( array( 227 'status' => 'private', 228 229 ) ); 230 groups_update_groupmeta( $g1, 'invite_status', 'members' ); 231 $u1 = $this->factory->user->create(); 232 $this->add_user_to_group( $u1, $g1 ); 233 234 $this->assertTrue( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) ); 235 } 236 237 public function test_user_can_send_invitation_to_hidden_group_if_a_member() { 238 $g1 = $this->factory->group->create( array( 239 'status' => 'hidden' 240 ) ); 241 $u1 = $this->factory->user->create(); 242 $u1 = $this->factory->user->create(); 243 $this->add_user_to_group( $u1, $g1 ); 244 245 $this->assertTrue( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) ); 246 } 247 248 public function test_user_can_access_public_group_even_when_not_logged_in() { 249 $g1 = $this->factory->group->create( array( 250 'status' => 'public' 251 ) ); 252 $old_user = get_current_user_id(); 253 $this->set_current_user( 0 ); 254 255 $this->assertTrue( bp_user_can( 0, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 256 257 $this->set_current_user( $old_user ); 258 } 259 260 public function test_user_can_access_public_group_if_not_a_member() { 261 $g1 = $this->factory->group->create( array( 262 'status' => 'public' 263 ) ); 264 $u1 = $this->factory->user->create(); 265 266 $this->assertTrue( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 267 } 268 269 public function test_user_cannot_access_private_group_if_not_logged_in() { 270 $g1 = $this->factory->group->create( array( 271 'status' => 'private' 272 ) ); 273 $old_user = get_current_user_id(); 274 $this->set_current_user( 0 ); 275 276 $this->assertFalse( bp_user_can( 0, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 277 278 $this->set_current_user( $old_user ); 279 } 280 281 public function test_user_cannot_access_private_group_if_not_a_member() { 282 $g1 = $this->factory->group->create( array( 283 'status' => 'private' 284 ) ); 285 $u1 = $this->factory->user->create(); 286 287 $this->assertFalse( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 288 } 289 290 public function test_user_can_access_private_group_if_a_member() { 291 $g1 = $this->factory->group->create( array( 292 'status' => 'private' 293 ) ); 294 $u1 = $this->factory->user->create(); 295 $this->add_user_to_group( $u1, $g1 ); 296 297 $this->assertTrue( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 298 } 299 300 public function test_user_cannot_access_hidden_group_if_not_logged_in() { 301 $g1 = $this->factory->group->create( array( 302 'status' => 'hidden' 303 ) ); 304 $old_user = get_current_user_id(); 305 $this->set_current_user( 0 ); 306 307 $this->assertFalse( bp_user_can( 0, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 308 309 $this->set_current_user( $old_user ); 310 } 311 312 public function test_user_cannot_access_hidden_group_if_not_a_member() { 313 $g1 = $this->factory->group->create( array( 314 'status' => 'hidden' 315 ) ); 316 $u1 = $this->factory->user->create(); 317 318 $this->assertFalse( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 319 } 320 321 public function test_user_can_access_hidden_group_if_a_member() { 322 $g1 = $this->factory->group->create( array( 323 'status' => 'hidden' 324 ) ); 325 $u1 = $this->factory->user->create(); 326 $this->add_user_to_group( $u1, $g1 ); 327 328 $this->assertTrue( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 329 } 330 331 public function test_user_can_see_public_group_even_when_not_logged_in() { 332 $g1 = $this->factory->group->create( array( 333 'status' => 'public' 334 ) ); 335 $old_user = get_current_user_id(); 336 $this->set_current_user( 0 ); 337 338 $this->assertTrue( bp_user_can( 0, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 339 340 $this->set_current_user( $old_user ); 341 } 342 343 public function test_user_can_see_public_group() { 344 $g1 = $this->factory->group->create( array( 345 'status' => 'public' 346 ) ); 347 $u1 = $this->factory->user->create(); 348 349 $this->assertTrue( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 350 } 351 352 public function test_user_can_see_private_group_even_when_not_logged_in() { 353 $g1 = $this->factory->group->create( array( 354 'status' => 'private' 355 ) ); 356 $old_user = get_current_user_id(); 357 $this->set_current_user( 0 ); 358 359 $this->assertTrue( bp_user_can( 0, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 360 361 $this->set_current_user( $old_user ); 362 } 363 364 public function test_user_can_see_private_group() { 365 $g1 = $this->factory->group->create( array( 366 'status' => 'private' 367 ) ); 368 $u1 = $this->factory->user->create(); 369 370 $this->assertTrue( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 371 } 372 373 public function test_user_cannot_see_hidden_group_if_not_logged_in() { 374 $g1 = $this->factory->group->create( array( 375 'status' => 'hidden' 376 ) ); 377 $old_user = get_current_user_id(); 378 $this->set_current_user( 0 ); 379 380 $this->assertFalse( bp_user_can( 0, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 381 382 $this->set_current_user( $old_user ); 383 } 384 385 public function test_user_cannot_see_hidden_group_if_not_a_member() { 386 $g1 = $this->factory->group->create( array( 387 'status' => 'hidden' 388 ) ); 389 $u1 = $this->factory->user->create(); 390 391 $this->assertFalse( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 392 } 393 394 public function test_user_can_see_hidden_group_if_member() { 395 $g1 = $this->factory->group->create( array( 396 'status' => 'hidden' 397 ) ); 398 $u1 = $this->factory->user->create(); 399 $this->add_user_to_group( $u1, $g1 ); 400 401 $this->assertTrue( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 402 } 403 404 /** 405 * @ticket BP7610 406 */ 407 public function test_user_can_groups_request_membership_for_super_admin() { 408 if ( ! is_multisite() ) { 409 $this->markTestSkipped(); 410 } 411 412 $g1 = $this->factory->group->create( array( 413 'status' => 'public' 414 ) ); 415 $u1 = $this->factory->user->create(); 416 $this->add_user_to_group( $u1, $g1 ); 417 418 // Grant super admin status. 419 grant_super_admin( $u1 ); 420 421 // Assert false since public groups shouldn't be able to request membership. 422 $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 423 } 424 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |