[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
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 'status' => 'private' 25 ) ); 26 27 $now = time(); 28 29 self::commit_transaction(); 30 } 31 32 public static function tearDownAfterClass() { 33 foreach ( self::$groups as $group ) { 34 groups_delete_group( $group ); 35 } 36 37 if ( is_multisite() ) { 38 wpmu_delete_user( self::$user ); 39 wpmu_delete_user( self::$admin_user ); 40 } else { 41 wp_delete_user( self::$user ); 42 wp_delete_user( self::$admin_user ); 43 } 44 45 self::commit_transaction(); 46 } 47 48 public function test_groups_is_user_admin_expected_true() { 49 $this->add_user_to_group( self::$user, self::$groups[0], array( 50 'is_admin' => false, 51 ) ); 52 $this->add_user_to_group( self::$user, self::$groups[1], array( 53 'is_admin' => true, 54 ) ); 55 56 $this->assertNotEmpty( groups_is_user_admin( self::$user, self::$groups[1] ) ); 57 } 58 59 public function test_groups_is_user_admin_expected_false() { 60 $this->add_user_to_group( self::$user, self::$groups[0], array( 61 'is_admin' => false, 62 ) ); 63 $this->add_user_to_group( self::$user, self::$groups[1], array( 64 'is_admin' => true, 65 ) ); 66 67 $this->assertEquals( false, groups_is_user_admin( self::$user, self::$groups[0] ) ); 68 } 69 70 public function test_groups_is_user_mod_expected_true() { 71 $this->add_user_to_group( self::$user, self::$groups[0], array( 72 'is_mod' => false, 73 ) ); 74 $this->add_user_to_group( self::$user, self::$groups[1], array( 75 'is_mod' => true, 76 ) ); 77 78 $this->assertNotEmpty( groups_is_user_mod( self::$user, self::$groups[1] ) ); 79 } 80 81 public function test_groups_is_user_mod_expected_false() { 82 $this->add_user_to_group( self::$user, self::$groups[0], array( 83 'is_mod' => false, 84 ) ); 85 $this->add_user_to_group( self::$user, self::$groups[1], array( 86 'is_mod' => true, 87 ) ); 88 89 $this->assertEquals( false, groups_is_user_mod( self::$user, self::$groups[0] ) ); 90 } 91 92 public function test_groups_is_user_mod_should_return_false_when_user_is_also_banned() { 93 $this->add_user_to_group( self::$user, self::$groups[0], array( 94 'is_mod' => false, 95 ) ); 96 $this->add_user_to_group( self::$user, self::$groups[1], array( 97 'is_mod' => true, 98 ) ); 99 100 $m = new BP_Groups_Member( self::$user, self::$groups[1] ); 101 $m->ban(); 102 103 $this->assertEquals( false, groups_is_user_mod( self::$user, self::$groups[1] ) ); 104 } 105 106 public function test_groups_is_user_member_expected_true() { 107 $this->add_user_to_group( self::$user, self::$groups[1] ); 108 109 $this->assertNotEmpty( groups_is_user_member( self::$user, self::$groups[1] ) ); 110 } 111 112 public function test_groups_is_user_member_should_return_true_for_admin() { 113 $this->add_user_to_group( self::$user, self::$groups[1], array( 114 'is_admin' => true, 115 ) ); 116 117 $this->assertNotEmpty( groups_is_user_member( self::$user, self::$groups[1] ) ); 118 } 119 120 public function test_groups_is_user_member_should_return_true_for_mod() { 121 $this->add_user_to_group( self::$user, self::$groups[1], array( 122 'is_mod' => true, 123 ) ); 124 125 $this->assertNotEmpty( groups_is_user_member( self::$user, self::$groups[1] ) ); 126 } 127 128 public function test_groups_is_user_member_expected_false() { 129 $this->add_user_to_group( self::$user, self::$groups[1] ); 130 131 $this->assertEquals( false, groups_is_user_member( self::$user, self::$groups[0] ) ); 132 } 133 134 public function test_groups_is_user_member_should_return_false_when_user_is_also_banned() { 135 $this->add_user_to_group( self::$user, self::$groups[1] ); 136 137 $m = new BP_Groups_Member( self::$user, self::$groups[1] ); 138 $m->ban(); 139 140 $this->assertEquals( false, groups_is_user_member( self::$user, self::$groups[1] ) ); 141 } 142 143 public function test_groups_is_user_banned_should_return_false_for_non_member() { 144 $this->assertEquals( false, groups_is_user_banned( self::$user, self::$groups[1] ) ); 145 } 146 147 /** 148 * Return values for these functions are terrible. 149 */ 150 public function test_groups_is_user_banned_should_return_false_for_non_banned_member() { 151 $this->add_user_to_group( self::$user, self::$groups[1] ); 152 $this->assertEquals( 0, groups_is_user_banned( self::$user, self::$groups[1] ) ); 153 } 154 155 public function test_groups_is_user_banned_should_return_true_for_banned_member() { 156 $this->add_user_to_group( self::$user, self::$groups[1] ); 157 158 $m = new BP_Groups_Member( self::$user, self::$groups[1] ); 159 $m->ban(); 160 161 $this->assertNotEmpty( groups_is_user_banned( self::$user, self::$groups[1] ) ); 162 } 163 164 public function test_groups_is_user_invited_should_return_false_for_confirmed_member() { 165 $this->add_user_to_group( self::$user, self::$groups[1] ); 166 $this->assertEquals( false, groups_is_user_invited( self::$user, self::$groups[1] ) ); 167 } 168 169 public function test_groups_is_user_invited_should_return_false_for_uninvited_member() { 170 $this->assertEquals( false, groups_is_user_invited( self::$user, self::$groups[1] ) ); 171 } 172 173 public function test_groups_is_user_invited_should_return_true_for_invited_member() { 174 $i = groups_invite_user( array( 175 'user_id' => self::$user, 176 'group_id' => self::$groups[1], 177 'inviter_id' => self::$admin_user, 178 'send_invite' => 1, 179 ) ); 180 181 $this->assertNotEmpty( groups_is_user_invited( self::$user, self::$groups[1] ) ); 182 } 183 184 public function test_groups_is_user_pending_should_return_false_for_invited_member() { 185 groups_invite_user( array( 186 'user_id' => self::$user, 187 'group_id' => self::$groups[1], 188 'send_invite' => 1 189 ) ); 190 191 $this->assertEquals( false, groups_is_user_pending( self::$user, self::$groups[1] ) ); 192 } 193 194 public function test_groups_is_user_pending_should_return_false_for_member_with_no_request() { 195 $this->assertEquals( false, groups_is_user_pending( self::$user, self::$groups[1] ) ); 196 } 197 198 public function test_groups_is_user_pending_should_return_true_for_pending_member() { 199 groups_send_membership_request( array( 200 'user_id' => self::$user, 201 'group_id' => self::$groups[1], 202 ) ); 203 204 $this->assertNotEmpty( groups_is_user_pending( self::$user, self::$groups[1] ) ); 205 } 206 }
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 |