[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
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. Should return existing invite. 59 $i2 = $invites_class->add_invitation( $invite_args ); 60 $this->assertEquals( $i1, $i2 ); 61 62 $this->set_current_user( $old_current_user ); 63 } 64 65 public function test_bp_invitations_add_invitation_invite_plus_request_should_accept() { 66 $old_current_user = get_current_user_id(); 67 68 $u1 = $this->factory->user->create(); 69 $u2 = $this->factory->user->create(); 70 $u3 = $this->factory->user->create(); 71 $this->set_current_user( $u1 ); 72 73 $invites_class = new BPTest_Invitation_Manager_Extension(); 74 75 // Create an invitation. 76 $invite_args = array( 77 'user_id' => $u3, 78 'inviter_id' => $u1, 79 'item_id' => 1, 80 'send_invite' => 'sent', 81 ); 82 $i1 = $invites_class->add_invitation( $invite_args ); 83 84 // Create a request. 85 $request_args = array( 86 'user_id' => $u3, 87 'item_id' => 1, 88 ); 89 $r1 = $invites_class->add_request( $request_args ); 90 91 $get_invites = array( 92 'user_id' => $u3, 93 'accepted' => 'accepted' 94 ); 95 $invites = $invites_class->get_invitations( $get_invites ); 96 $this->assertEqualSets( array( $i1 ), wp_list_pluck( $invites, 'id' ) ); 97 98 $this->set_current_user( $old_current_user ); 99 } 100 101 public function test_bp_invitations_add_invitation_unsent_invite_plus_request_should_not_accept() { 102 $old_current_user = get_current_user_id(); 103 104 $u1 = $this->factory->user->create(); 105 $u2 = $this->factory->user->create(); 106 $u3 = $this->factory->user->create(); 107 $this->set_current_user( $u1 ); 108 109 $invites_class = new BPTest_Invitation_Manager_Extension(); 110 111 // Create an invitation. 112 $invite_args = array( 113 'user_id' => $u3, 114 'inviter_id' => $u1, 115 'item_id' => 1, 116 'send_invite' => 0, 117 ); 118 $i1 = $invites_class->add_invitation( $invite_args ); 119 120 // Create a request. 121 $request_args = array( 122 'user_id' => $u3, 123 'item_id' => 1, 124 ); 125 $r1 = $invites_class->add_request( $request_args ); 126 127 $get_invites = array( 128 'user_id' => $u3, 129 'accepted' => 'accepted' 130 ); 131 $invites = $invites_class->get_invitations( $get_invites ); 132 $this->assertEqualSets( array(), wp_list_pluck( $invites, 'id' ) ); 133 134 $this->set_current_user( $old_current_user ); 135 } 136 137 public function test_bp_invitations_add_invitation_unsent_invite_plus_request_then_send_invite_should_accept() { 138 $old_current_user = get_current_user_id(); 139 140 $u1 = $this->factory->user->create(); 141 $u2 = $this->factory->user->create(); 142 $u3 = $this->factory->user->create(); 143 $this->set_current_user( $u1 ); 144 145 $invites_class = new BPTest_Invitation_Manager_Extension(); 146 147 // Create an invitation. 148 $invite_args = array( 149 'user_id' => $u3, 150 'inviter_id' => $u1, 151 'item_id' => 1, 152 'send_invite' => 0, 153 ); 154 $i1 = $invites_class->add_invitation( $invite_args ); 155 156 // Create a request. 157 $request_args = array( 158 'user_id' => $u3, 159 'item_id' => 1, 160 ); 161 $r1 = $invites_class->add_request( $request_args ); 162 163 $invites_class->send_invitation_by_id( $i1 ); 164 165 // Check that both the request and invitation are marked 'accepted'. 166 $get_invites = array( 167 'user_id' => $u3, 168 'type' => 'all', 169 'accepted' => 'accepted', 170 'fields' => 'ids' 171 ); 172 $invites = $invites_class->get_invitations( $get_invites ); 173 $this->assertEqualSets( array( $i1, $r1 ), $invites ); 174 175 $this->set_current_user( $old_current_user ); 176 } 177 178 public function test_bp_invitations_add_request_vanilla() { 179 $old_current_user = get_current_user_id(); 180 181 $u1 = $this->factory->user->create(); 182 $this->set_current_user( $u1 ); 183 184 $invites_class = new BPTest_Invitation_Manager_Extension(); 185 186 // Create a couple of requests. 187 $request_args = array( 188 'user_id' => $u1, 189 'item_id' => 7, 190 ); 191 $r1 = $invites_class->add_request( $request_args ); 192 $request_args['item_id'] = 4; 193 $r2 = $invites_class->add_request( $request_args ); 194 195 $get_requests = array( 196 'user_id' => $u1, 197 'fields' => 'ids' 198 ); 199 $requests = $invites_class->get_requests( $get_requests ); 200 $this->assertEqualSets( array( $r1, $r2 ), $requests ); 201 202 $this->set_current_user( $old_current_user ); 203 } 204 205 public function test_bp_invitations_add_request_avoid_duplicates() { 206 $old_current_user = get_current_user_id(); 207 208 $invites_class = new BPTest_Invitation_Manager_Extension(); 209 210 $u1 = $this->factory->user->create(); 211 $this->set_current_user( $u1 ); 212 213 // Create a couple of requests. 214 $request_args = array( 215 'user_id' => $u1, 216 'item_id' => 7, 217 ); 218 $r1 = $invites_class->add_request( $request_args ); 219 // Attempt to create a duplicate. 220 $this->assertFalse( $invites_class->add_request( $request_args ) ); 221 222 $this->set_current_user( $old_current_user ); 223 } 224 225 public function test_bp_invitations_add_request_request_plus_sent_invite_should_accept() { 226 $old_current_user = get_current_user_id(); 227 228 $u1 = $this->factory->user->create(); 229 $u2 = $this->factory->user->create(); 230 $this->set_current_user( $u1 ); 231 232 $invites_class = new BPTest_Invitation_Manager_Extension(); 233 234 // Create a request. 235 $request_args = array( 236 'user_id' => $u2, 237 'item_id' => 1, 238 ); 239 $r1 = $invites_class->add_request( $request_args ); 240 241 // Create an invitation. 242 $invite_args = array( 243 'user_id' => $u2, 244 'inviter_id' => $u1, 245 'item_id' => 1, 246 'send_invite' => 1, 247 ); 248 $i1 = $invites_class->add_invitation( $invite_args ); 249 250 // Check that both the request and invitation are marked 'accepted'. 251 $get_invites = array( 252 'user_id' => $u2, 253 'type' => 'all', 254 'accepted' => 'accepted', 255 'fields' => 'ids' 256 ); 257 $invites = $invites_class->get_invitations( $get_invites ); 258 $this->assertEqualSets( array( $r1, $i1 ), $invites ); 259 260 $this->set_current_user( $old_current_user ); 261 } 262 263 public function test_bp_invitations_sending_should_clear_cache() { 264 $old_current_user = get_current_user_id(); 265 266 $u1 = $this->factory->user->create(); 267 $u2 = $this->factory->user->create(); 268 $this->set_current_user( $u1 ); 269 270 $invites_class = new BPTest_Invitation_Manager_Extension(); 271 272 // Create an invitation. 273 $invite_args = array( 274 'user_id' => $u2, 275 'inviter_id' => $u1, 276 'item_id' => 1, 277 ); 278 $i1 = $invites_class->add_invitation( $invite_args ); 279 280 $invite = new BP_Invitation( $i1 ); 281 $this->assertEquals( 0, $invite->invite_sent ); 282 283 $invites_class->send_invitation_by_id( $i1 ); 284 285 $invite = new BP_Invitation( $i1 ); 286 $this->assertEquals( 1, $invite->invite_sent ); 287 288 $this->set_current_user( $old_current_user ); 289 } 290 291 public function test_bp_invitations_get_by_search_terms() { 292 $old_current_user = get_current_user_id(); 293 294 $u1 = $this->factory->user->create(); 295 $u2 = $this->factory->user->create(); 296 $this->set_current_user( $u1 ); 297 298 $invites_class = new BPTest_Invitation_Manager_Extension(); 299 300 // Create an invitation. 301 $i1_args = array( 302 'user_id' => $u2, 303 'inviter_id' => $u1, 304 'item_id' => 1, 305 'content' => 'Sometimes, the mystery is enough.', 306 ); 307 $i1 = $invites_class->add_invitation( $i1_args ); 308 $invites_class->send_invitation_by_id( $i1 ); 309 310 // Create an invitation that uses an email address. 311 $i2_args = array( 312 'invitee_email' => 'findme@buddypress.org', 313 'inviter_id' => $u1, 314 'item_id' => 1, 315 ); 316 $i2 = $invites_class->add_invitation( $i2_args ); 317 $invites_class->send_invitation_by_id( $i2 ); 318 319 $get_invites = array( 320 'search_terms' => 'mystery', 321 'fields' => 'ids', 322 ); 323 $invites = $invites_class->get_invitations( $get_invites ); 324 $this->assertEqualSets( array( $i1 ), $invites ); 325 326 $get_invites = array( 327 'search_terms' => 'findme', 328 'fields' => 'ids', 329 ); 330 $invites = $invites_class->get_invitations( $get_invites ); 331 $this->assertEqualSets( array( $i2 ), $invites ); 332 333 $this->set_current_user( $old_current_user ); 334 } 335 336 public function test_bp_invitations_add_request_with_date_modified() { 337 $old_current_user = get_current_user_id(); 338 339 $u1 = $this->factory->user->create(); 340 $this->set_current_user( $u1 ); 341 342 $invites_class = new BPTest_Invitation_Manager_Extension(); 343 344 $time = gmdate( 'Y-m-d H:i:s', time() - 100 ); 345 $args = array( 346 'user_id' => $u1, 347 'item_id' => 7, 348 'date_modified' => $time, 349 ); 350 $r1 = $invites_class->add_request( $args ); 351 352 $req = new BP_Invitation( $r1 ); 353 $this->assertEquals( $time, $req->date_modified ); 354 355 $this->set_current_user( $old_current_user ); 356 } 357 358 public function test_bp_invitations_add_invite_with_date_modified() { 359 $old_current_user = get_current_user_id(); 360 361 $u1 = $this->factory->user->create(); 362 $u2 = $this->factory->user->create(); 363 $this->set_current_user( $u1 ); 364 365 $invites_class = new BPTest_Invitation_Manager_Extension(); 366 $time = gmdate( 'Y-m-d H:i:s', time() - 100 ); 367 368 // Create an invitation. 369 $invite_args = array( 370 'user_id' => $u2, 371 'inviter_id' => $u1, 372 'item_id' => 1, 373 'send_invite' => 1, 374 'date_modified' => $time, 375 ); 376 $i1 = $invites_class->add_invitation( $invite_args ); 377 378 $inv = new BP_Invitation( $i1 ); 379 $this->assertEquals( $time, $inv->date_modified ); 380 381 $this->set_current_user( $old_current_user ); 382 } 383 384 public function test_bp_invitations_orderby_item_id() { 385 $old_current_user = get_current_user_id(); 386 387 $u1 = $this->factory->user->create(); 388 $u2 = $this->factory->user->create(); 389 $u3 = $this->factory->user->create(); 390 $this->set_current_user( $u1 ); 391 392 $invites_class = new BPTest_Invitation_Manager_Extension(); 393 394 // Create an invitation. 395 $i1_args = array( 396 'user_id' => $u2, 397 'inviter_id' => $u1, 398 'item_id' => 6, 399 ); 400 $i1 = $invites_class->add_invitation( $i1_args ); 401 $invites_class->send_invitation_by_id( $i1 ); 402 403 $i2_args = array( 404 'user_id' => $u3, 405 'inviter_id' => $u1, 406 'item_id' => 4, 407 ); 408 $i2 = $invites_class->add_invitation( $i2_args ); 409 $invites_class->send_invitation_by_id( $i2 ); 410 411 $i3_args = array( 412 'user_id' => $u2, 413 'inviter_id' => $u1, 414 'item_id' => 8, 415 ); 416 $i3 = $invites_class->add_invitation( $i3_args ); 417 $invites_class->send_invitation_by_id( $i3 ); 418 419 $get_invites = array( 420 'order_by' => 'item_id', 421 'sort_order' => 'ASC', 422 'fields' => 'ids', 423 ); 424 $invites = $invites_class->get_invitations( $get_invites ); 425 $this->assertEquals( array( $i2, $i1, $i3 ), $invites ); 426 427 $get_invites['sort_order'] = 'DESC'; 428 $invites = $invites_class->get_invitations( $get_invites ); 429 $this->assertEquals( array( $i3, $i1, $i2 ), $invites ); 430 431 $this->set_current_user( $old_current_user ); 432 } 433 }
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 |