[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/groups/ -> user_can.php (source)

   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( $u1, $g1 );
 112  
 113          $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) );
 114      }
 115  
 116      public function test_user_cannot_request_membership_in_private_group_if_banned() {
 117          $g1 = $this->factory->group->create( array(
 118              'status'      => 'private'
 119          ) );
 120          $u1 = $this->factory->user->create();
 121          $this->add_user_to_group( $u1, $g1 );
 122  
 123          buddypress()->is_item_admin = true;
 124          groups_ban_member( $u1, $g1 );
 125  
 126          $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) );
 127      }
 128  
 129      public function test_user_cannot_receive_invitation_to_public_group() {
 130          $g1 = $this->factory->group->create( array(
 131              'status'      => 'public'
 132          ) );
 133          $u1 = $this->factory->user->create();
 134  
 135          $this->assertFalse( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) );
 136      }
 137  
 138      public function test_user_can_receive_invitation_to_private_group() {
 139          $g1 = $this->factory->group->create( array(
 140              'status'      => 'private'
 141          ) );
 142          $u1 = $this->factory->user->create();
 143  
 144          $this->assertTrue( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) );
 145      }
 146  
 147      public function test_user_cannot_receive_invitation_to_private_group_if_already_member() {
 148          $g1 = $this->factory->group->create( array(
 149              'status'      => 'private'
 150          ) );
 151          $u1 = $this->factory->user->create();
 152          $this->add_user_to_group( $u1, $g1 );
 153  
 154          $this->assertFalse( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) );
 155      }
 156  
 157      /**
 158       * @ticket BP7610
 159       */
 160      public function test_user_cannot_receive_invitation_to_private_group_if_already_member_even_superadmin() {
 161          if ( ! is_multisite() ) {
 162              $this->markTestSkipped();
 163          }
 164  
 165          $g1 = $this->factory->group->create( array(
 166              'status'      => 'private'
 167          ) );
 168          $u1 = $this->factory->user->create();
 169          $this->add_user_to_group( $u1, $g1 );
 170  
 171          // Grant super admin status.
 172          grant_super_admin( $u1 );
 173  
 174          $this->assertFalse( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) );
 175      }
 176  
 177      public function test_user_cannot_receive_invitation_to_private_group_if_banned() {
 178          $g1 = $this->factory->group->create( array(
 179              'status'      => 'private'
 180          ) );
 181          $u1 = $this->factory->user->create();
 182          $this->add_user_to_group( $u1, $g1 );
 183  
 184          buddypress()->is_item_admin = true;
 185          groups_ban_member( $u1, $g1 );
 186  
 187          $this->assertFalse( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) );
 188      }
 189  
 190      public function test_user_can_receive_invitation_to_hidden_group() {
 191          $g1 = $this->factory->group->create( array(
 192              'status'      => 'hidden'
 193          ) );
 194          $u1 = $this->factory->user->create();
 195  
 196          $this->assertTrue( bp_user_can( $u1, 'groups_receive_invitation', array( 'group_id' => $g1 ) ) );
 197      }
 198  
 199      public function test_user_cannot_send_invitation_to_public_group_if_not_a_member() {
 200          $g1 = $this->factory->group->create( array(
 201              'status'      => 'public'
 202          ) );
 203          $u1 = $this->factory->user->create();
 204  
 205          $this->assertFalse( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) );
 206      }
 207  
 208      public function test_user_cannot_send_invitation_to_private_group_if_not_a_member() {
 209          $g1 = $this->factory->group->create( array(
 210              'status'      => 'private'
 211          ) );
 212          $u1 = $this->factory->user->create();
 213  
 214          $this->assertFalse( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) );
 215      }
 216  
 217      public function test_user_cannot_send_invitation_to_private_group_if_banned() {
 218          $g1 = $this->factory->group->create( array(
 219              'status'      => 'private'
 220          ) );
 221          groups_update_groupmeta( $g1, 'invite_status', 'members' );
 222          $u1 = $this->factory->user->create();
 223          $this->add_user_to_group( $u1, $g1 );
 224  
 225          buddypress()->is_item_admin = true;
 226          groups_ban_member( $u1, $g1 );
 227  
 228          $this->assertFalse( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) );
 229      }
 230  
 231      public function test_user_can_send_invitation_to_private_group_if_a_member() {
 232          $g1 = $this->factory->group->create( array(
 233              'status'      => 'private',
 234  
 235          ) );
 236          groups_update_groupmeta( $g1, 'invite_status', 'members' );
 237          $u1 = $this->factory->user->create();
 238          $this->add_user_to_group( $u1, $g1 );
 239  
 240          $this->assertTrue( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) );
 241      }
 242  
 243      public function test_user_can_send_invitation_to_hidden_group_if_a_member() {
 244          $g1 = $this->factory->group->create( array(
 245              'status'      => 'hidden'
 246          ) );
 247          $u1 = $this->factory->user->create();
 248          $u1 = $this->factory->user->create();
 249          $this->add_user_to_group( $u1, $g1 );
 250  
 251          $this->assertTrue( bp_user_can( $u1, 'groups_send_invitation', array( 'group_id' => $g1 ) ) );
 252      }
 253  
 254      public function test_user_can_access_public_group_even_when_not_logged_in() {
 255          $g1 = $this->factory->group->create( array(
 256              'status'      => 'public'
 257          ) );
 258          $old_user = get_current_user_id();
 259          $this->set_current_user( 0 );
 260  
 261          $this->assertTrue( bp_user_can( 0, 'groups_access_group', array( 'group_id' => $g1 ) ) );
 262  
 263          $this->set_current_user( $old_user );
 264      }
 265  
 266      public function test_user_can_access_public_group_if_not_a_member() {
 267          $g1 = $this->factory->group->create( array(
 268              'status'      => 'public'
 269          ) );
 270          $u1 = $this->factory->user->create();
 271  
 272          $this->assertTrue( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) );
 273      }
 274  
 275      public function test_user_cannot_access_private_group_if_not_logged_in() {
 276          $g1 = $this->factory->group->create( array(
 277              'status'      => 'private'
 278          ) );
 279          $old_user = get_current_user_id();
 280          $this->set_current_user( 0 );
 281  
 282          $this->assertFalse( bp_user_can( 0, 'groups_access_group', array( 'group_id' => $g1 ) ) );
 283  
 284          $this->set_current_user( $old_user );
 285      }
 286  
 287      public function test_user_cannot_access_private_group_if_not_a_member() {
 288          $g1 = $this->factory->group->create( array(
 289              'status'      => 'private'
 290          ) );
 291          $u1 = $this->factory->user->create();
 292  
 293          $this->assertFalse( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) );
 294      }
 295  
 296      public function test_user_can_access_private_group_if_a_member() {
 297          $g1 = $this->factory->group->create( array(
 298              'status'      => 'private'
 299          ) );
 300          $u1 = $this->factory->user->create();
 301          $this->add_user_to_group( $u1, $g1 );
 302  
 303          $this->assertTrue( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) );
 304      }
 305  
 306      public function test_user_cannot_access_hidden_group_if_not_logged_in() {
 307          $g1 = $this->factory->group->create( array(
 308              'status'      => 'hidden'
 309          ) );
 310          $old_user = get_current_user_id();
 311          $this->set_current_user( 0 );
 312  
 313          $this->assertFalse( bp_user_can( 0, 'groups_access_group', array( 'group_id' => $g1 ) ) );
 314  
 315          $this->set_current_user( $old_user );
 316      }
 317  
 318      public function test_user_cannot_access_hidden_group_if_not_a_member() {
 319          $g1 = $this->factory->group->create( array(
 320              'status'      => 'hidden'
 321          ) );
 322          $u1 = $this->factory->user->create();
 323  
 324          $this->assertFalse( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) );
 325      }
 326  
 327  	public function test_user_can_access_hidden_group_if_a_member() {
 328          $g1 = $this->factory->group->create( array(
 329              'status'      => 'hidden'
 330          ) );
 331          $u1 = $this->factory->user->create();
 332          $this->add_user_to_group( $u1, $g1 );
 333  
 334          $this->assertTrue( bp_user_can( $u1, 'groups_access_group', array( 'group_id' => $g1 ) ) );
 335      }
 336  
 337      public function test_user_can_see_public_group_even_when_not_logged_in() {
 338          $g1 = $this->factory->group->create( array(
 339              'status'      => 'public'
 340          ) );
 341          $old_user = get_current_user_id();
 342          $this->set_current_user( 0 );
 343  
 344          $this->assertTrue( bp_user_can( 0, 'groups_see_group', array( 'group_id' => $g1 ) ) );
 345  
 346          $this->set_current_user( $old_user );
 347      }
 348  
 349  	public function test_user_can_see_public_group() {
 350          $g1 = $this->factory->group->create( array(
 351              'status'      => 'public'
 352          ) );
 353          $u1 = $this->factory->user->create();
 354  
 355          $this->assertTrue( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) );
 356      }
 357  
 358      public function test_user_can_see_private_group_even_when_not_logged_in() {
 359          $g1 = $this->factory->group->create( array(
 360              'status'      => 'private'
 361          ) );
 362          $old_user = get_current_user_id();
 363          $this->set_current_user( 0 );
 364  
 365          $this->assertTrue( bp_user_can( 0, 'groups_see_group', array( 'group_id' => $g1 ) ) );
 366  
 367          $this->set_current_user( $old_user );
 368      }
 369  
 370  	public function test_user_can_see_private_group() {
 371          $g1 = $this->factory->group->create( array(
 372              'status'      => 'private'
 373          ) );
 374          $u1 = $this->factory->user->create();
 375  
 376          $this->assertTrue( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) );
 377      }
 378  
 379      public function test_user_cannot_see_hidden_group_if_not_logged_in() {
 380          $g1 = $this->factory->group->create( array(
 381              'status'      => 'hidden'
 382          ) );
 383          $old_user = get_current_user_id();
 384          $this->set_current_user( 0 );
 385  
 386          $this->assertFalse( bp_user_can( 0, 'groups_see_group', array( 'group_id' => $g1 ) ) );
 387  
 388          $this->set_current_user( $old_user );
 389      }
 390  
 391      public function test_user_cannot_see_hidden_group_if_not_a_member() {
 392          $g1 = $this->factory->group->create( array(
 393              'status'      => 'hidden'
 394          ) );
 395          $u1 = $this->factory->user->create();
 396  
 397          $this->assertFalse( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) );
 398      }
 399  
 400  	public function test_user_can_see_hidden_group_if_member() {
 401          $g1 = $this->factory->group->create( array(
 402              'status'      => 'hidden'
 403          ) );
 404          $u1 = $this->factory->user->create();
 405          $this->add_user_to_group( $u1, $g1 );
 406  
 407          $this->assertTrue( bp_user_can( $u1, 'groups_see_group', array( 'group_id' => $g1 ) ) );
 408      }
 409  
 410      /**
 411       * @ticket BP7610
 412       */
 413      public function test_user_can_groups_request_membership_for_super_admin() {
 414          if ( ! is_multisite() ) {
 415              $this->markTestSkipped();
 416          }
 417  
 418          $g1 = $this->factory->group->create( array(
 419              'status' => 'public'
 420          ) );
 421          $u1 = $this->factory->user->create();
 422          $this->add_user_to_group( $u1, $g1 );
 423  
 424          // Grant super admin status.
 425          grant_super_admin( $u1 );
 426  
 427          // Assert false since public groups shouldn't be able to request membership.
 428          $this->assertFalse( bp_user_can( $u1, 'groups_request_membership', array( 'group_id' => $g1 ) ) );
 429      }
 430  }


Generated: Sat Jul 20 01:01:39 2019 Cross-referenced by PHPXref 0.7.1