[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * Tests for the `groups_is_user_*()` functions.
   5   *
   6   * @group groups
   7   */
   8  class BP_Tests_Groups_Functions_GroupsIsUser extends BP_UnitTestCase {
   9      static $user;
  10      static $admin_user;
  11      static $groups;
  12  
  13  	public static function wpSetUpBeforeClass( $f ) {
  14          self::$user = $f->user->create( array(
  15              'user_login' => 'groups_is_user',
  16              'user_email' => 'groups_is_user@example.com',
  17          ) );
  18          self::$admin_user = $f->user->create( array(
  19              'user_login' => 'groups_is_user_admin',
  20              'user_email' => 'groups_is_user_admin@example.com',
  21          ) );
  22          self::$groups = $f->group->create_many( 3, array(
  23              'creator_id' => self::$admin_user,
  24          ) );
  25  
  26          $now = time();
  27  
  28          self::commit_transaction();
  29      }
  30  
  31  	public static function tearDownAfterClass() {
  32          foreach ( self::$groups as $group ) {
  33              groups_delete_group( $group );
  34          }
  35  
  36          if ( is_multisite() ) {
  37              wpmu_delete_user( self::$user );
  38              wpmu_delete_user( self::$admin_user );
  39          } else {
  40              wp_delete_user( self::$user );
  41              wp_delete_user( self::$admin_user );
  42          }
  43  
  44          self::commit_transaction();
  45      }
  46  
  47  	public function test_groups_is_user_admin_expected_true() {
  48          $this->add_user_to_group( self::$user, self::$groups[0], array(
  49              'is_admin' => false,
  50          ) );
  51          $this->add_user_to_group( self::$user, self::$groups[1], array(
  52              'is_admin' => true,
  53          ) );
  54  
  55          $this->assertNotEmpty( groups_is_user_admin( self::$user, self::$groups[1] ) );
  56      }
  57  
  58  	public function test_groups_is_user_admin_expected_false() {
  59          $this->add_user_to_group( self::$user, self::$groups[0], array(
  60              'is_admin' => false,
  61          ) );
  62          $this->add_user_to_group( self::$user, self::$groups[1], array(
  63              'is_admin' => true,
  64          ) );
  65  
  66          $this->assertEquals( false, groups_is_user_admin( self::$user, self::$groups[0] ) );
  67      }
  68  
  69  	public function test_groups_is_user_mod_expected_true() {
  70          $this->add_user_to_group( self::$user, self::$groups[0], array(
  71              'is_mod' => false,
  72          ) );
  73          $this->add_user_to_group( self::$user, self::$groups[1], array(
  74              'is_mod' => true,
  75          ) );
  76  
  77          $this->assertNotEmpty( groups_is_user_mod( self::$user, self::$groups[1] ) );
  78      }
  79  
  80  	public function test_groups_is_user_mod_expected_false() {
  81          $this->add_user_to_group( self::$user, self::$groups[0], array(
  82              'is_mod' => false,
  83          ) );
  84          $this->add_user_to_group( self::$user, self::$groups[1], array(
  85              'is_mod' => true,
  86          ) );
  87  
  88          $this->assertEquals( false, groups_is_user_mod( self::$user, self::$groups[0] ) );
  89      }
  90  
  91      public function test_groups_is_user_mod_should_return_false_when_user_is_also_banned() {
  92          $this->add_user_to_group( self::$user, self::$groups[0], array(
  93              'is_mod' => false,
  94          ) );
  95          $this->add_user_to_group( self::$user, self::$groups[1], array(
  96              'is_mod' => true,
  97          ) );
  98  
  99          $m = new BP_Groups_Member( self::$user, self::$groups[1] );
 100          $m->ban();
 101  
 102          $this->assertEquals( false, groups_is_user_mod( self::$user, self::$groups[1] ) );
 103      }
 104  
 105  	public function test_groups_is_user_member_expected_true() {
 106          $this->add_user_to_group( self::$user, self::$groups[1] );
 107  
 108          $this->assertNotEmpty( groups_is_user_member( self::$user, self::$groups[1] ) );
 109      }
 110  
 111      public function test_groups_is_user_member_should_return_true_for_admin() {
 112          $this->add_user_to_group( self::$user, self::$groups[1], array(
 113              'is_admin' => true,
 114          ) );
 115  
 116          $this->assertNotEmpty( groups_is_user_member( self::$user, self::$groups[1] ) );
 117      }
 118  
 119      public function test_groups_is_user_member_should_return_true_for_mod() {
 120          $this->add_user_to_group( self::$user, self::$groups[1], array(
 121              'is_mod' => true,
 122          ) );
 123  
 124          $this->assertNotEmpty( groups_is_user_member( self::$user, self::$groups[1] ) );
 125      }
 126  
 127  	public function test_groups_is_user_member_expected_false() {
 128          $this->add_user_to_group( self::$user, self::$groups[1] );
 129  
 130          $this->assertEquals( false, groups_is_user_member( self::$user, self::$groups[0] ) );
 131      }
 132  
 133      public function test_groups_is_user_member_should_return_false_when_user_is_also_banned() {
 134          $this->add_user_to_group( self::$user, self::$groups[1] );
 135  
 136          $m = new BP_Groups_Member( self::$user, self::$groups[1] );
 137          $m->ban();
 138  
 139          $this->assertEquals( false, groups_is_user_member( self::$user, self::$groups[1] ) );
 140      }
 141  
 142      public function test_groups_is_user_banned_should_return_false_for_non_member() {
 143          $this->assertEquals( false, groups_is_user_banned( self::$user, self::$groups[1] ) );
 144      }
 145  
 146      /**
 147       * Return values for these functions are terrible.
 148       */
 149      public function test_groups_is_user_banned_should_return_false_for_non_banned_member() {
 150          $this->add_user_to_group( self::$user, self::$groups[1] );
 151          $this->assertEquals( 0, groups_is_user_banned( self::$user, self::$groups[1] ) );
 152      }
 153  
 154      public function test_groups_is_user_banned_should_return_true_for_banned_member() {
 155          $this->add_user_to_group( self::$user, self::$groups[1] );
 156  
 157          $m = new BP_Groups_Member( self::$user, self::$groups[1] );
 158          $m->ban();
 159  
 160          $this->assertNotEmpty( groups_is_user_banned( self::$user, self::$groups[1] ) );
 161      }
 162  
 163      public function test_groups_is_user_invited_should_return_false_for_confirmed_member() {
 164          $this->add_user_to_group( self::$user, self::$groups[1] );
 165          $this->assertEquals( false, groups_is_user_invited( self::$user, self::$groups[1] ) );
 166      }
 167  
 168      public function test_groups_is_user_invited_should_return_false_for_uninvited_member() {
 169          $this->assertEquals( false, groups_is_user_invited( self::$user, self::$groups[1] ) );
 170      }
 171  
 172      public function test_groups_is_user_invited_should_return_true_for_invited_member() {
 173          $i = groups_invite_user( array(
 174              'user_id' => self::$user,
 175              'group_id' => self::$groups[1],
 176              'inviter_id' => 123,
 177          ) );
 178  
 179          // Send invite.
 180          $m = new BP_Groups_Member( self::$user, self::$groups[1] );
 181          $m->invite_sent = 1;
 182          $m->save();
 183  
 184          $this->assertNotEmpty( groups_is_user_invited( self::$user, self::$groups[1] ) );
 185      }
 186  
 187      public function test_groups_is_user_pending_should_return_false_for_pending_member() {
 188          groups_invite_user( array(
 189              'user_id' => self::$user,
 190              'group_id' => self::$groups[1],
 191              'inviter_id' => 123,
 192          ) );
 193  
 194          // Send invite.
 195          $m = new BP_Groups_Member( self::$user, self::$groups[1] );
 196          $m->invite_sent = 1;
 197          $m->save();
 198  
 199          $this->assertEquals( false, groups_is_user_pending( self::$user, self::$groups[1] ) );
 200      }
 201  
 202      public function test_groups_is_user_pending_should_return_false_for_member_with_no_request() {
 203          $this->assertEquals( false, groups_is_user_pending( self::$user, self::$groups[1] ) );
 204      }
 205  
 206      public function test_groups_is_user_pending_should_return_true_for_pending_member() {
 207  
 208          $m                = new BP_Groups_Member;
 209          $m->group_id      = self::$groups[1];
 210          $m->user_id       = self::$user;
 211          $m->inviter_id    = 0;
 212          $m->is_admin      = 0;
 213          $m->user_title    = '';
 214          $m->date_modified = bp_core_current_time();
 215          $m->is_confirmed  = 0;
 216          $m->comments      = 'request';
 217          $m->save();
 218  
 219          $this->assertNotEmpty( groups_is_user_pending( self::$user, self::$groups[1] ) );
 220      }
 221  }


Generated: Tue Jul 16 01:01:43 2019 Cross-referenced by PHPXref 0.7.1