Ticket #7610: 7610.02.diff
File 7610.02.diff, 23.8 KB (added by , 7 years ago) |
---|
-
src/bp-forums/bp-forums-screens.php
diff --git src/bp-forums/bp-forums-screens.php src/bp-forums/bp-forums-screens.php index 7b8a43553..6cf4bbafb 100644
function bp_forums_directory_forums_setup() { 45 45 $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ); 46 46 if ( !empty( $bp->groups->current_group->id ) ) { 47 47 // Auto join this user if they are not yet a member of this group. 48 if ( ! bp_current_user_can( 'bp_moderate' ) && 'public' == $bp->groups->current_group->status && !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id) )48 if ( ! bp_current_user_can( 'bp_moderate' ) && bp_current_user_can( 'groups_join_group', array( 'group_id' => $bp->groups->current_group->id ) ) ) 49 49 groups_join_group( $bp->groups->current_group->id ); 50 50 51 51 $error_message = ''; -
src/bp-groups/bp-groups-actions.php
diff --git src/bp-groups/bp-groups-actions.php src/bp-groups/bp-groups-actions.php index 4f804955f..e1ff5a266 100644
function groups_action_join_group() { 423 423 if ( !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) && !groups_is_user_banned( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 424 424 425 425 // User wants to join a group that is not public. 426 if ( $bp->groups->current_group->status != 'public') {426 if ( bp_current_user_can( 'groups_join_group', array( 'group_id' => $bp->groups->current_group->id ) ) ) { 427 427 if ( !groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 428 428 bp_core_add_message( __( 'There was an error joining the group.', 'buddypress' ), 'error' ); 429 429 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); -
src/bp-groups/bp-groups-filters.php
diff --git src/bp-groups/bp-groups-filters.php src/bp-groups/bp-groups-filters.php index 107175975..172f339e6 100644
function bp_groups_disable_at_mention_notification_for_non_public_groups( $send, 313 313 return $send; 314 314 } 315 315 316 if ( 'groups' === $activity->component ) { 317 $group = groups_get_group( $activity->item_id ); 318 if ( 'public' !== $group->status && ! groups_is_user_member( $user_id, $group->id ) ) { 319 $send = false; 320 } 316 if ( 'groups' === $activity->component && ! bp_user_can( $user_id, 'groups_access_group', array( 'group_id' => $activity->item_id ) ) ) { 317 $send = false; 321 318 } 322 319 323 320 return $send; … … function bp_groups_default_avatar( $avatar, $params ) { 345 342 346 343 return $avatar; 347 344 } 345 346 /** 347 * Filter the bp_user_can value to determine what the user can do 348 * with regards to a specific group. 349 * 350 * @since 3.0.0 351 * 352 * @param bool $retval Whether or not the current user has the capability. 353 * @param int $user_id 354 * @param string $capability The capability being checked for. 355 * @param int $site_id Site ID. Defaults to the BP root blog. 356 * @param array $args Array of extra arguments passed. 357 * 358 * @return bool 359 */ 360 function bp_groups_user_can_filter( $retval, $user_id, $capability, $site_id, $args ) { 361 if ( empty( $args['group_id'] ) ) { 362 $group_id = bp_get_current_group_id(); 363 } else { 364 $group_id = (int) $args['group_id']; 365 } 366 367 switch ( $capability ) { 368 case 'groups_join_group': 369 // Return early if the user isn't logged in or the group ID is unknown. 370 if ( ! $user_id || ! $group_id ) { 371 break; 372 } 373 374 // The group must allow joining, and the user should not currently be a member. 375 $group = groups_get_group( $group_id ); 376 if ( 'public' === bp_get_group_status( $group ) 377 && ! groups_is_user_member( $user_id, $group->id ) 378 && ! groups_is_user_banned( $user_id, $group->id ) 379 ) { 380 $retval = true; 381 } 382 break; 383 384 case 'groups_request_membership': 385 // Return early if the user isn't logged in or the group ID is unknown. 386 if ( ! $user_id || ! $group_id ) { 387 break; 388 } 389 390 /* 391 * The group must accept membership requests, and the user should not 392 * currently be a member, have an active request, or be banned. 393 */ 394 $group = groups_get_group( $group_id ); 395 if ( 'private' === bp_get_group_status( $group ) 396 && ! groups_is_user_member( $user_id, $group->id ) 397 && ! groups_check_for_membership_request( $user_id, $group->id ) 398 && ! groups_is_user_banned( $user_id, $group->id ) 399 ) { 400 $retval = true; 401 } 402 break; 403 404 case 'groups_send_invitation': 405 // Return early if the user isn't logged in or the group ID is unknown. 406 if ( ! $user_id || ! $group_id ) { 407 break; 408 } 409 410 /* 411 * The group must allow invitations, and the user should not 412 * currently be a member or be banned from the group. 413 */ 414 $group = groups_get_group( $group_id ); 415 // Users with the 'bp_moderate' cap can always send invitations. 416 if ( bp_user_can( $user_id, 'bp_moderate' ) ) { 417 $retval = true; 418 } else { 419 $invite_status = bp_group_get_invite_status( $group_id ); 420 421 switch ( $invite_status ) { 422 case 'admins' : 423 if ( groups_is_user_admin( $user_id, $group_id ) ) { 424 $retval = true; 425 } 426 break; 427 428 case 'mods' : 429 if ( groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) ) { 430 $retval = true; 431 } 432 break; 433 434 case 'members' : 435 if ( groups_is_user_member( $user_id, $group_id ) ) { 436 $retval = true; 437 } 438 break; 439 } 440 } 441 break; 442 443 case 'groups_receive_invitation': 444 // Return early if the user isn't logged in or the group ID is unknown. 445 if ( ! $user_id || ! $group_id ) { 446 break; 447 } 448 449 /* 450 * The group must allow invitations, and the user should not 451 * currently be a member or be banned from the group. 452 */ 453 $group = groups_get_group( $group_id ); 454 if ( in_array( bp_get_group_status( $group ), array( 'private', 'hidden' ), true ) 455 && ! groups_is_user_member( $user_id, $group->id ) 456 && ! groups_is_user_banned( $user_id, $group->id ) 457 ) { 458 $retval = true; 459 } 460 break; 461 462 case 'groups_access_group': 463 // Return early if the group ID is unknown. 464 if ( ! $group_id ) { 465 break; 466 } 467 468 $group = groups_get_group( $group_id ); 469 470 // If the check is for the logged-in user, use the BP_Groups_Group property. 471 if ( $user_id === bp_loggedin_user_id() ) { 472 $retval = $group->user_has_access; 473 474 /* 475 * If the check is for a specified user who is not the logged-in user 476 * run the check manually. 477 */ 478 } elseif ( 'public' === bp_get_group_status( $group ) || groups_is_user_member( $user_id, $group->id ) ) { 479 $retval = true; 480 } 481 break; 482 483 case 'groups_see_group': 484 // Return early if the group ID is unknown. 485 if ( ! $group_id ) { 486 break; 487 } 488 489 $group = groups_get_group( $group_id ); 490 491 // If the check is for the logged-in user, use the BP_Groups_Group property. 492 if ( $user_id === bp_loggedin_user_id() ) { 493 $retval = $group->is_visible; 494 495 /* 496 * If the check is for a specified user who is not the logged-in user 497 * run the check manually. 498 */ 499 } elseif ( 'hidden' !== bp_get_group_status( $group ) || groups_is_user_member( $user_id, $group->id ) ) { 500 $retval = true; 501 } 502 break; 503 } 504 505 return $retval; 506 507 } 508 add_filter( 'bp_user_can', 'bp_groups_user_can_filter', 10, 5 ); -
src/bp-groups/bp-groups-template.php
diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php index ac0d31568..77a8a934d 100644
function bp_groups_user_can_send_invites( $group_id = 0, $user_id = 0 ) { 2357 2357 } 2358 2358 2359 2359 if ( $user_id ) { 2360 // Users with the 'bp_moderate' cap can always send invitations. 2361 if ( bp_user_can( $user_id, 'bp_moderate' ) ) { 2362 $can_send_invites = true; 2363 } else { 2364 $invite_status = bp_group_get_invite_status( $group_id ); 2365 2366 switch ( $invite_status ) { 2367 case 'admins' : 2368 if ( groups_is_user_admin( $user_id, $group_id ) ) { 2369 $can_send_invites = true; 2370 } 2371 break; 2372 2373 case 'mods' : 2374 if ( groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) ) { 2375 $can_send_invites = true; 2376 } 2377 break; 2378 2379 case 'members' : 2380 if ( groups_is_user_member( $user_id, $group_id ) ) { 2381 $can_send_invites = true; 2382 } 2383 break; 2384 } 2385 } 2360 $can_send_invites = bp_user_can( $user_id, 'groups_send_invitation', array( 'group_id' => $group_id ) ); 2386 2361 } 2387 2362 2388 2363 /** -
src/bp-groups/classes/class-bp-groups-component.php
diff --git src/bp-groups/classes/class-bp-groups-component.php src/bp-groups/classes/class-bp-groups-component.php index fc81d045a..3e4c09250 100644
class BP_Groups_Component extends BP_Component { 544 544 // If this is a private group, and the user is not a 545 545 // member and does not have an outstanding invitation, 546 546 // show a "Request Membership" nav item. 547 if ( is_user_logged_in() && 548 ! $this->current_group->is_member && 549 ! groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) && 550 $this->current_group->status == 'private' && 551 ! groups_check_user_has_invite( bp_loggedin_user_id(), $this->current_group->id ) 552 ) { 547 if ( bp_current_user_can( 'groups_request_membership', array( 'group_id' => $this->current_group->id ) ) ) { 553 548 554 549 $sub_nav[] = array( 555 550 'name' => _x( 'Request Membership','Group screen nav', 'buddypress' ), -
src/bp-templates/bp-legacy/buddypress-functions.php
diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php index 621eacd4c..13d2663e2 100644
function bp_legacy_theme_ajax_joinleave_group() { 1492 1492 return; 1493 1493 1494 1494 if ( ! groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) { 1495 if ( 'public' == $group->status) {1495 if ( bp_current_user_can( 'groups_join_group', array( 'group_id' => $group->id ) ) ) { 1496 1496 check_ajax_referer( 'groups_join_group' ); 1497 1497 1498 1498 if ( ! groups_join_group( $group->id ) ) { … … function bp_legacy_theme_ajax_joinleave_group() { 1501 1501 echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button leave-group" rel="leave" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>'; 1502 1502 } 1503 1503 1504 } elseif ( 'private' == $group->status) {1504 } elseif ( bp_current_user_can( 'groups_request_membership', array( 'group_id' => $group->id ) ) ) { 1505 1505 1506 1506 // If the user has already been invited, then this is 1507 1507 // an Accept Invitation button. … … function bp_legacy_theme_ajax_joinleave_group() { 1531 1531 1532 1532 if ( ! groups_leave_group( $group->id ) ) { 1533 1533 _e( 'Error leaving group', 'buddypress' ); 1534 } elseif ( 'public' == $group->status) {1534 } elseif ( bp_current_user_can( 'groups_join_group', array( 'group_id' => $group->id ) ) ) { 1535 1535 echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button join-group" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>'; 1536 } elseif ( 'private' == $group->status) {1536 } elseif ( bp_current_user_can( 'groups_request_membership', array( 'group_id' => $group->id ) ) ) { 1537 1537 echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button request-membership" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ) . '">' . __( 'Request Membership', 'buddypress' ) . '</a>'; 1538 1538 } 1539 1539 } -
new file tests/phpunit/testcases/groups/user_can.php
diff --git tests/phpunit/testcases/groups/user_can.php tests/phpunit/testcases/groups/user_can.php new file mode 100644 index 000000000..19df3a0d9
- + 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 public function test_user_cannot_join_private_group() { 28 $g1 = $this->factory->group->create( array( 29 'status' => 'private' 30 ) ); 31 $u1 = $this->factory->user->create(); 32 33 $this->assertFalse( bp_user_can( $u1, 'groups_join_group', array( 'group_id' => $g1 ) ) ); 34 } 35 36 public function test_user_cannot_join_group_if_banned() { 37 $g1 = $this->factory->group->create( array( 38 'status' => 'public' 39 ) ); 40 $u1 = $this->factory->user->create(); 41 $this->add_user_to_group( $u1, $g1 ); 42 43 buddypress()->is_item_admin = true; 44 groups_ban_member( $u1, $g1 ); 45 46 $this->assertFalse( bp_user_can( $u1, 'groups_join_group', array( 'group_id' => $g1 ) ) ); 47 } 48 49 public function test_user_cannot_request_membership_in_public_group() { 50 $g1 = $this->factory->group->create( array( 51 'status' => 'public' 52 ) ); 53 $u1 = $this->factory->user->create(); 54 55 $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 56 } 57 58 public function test_user_can_request_membership_in_private_group() { 59 $g1 = $this->factory->group->create( array( 60 'status' => 'private' 61 ) ); 62 $u1 = $this->factory->user->create(); 63 64 $this->assertTrue( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 65 } 66 67 public function test_user_cannot_request_membership_in_hidden_group() { 68 $g1 = $this->factory->group->create( array( 69 'status' => 'hidden' 70 ) ); 71 $u1 = $this->factory->user->create(); 72 73 $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 74 } 75 76 public function test_user_cannot_request_membership_in_private_group_if_already_member() { 77 $g1 = $this->factory->group->create( array( 78 'status' => 'private' 79 ) ); 80 $u1 = $this->factory->user->create(); 81 $this->add_user_to_group( $u1, $g1 ); 82 83 $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 84 } 85 86 public function test_user_cannot_request_membership_in_private_group_if_already_requested() { 87 $g1 = $this->factory->group->create( array( 88 'status' => 'private' 89 ) ); 90 $u1 = $this->factory->user->create(); 91 groups_send_membership_request( $u1, $g1 ); 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_banned() { 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 buddypress()->is_item_admin = true; 104 groups_ban_member( $u1, $g1 ); 105 106 $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) ); 107 } 108 109 public function test_user_cannot_receive_invitation_to_public_group() { 110 $g1 = $this->factory->group->create( array( 111 'status' => 'public' 112 ) ); 113 $u1 = $this->factory->user->create(); 114 115 $this->assertFalse( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) ); 116 } 117 118 public function test_user_can_receive_invitation_to_private_group() { 119 $g1 = $this->factory->group->create( array( 120 'status' => 'private' 121 ) ); 122 $u1 = $this->factory->user->create(); 123 124 $this->assertTrue( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) ); 125 } 126 127 public function test_user_cannot_receive_invitation_to_private_group_if_already_member() { 128 $g1 = $this->factory->group->create( array( 129 'status' => 'private' 130 ) ); 131 $u1 = $this->factory->user->create(); 132 $this->add_user_to_group( $u1, $g1 ); 133 134 $this->assertFalse( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) ); 135 } 136 137 138 public function test_user_cannot_receive_invitation_to_private_group_if_banned() { 139 $g1 = $this->factory->group->create( array( 140 'status' => 'private' 141 ) ); 142 $u1 = $this->factory->user->create(); 143 $this->add_user_to_group( $u1, $g1 ); 144 145 buddypress()->is_item_admin = true; 146 groups_ban_member( $u1, $g1 ); 147 148 $this->assertFalse( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) ); 149 } 150 151 public function test_user_can_receive_invitation_to_hidden_group() { 152 $g1 = $this->factory->group->create( array( 153 'status' => 'hidden' 154 ) ); 155 $u1 = $this->factory->user->create(); 156 157 $this->assertTrue( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) ); 158 } 159 160 public function test_user_cannot_send_invitation_to_public_group_if_not_a_member() { 161 $g1 = $this->factory->group->create( array( 162 'status' => 'public' 163 ) ); 164 $u1 = $this->factory->user->create(); 165 166 $this->assertFalse( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) ); 167 } 168 169 public function test_user_cannot_send_invitation_to_private_group_if_not_a_member() { 170 $g1 = $this->factory->group->create( array( 171 'status' => 'private' 172 ) ); 173 $u1 = $this->factory->user->create(); 174 175 $this->assertFalse( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) ); 176 } 177 178 public function test_user_cannot_send_invitation_to_private_group_if_banned() { 179 $g1 = $this->factory->group->create( array( 180 'status' => 'private' 181 ) ); 182 groups_update_groupmeta( $g1, 'invite_status', 'members' ); 183 $u1 = $this->factory->user->create(); 184 $this->add_user_to_group( $u1, $g1 ); 185 186 buddypress()->is_item_admin = true; 187 groups_ban_member( $u1, $g1 ); 188 189 $this->assertFalse( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) ); 190 } 191 192 public function test_user_can_send_invitation_to_private_group_if_a_member() { 193 $g1 = $this->factory->group->create( array( 194 'status' => 'private', 195 196 ) ); 197 groups_update_groupmeta( $g1, 'invite_status', 'members' ); 198 $u1 = $this->factory->user->create(); 199 $this->add_user_to_group( $u1, $g1 ); 200 201 $this->assertTrue( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) ); 202 } 203 204 public function test_user_can_send_invitation_to_hidden_group_if_a_member() { 205 $g1 = $this->factory->group->create( array( 206 'status' => 'hidden' 207 ) ); 208 $u1 = $this->factory->user->create(); 209 $u1 = $this->factory->user->create(); 210 $this->add_user_to_group( $u1, $g1 ); 211 212 $this->assertTrue( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) ); 213 } 214 215 public function test_user_can_access_public_group_even_when_not_logged_in() { 216 $g1 = $this->factory->group->create( array( 217 'status' => 'public' 218 ) ); 219 $old_user = get_current_user_id(); 220 $this->set_current_user( 0 ); 221 222 $this->assertTrue( bp_user_can( 0, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 223 224 $this->set_current_user( $old_user ); 225 } 226 227 public function test_user_can_access_public_group_if_not_a_member() { 228 $g1 = $this->factory->group->create( array( 229 'status' => 'public' 230 ) ); 231 $u1 = $this->factory->user->create(); 232 233 $this->assertTrue( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 234 } 235 236 public function test_user_cannot_access_private_group_if_not_logged_in() { 237 $g1 = $this->factory->group->create( array( 238 'status' => 'private' 239 ) ); 240 $old_user = get_current_user_id(); 241 $this->set_current_user( 0 ); 242 243 $this->assertFalse( bp_user_can( 0, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 244 245 $this->set_current_user( $old_user ); 246 } 247 248 public function test_user_cannot_access_private_group_if_not_a_member() { 249 $g1 = $this->factory->group->create( array( 250 'status' => 'private' 251 ) ); 252 $u1 = $this->factory->user->create(); 253 254 $this->assertFalse( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 255 } 256 257 public function test_user_can_access_private_group_if_a_member() { 258 $g1 = $this->factory->group->create( array( 259 'status' => 'private' 260 ) ); 261 $u1 = $this->factory->user->create(); 262 $this->add_user_to_group( $u1, $g1 ); 263 264 $this->assertTrue( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 265 } 266 267 public function test_user_cannot_access_hidden_group_if_not_logged_in() { 268 $g1 = $this->factory->group->create( array( 269 'status' => 'hidden' 270 ) ); 271 $old_user = get_current_user_id(); 272 $this->set_current_user( 0 ); 273 274 $this->assertFalse( bp_user_can( 0, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 275 276 $this->set_current_user( $old_user ); 277 } 278 279 public function test_user_cannot_access_hidden_group_if_not_a_member() { 280 $g1 = $this->factory->group->create( array( 281 'status' => 'hidden' 282 ) ); 283 $u1 = $this->factory->user->create(); 284 285 $this->assertFalse( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 286 } 287 288 public function test_user_can_access_hidden_group_if_a_member() { 289 $g1 = $this->factory->group->create( array( 290 'status' => 'hidden' 291 ) ); 292 $u1 = $this->factory->user->create(); 293 $this->add_user_to_group( $u1, $g1 ); 294 295 $this->assertTrue( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) ); 296 } 297 298 public function test_user_can_see_public_group_even_when_not_logged_in() { 299 $g1 = $this->factory->group->create( array( 300 'status' => 'public' 301 ) ); 302 $old_user = get_current_user_id(); 303 $this->set_current_user( 0 ); 304 305 $this->assertTrue( bp_user_can( 0, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 306 307 $this->set_current_user( $old_user ); 308 } 309 310 public function test_user_can_see_public_group() { 311 $g1 = $this->factory->group->create( array( 312 'status' => 'public' 313 ) ); 314 $u1 = $this->factory->user->create(); 315 316 $this->assertTrue( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 317 } 318 319 public function test_user_can_see_private_group_even_when_not_logged_in() { 320 $g1 = $this->factory->group->create( array( 321 'status' => 'private' 322 ) ); 323 $old_user = get_current_user_id(); 324 $this->set_current_user( 0 ); 325 326 $this->assertTrue( bp_user_can( 0, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 327 328 $this->set_current_user( $old_user ); 329 } 330 331 public function test_user_can_see_private_group() { 332 $g1 = $this->factory->group->create( array( 333 'status' => 'private' 334 ) ); 335 $u1 = $this->factory->user->create(); 336 337 $this->assertTrue( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 338 } 339 340 public function test_user_cannot_see_hidden_group_if_not_logged_in() { 341 $g1 = $this->factory->group->create( array( 342 'status' => 'hidden' 343 ) ); 344 $old_user = get_current_user_id(); 345 $this->set_current_user( 0 ); 346 347 $this->assertFalse( bp_user_can( 0, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 348 349 $this->set_current_user( $old_user ); 350 } 351 352 public function test_user_cannot_see_hidden_group_if_not_a_member() { 353 $g1 = $this->factory->group->create( array( 354 'status' => 'hidden' 355 ) ); 356 $u1 = $this->factory->user->create(); 357 358 $this->assertFalse( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 359 } 360 361 public function test_user_can_see_hidden_group_if_member() { 362 $g1 = $this->factory->group->create( array( 363 'status' => 'hidden' 364 ) ); 365 $u1 = $this->factory->user->create(); 366 $this->add_user_to_group( $u1, $g1 ); 367 368 $this->assertTrue( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) ); 369 } 370 371 }