[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/core/ -> invitations.php (source)

   1  <?php
   2  
   3  include_once BP_TESTS_DIR . 'assets/invitations-extensions.php';
   4  
   5  /**
   6   * @group core
   7   * @group invitations
   8   */
   9   class BP_Tests_Invitations extends BP_UnitTestCase {
  10  	public function test_bp_invitations_add_invitation_vanilla() {
  11          $old_current_user = get_current_user_id();
  12  
  13          $u1 = $this->factory->user->create();
  14          $u2 = $this->factory->user->create();
  15          $u3 = $this->factory->user->create();
  16          $this->set_current_user( $u1 );
  17  
  18          $invites_class = new BPTest_Invitation_Manager_Extension();
  19  
  20          // Create a couple of invitations.
  21          $invite_args = array(
  22              'user_id'           => $u3,
  23              'inviter_id'        => $u1,
  24              'item_id'           => 1,
  25              'send_invite'       => 'sent',
  26          );
  27          $i1 = $invites_class->add_invitation( $invite_args );
  28          $invite_args['inviter_id'] = $u2;
  29          $i2 = $invites_class->add_invitation( $invite_args );
  30  
  31          $get_invites = array(
  32              'user_id'        => $u3,
  33              'fields'         => 'ids',
  34          );
  35          $invites = $invites_class->get_invitations( $get_invites );
  36          $this->assertEqualSets( array( $i1, $i2 ), $invites );
  37  
  38          $this->set_current_user( $old_current_user );
  39      }
  40  
  41      public function test_bp_invitations_add_invitation_avoid_duplicates() {
  42          $old_current_user = get_current_user_id();
  43  
  44          $u1 = $this->factory->user->create();
  45          $u2 = $this->factory->user->create();
  46          $this->set_current_user( $u1 );
  47  
  48          $invites_class = new BPTest_Invitation_Manager_Extension();
  49  
  50          // Create an invitation.
  51          $invite_args = array(
  52              'user_id'           => $u2,
  53              'inviter_id'        => $u1,
  54              'item_id'           => 1,
  55              'send_invite'       => 'sent',
  56          );
  57          $i1 = $invites_class->add_invitation( $invite_args );
  58          // Attempt to create a duplicate.
  59          $this->assertFalse( $invites_class->add_invitation( $invite_args ) );
  60  
  61          $this->set_current_user( $old_current_user );
  62      }
  63  
  64      public function test_bp_invitations_add_invitation_invite_plus_request_should_accept() {
  65          $old_current_user = get_current_user_id();
  66  
  67          $u1 = $this->factory->user->create();
  68          $u2 = $this->factory->user->create();
  69          $u3 = $this->factory->user->create();
  70          $this->set_current_user( $u1 );
  71  
  72          $invites_class = new BPTest_Invitation_Manager_Extension();
  73  
  74          // Create an invitation.
  75          $invite_args = array(
  76              'user_id'           => $u3,
  77              'inviter_id'        => $u1,
  78              'item_id'           => 1,
  79              'send_invite'       => 'sent',
  80          );
  81          $i1 = $invites_class->add_invitation( $invite_args );
  82  
  83          // Create a request.
  84          $request_args = array(
  85              'user_id'           => $u3,
  86              'item_id'           => 1,
  87          );
  88          $r1 = $invites_class->add_request( $request_args );
  89  
  90          $get_invites = array(
  91              'user_id'          => $u3,
  92              'accepted'         => 'accepted'
  93          );
  94          $invites = $invites_class->get_invitations( $get_invites );
  95          $this->assertEqualSets( array( $i1 ), wp_list_pluck( $invites, 'id' ) );
  96  
  97          $this->set_current_user( $old_current_user );
  98      }
  99  
 100      public function test_bp_invitations_add_invitation_unsent_invite_plus_request_should_not_accept() {
 101          $old_current_user = get_current_user_id();
 102  
 103          $u1 = $this->factory->user->create();
 104          $u2 = $this->factory->user->create();
 105          $u3 = $this->factory->user->create();
 106          $this->set_current_user( $u1 );
 107  
 108          $invites_class = new BPTest_Invitation_Manager_Extension();
 109  
 110          // Create an invitation.
 111          $invite_args = array(
 112              'user_id'           => $u3,
 113              'inviter_id'        => $u1,
 114              'item_id'           => 1,
 115              'send_invite'       => 0,
 116          );
 117          $i1 = $invites_class->add_invitation( $invite_args );
 118  
 119          // Create a request.
 120          $request_args = array(
 121              'user_id'           => $u3,
 122              'item_id'           => 1,
 123          );
 124          $r1 = $invites_class->add_request( $request_args );
 125  
 126          $get_invites = array(
 127              'user_id'          => $u3,
 128              'accepted'         => 'accepted'
 129          );
 130          $invites = $invites_class->get_invitations( $get_invites );
 131          $this->assertEqualSets( array(), wp_list_pluck( $invites, 'id' ) );
 132  
 133          $this->set_current_user( $old_current_user );
 134      }
 135  
 136      public function test_bp_invitations_add_invitation_unsent_invite_plus_request_then_send_invite_should_accept() {
 137          $old_current_user = get_current_user_id();
 138  
 139          $u1 = $this->factory->user->create();
 140          $u2 = $this->factory->user->create();
 141          $u3 = $this->factory->user->create();
 142          $this->set_current_user( $u1 );
 143  
 144          $invites_class = new BPTest_Invitation_Manager_Extension();
 145  
 146          // Create an invitation.
 147          $invite_args = array(
 148              'user_id'           => $u3,
 149              'inviter_id'        => $u1,
 150              'item_id'           => 1,
 151              'send_invite'       => 0,
 152          );
 153          $i1 = $invites_class->add_invitation( $invite_args );
 154  
 155          // Create a request.
 156          $request_args = array(
 157              'user_id'           => $u3,
 158              'item_id'           => 1,
 159          );
 160          $r1 = $invites_class->add_request( $request_args );
 161  
 162          $invites_class->send_invitation_by_id( $i1 );
 163  
 164          // Check that both the request and invitation are marked 'accepted'.
 165          $get_invites = array(
 166              'user_id'          => $u3,
 167              'type'             => 'all',
 168              'accepted'         => 'accepted',
 169              'fields'           => 'ids'
 170          );
 171          $invites = $invites_class->get_invitations( $get_invites );
 172          $this->assertEqualSets( array( $i1, $r1 ), $invites );
 173  
 174          $this->set_current_user( $old_current_user );
 175      }
 176      
 177  	public function test_bp_invitations_add_request_vanilla() {
 178          $old_current_user = get_current_user_id();
 179  
 180          $u1 = $this->factory->user->create();
 181          $this->set_current_user( $u1 );
 182  
 183          $invites_class = new BPTest_Invitation_Manager_Extension();
 184  
 185          // Create a couple of requests.
 186          $request_args = array(
 187              'user_id'           => $u1,
 188              'item_id'           => 7,
 189          );
 190          $r1 = $invites_class->add_request( $request_args );
 191          $request_args['item_id'] = 4;
 192          $r2 = $invites_class->add_request( $request_args );
 193  
 194          $get_requests = array(
 195              'user_id'           => $u1,
 196              'fields'            => 'ids'
 197          );
 198          $requests = $invites_class->get_requests( $get_requests );
 199          $this->assertEqualSets( array( $r1, $r2 ), $requests );
 200  
 201          $this->set_current_user( $old_current_user );
 202      }
 203  
 204      public function test_bp_invitations_add_request_avoid_duplicates() {
 205          $old_current_user = get_current_user_id();
 206  
 207          $invites_class = new BPTest_Invitation_Manager_Extension();
 208  
 209          $u1 = $this->factory->user->create();
 210          $this->set_current_user( $u1 );
 211  
 212          // Create a couple of requests.
 213          $request_args = array(
 214              'user_id'           => $u1,
 215              'item_id'           => 7,
 216          );
 217          $r1 = $invites_class->add_request( $request_args );
 218          // Attempt to create a duplicate.
 219          $this->assertFalse( $invites_class->add_request( $request_args ) );
 220  
 221          $this->set_current_user( $old_current_user );
 222      }
 223  
 224      public function test_bp_invitations_add_request_request_plus_sent_invite_should_accept() {
 225          $old_current_user = get_current_user_id();
 226  
 227          $u1 = $this->factory->user->create();
 228          $u2 = $this->factory->user->create();
 229          $this->set_current_user( $u1 );
 230  
 231          $invites_class = new BPTest_Invitation_Manager_Extension();
 232  
 233          // Create a request.
 234          $request_args = array(
 235              'user_id'           => $u2,
 236              'item_id'           => 1,
 237          );
 238          $r1 = $invites_class->add_request( $request_args );
 239  
 240          // Create an invitation.
 241          $invite_args = array(
 242              'user_id'           => $u2,
 243              'inviter_id'        => $u1,
 244              'item_id'           => 1,
 245              'send_invite'       => 1,
 246          );
 247          $i1 = $invites_class->add_invitation( $invite_args );
 248  
 249          // Check that both the request and invitation are marked 'accepted'.
 250          $get_invites = array(
 251              'user_id'          => $u2,
 252              'type'             => 'all',
 253              'accepted'         => 'accepted',
 254              'fields'           => 'ids'
 255          );
 256          $invites = $invites_class->get_invitations( $get_invites );
 257          $this->assertEqualSets( array( $r1, $i1 ), $invites );
 258  
 259          $this->set_current_user( $old_current_user );
 260      }
 261  
 262      public function test_bp_invitations_sending_should_clear_cache() {
 263          $old_current_user = get_current_user_id();
 264  
 265          $u1 = $this->factory->user->create();
 266          $u2 = $this->factory->user->create();
 267          $this->set_current_user( $u1 );
 268  
 269          $invites_class = new BPTest_Invitation_Manager_Extension();
 270  
 271          // Create an invitation.
 272          $invite_args = array(
 273              'user_id'           => $u2,
 274              'inviter_id'        => $u1,
 275              'item_id'           => 1,
 276          );
 277          $i1 = $invites_class->add_invitation( $invite_args );
 278  
 279          $invite = new BP_Invitation( $i1 );
 280          $this->assertEquals( 0, $invite->invite_sent );
 281  
 282          $invites_class->send_invitation_by_id( $i1 );
 283  
 284          $invite = new BP_Invitation( $i1 );
 285          $this->assertEquals( 1, $invite->invite_sent );
 286  
 287          $this->set_current_user( $old_current_user );
 288      }
 289  
 290  }


Generated: Tue Dec 10 01:01:39 2019 Cross-referenced by PHPXref 0.7.1