[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @group activity 4 */ 5 class BP_Tests_Activity_Template extends BP_UnitTestCase { 6 7 /** 8 * @ticket BP4735 9 */ 10 public function test_user_can_delete() { 11 $bp = buddypress(); 12 $u = self::factory()->user->create(); 13 $original_user = bp_loggedin_user_id(); 14 $this->set_current_user( $u ); 15 16 $a = self::factory()->activity->create( array( 17 'type' => 'activity_update', 18 'user_id' => $u, 19 ) ); 20 21 // User can delete his own items 22 $activity = self::factory()->activity->get_object_by_id( $a ); 23 $this->assertTrue( bp_activity_user_can_delete( $activity ) ); 24 25 // Logged-out user can't delete 26 $this->set_current_user( 0 ); 27 $this->assertFalse( bp_activity_user_can_delete( $activity ) ); 28 29 // Miscellaneous user can't delete 30 $misc_user = self::factory()->user->create( array( 'role' => 'subscriber' ) ); 31 $this->set_current_user( $misc_user ); 32 $this->assertFalse( bp_activity_user_can_delete( $activity ) ); 33 34 // Item admin can delete 35 $is_single_item = $bp->is_single_item; 36 $bp->is_single_item = true; 37 38 $is_item_admin = $bp->is_item_admin; 39 $bp->is_item_admin = true; 40 41 $this->assertTrue( bp_activity_user_can_delete( $activity ) ); 42 43 $bp->is_single_item = $is_single_item; 44 $bp->is_item_admin = $is_item_admin; 45 $this->set_current_user( $original_user ); 46 } 47 48 /** 49 * Test if a non-admin can delete their own activity. 50 */ 51 public function test_user_can_delete_for_nonadmin() { 52 // save the current user and override logged-in user 53 $old_user = get_current_user_id(); 54 $u = self::factory()->user->create(); 55 $this->set_current_user( $u ); 56 57 // create an activity update for the user 58 self::factory()->activity->create( array( 59 'component' => buddypress()->activity->id, 60 'type' => 'activity_update', 61 'user_id' => $u, 62 ) ); 63 64 // start the activity loop 65 bp_has_activities( array( 'user_id' => $u ) ); 66 while ( bp_activities() ) : bp_the_activity(); 67 // assert! 68 $this->assertTrue( bp_activity_user_can_delete() ); 69 endwhile; 70 71 // reset 72 $this->set_current_user( $old_user ); 73 } 74 75 /** 76 * Make sure that action filters ('activity_update', etc) work when 77 * limiting query to user favorites 78 * 79 * @ticket BP4872 80 * @group scope 81 */ 82 public function test_bp_has_activities_favorites_action_filter() { 83 $user_id = self::factory()->user->create( array( 'role' => 'subscriber' ) ); 84 85 $now = time(); 86 87 $a1 = self::factory()->activity->create( array( 88 'type' => 'activity_update', 89 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 90 ) ); 91 92 $a2 = self::factory()->activity->create( array( 93 'type' => 'joined_group', 94 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 95 ) ); 96 97 $current_user = bp_loggedin_user_id(); 98 $this->set_current_user( $user_id ); 99 100 bp_activity_add_user_favorite( $a1, $user_id ); 101 bp_activity_add_user_favorite( $a2, $user_id ); 102 103 $this->set_current_user( $current_user ); 104 105 // groan. It sucks that you have to invoke the global 106 global $activities_template; 107 108 // Case 1: no action filter 109 bp_has_activities( array( 110 'user_id' => $user_id, 111 'scope' => 'favorites', 112 ) ); 113 114 // The formatting of $activities_template->activities is messed 115 // up, so we're just going to look at the IDs. This should be 116 // fixed in BP at some point 117 $ids = wp_list_pluck( $activities_template->activities, 'id' ); 118 119 $this->assertEquals( array( $a1, $a2 ), $ids ); 120 121 $activities_template = null; 122 123 // Case 2: action filter 124 bp_has_activities( array( 125 'user_id' => $user_id, 126 'scope' => 'favorites', 127 'action' => 'activity_update', 128 ) ); 129 130 $ids = wp_list_pluck( $activities_template->activities, 'id' ); 131 132 $this->assertEquals( array( $a1 ), $ids ); 133 134 $activities_template = null; 135 } 136 137 /** 138 * @group scope 139 * @group filter_query 140 * @group BP_Activity_Query 141 */ 142 function test_bp_has_activities_just_me_scope_with_no_user_id() { 143 $u1 = self::factory()->user->create(); 144 $u2 = self::factory()->user->create(); 145 146 // save the current user and override logged-in user 147 $old_user = get_current_user_id(); 148 $this->set_current_user( $u1 ); 149 150 $now = time(); 151 152 // activity item 153 $a1 = self::factory()->activity->create( array( 154 'user_id' => $u1, 155 'component' => 'activity', 156 'type' => 'activity_update', 157 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 158 ) ); 159 160 // misc activity items 161 162 self::factory()->activity->create( array( 163 'user_id' => $u2, 164 'component' => 'activity', 165 'type' => 'activity_update', 166 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 167 ) ); 168 self::factory()->activity->create( array( 169 'user_id' => $u2, 170 'component' => 'groups', 171 'item_id' => 324, 172 'type' => 'activity_update', 173 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 174 ) ); 175 176 global $activities_template; 177 178 // grab just-me scope with no user ID 179 // user ID should fallback to logged-in user ID 180 bp_has_activities( array( 181 'user_id' => false, 182 'scope' => 'just-me', 183 ) ); 184 185 // assert! 186 $this->assertEqualSets( array( $a1 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 187 188 // clean up! 189 $activities_template = null; 190 $this->set_current_user( $old_user ); 191 } 192 193 /** 194 * @group scope 195 * @group filter_query 196 * @group BP_Activity_Query 197 */ 198 function test_bp_has_activities_mentions_scope() { 199 $u1 = self::factory()->user->create(); 200 $u2 = self::factory()->user->create(); 201 202 $now = time(); 203 204 // mentioned activity item 205 $mention_username = '@' . bp_activity_get_user_mentionname( $u1 ); 206 $a1 = self::factory()->activity->create( array( 207 'user_id' => $u2, 208 'type' => 'activity_update', 209 'content' => "{$mention_username} - You rule, dude!", 210 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 211 ) ); 212 213 // misc activity items 214 self::factory()->activity->create( array( 215 'user_id' => $u1, 216 'component' => 'blogs', 217 'item_id' => 1, 218 'type' => 'new_blog_post', 219 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 220 ) ); 221 self::factory()->activity->create( array( 222 'user_id' => $u2, 223 'component' => 'activity', 224 'type' => 'activity_update', 225 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 226 ) ); 227 self::factory()->activity->create( array( 228 'user_id' => $u2, 229 'component' => 'groups', 230 'item_id' => 324, 231 'type' => 'activity_update', 232 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 233 ) ); 234 235 global $activities_template; 236 237 // grab activities from multiple scopes 238 bp_has_activities( array( 239 'user_id' => $u1, 240 'scope' => 'mentions', 241 ) ); 242 243 // assert! 244 $this->assertEqualSets( array( $a1 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 245 246 // clean up! 247 $activities_template = null; 248 } 249 250 /** 251 * @group scope 252 * @group filter_query 253 * @group BP_Activity_Query 254 */ 255 function test_bp_has_activities_friends_and_mentions_scope() { 256 $u1 = self::factory()->user->create(); 257 $u2 = self::factory()->user->create(); 258 $u3 = self::factory()->user->create(); 259 260 // user 1 becomes friends with user 2 261 friends_add_friend( $u1, $u2, true ); 262 263 $now = time(); 264 265 // friend status update 266 $a1 = self::factory()->activity->create( array( 267 'user_id' => $u2, 268 'type' => 'activity_update', 269 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 270 ) ); 271 272 // mentioned item by non-friend 273 $mention_username = '@' . bp_activity_get_user_mentionname( $u1 ); 274 $a2 = self::factory()->activity->create( array( 275 'user_id' => $u3, 276 'component' => 'activity', 277 'type' => 'activity_update', 278 'content' => "{$mention_username} - Oy!", 279 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 280 ) ); 281 282 // misc activity items 283 self::factory()->activity->create( array( 284 'user_id' => $u1, 285 'component' => 'blogs', 286 'item_id' => 1, 287 'type' => 'new_blog_post', 288 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 289 ) ); 290 self::factory()->activity->create( array( 291 'user_id' => $u3, 292 'component' => 'activity', 293 'type' => 'activity_update', 294 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 295 ) ); 296 self::factory()->activity->create( array( 297 'user_id' => $u3, 298 'component' => 'groups', 299 'item_id' => 324, 300 'type' => 'activity_update', 301 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 302 ) ); 303 304 global $activities_template; 305 306 // grab activities from multiple scopes 307 bp_has_activities( array( 308 'user_id' => $u1, 309 'scope' => 'mentions,friends', 310 ) ); 311 312 // assert! 313 $this->assertEqualSets( array( $a1, $a2 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 314 315 // clean up! 316 $activities_template = null; 317 } 318 319 /** 320 * @group scope 321 * @group filter_query 322 * @group BP_Activity_Query 323 */ 324 function test_bp_has_activities_groups_and_friends_scope() { 325 $u1 = self::factory()->user->create(); 326 $u2 = self::factory()->user->create(); 327 $u3 = self::factory()->user->create(); 328 329 // user 1 becomes friends with user 2 330 friends_add_friend( $u1, $u2, true ); 331 332 // user 1 joins a group 333 $g1 = self::factory()->group->create( array( 'creator_id' => $u1 ) ); 334 $g2 = self::factory()->group->create( array( 'creator_id' => $u1 ) ); 335 336 $now = time(); 337 338 // friend status update 339 $a1 = self::factory()->activity->create( array( 340 'user_id' => $u2, 341 'type' => 'activity_update', 342 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 343 ) ); 344 345 // group activity 346 $a2 = self::factory()->activity->create( array( 347 'user_id' => $u3, 348 'component' => 'groups', 349 'item_id' => $g1, 350 'type' => 'joined_group', 351 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 352 ) ); 353 354 // misc activity items 355 self::factory()->activity->create( array( 356 'user_id' => $u3, 357 'component' => 'blogs', 358 'item_id' => 1, 359 'type' => 'new_blog_post', 360 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 361 ) ); 362 self::factory()->activity->create( array( 363 'user_id' => $u3, 364 'component' => 'activity', 365 'type' => 'activity_update', 366 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 367 ) ); 368 369 // Make sure we get a fake group ID. 370 global $wpdb, $bp; 371 $max_group_id = $wpdb->get_var( "SELECT id FROM {$bp->groups->table_name} ORDER BY id DESC LIMIT 1" ); 372 self::factory()->activity->create( array( 373 'user_id' => $u3, 374 'component' => 'groups', 375 'item_id' => $max_group_id + 1, 376 'type' => 'activity_update', 377 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 378 ) ); 379 380 global $activities_template; 381 382 // grab activities from multiple scopes 383 bp_has_activities( array( 384 'user_id' => $u1, 385 'scope' => 'groups,friends', 386 ) ); 387 388 // assert! 389 $this->assertEqualSets( array( $a1, $a2 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 390 391 // clean up! 392 $activities_template = null; 393 } 394 395 /** 396 * @group scope 397 * @group filter_query 398 * @group BP_Activity_Query 399 */ 400 function test_bp_has_activities_scope_friends_no_items() { 401 $u1 = self::factory()->user->create(); 402 403 $now = time(); 404 405 // Create a random activity 406 self::factory()->activity->create( array( 407 'user_id' => $u1, 408 'type' => 'activity_update', 409 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 410 ) ); 411 412 global $activities_template; 413 $reset_activities_template = $activities_template; 414 415 // grab activities from friends scope 416 bp_has_activities( array( 417 'user_id' => $u1, 418 'scope' => 'friends', 419 ) ); 420 421 // assert! 422 $this->assertEmpty( $activities_template->activities, 'When a user does not have any friendship, no activities should be fetched when on friends scope' ); 423 424 // clean up! 425 $activities_template = $reset_activities_template; 426 } 427 428 /** 429 * @group scope 430 * @group filter_query 431 * @group BP_Activity_Query 432 */ 433 function test_bp_has_activities_scope_favorites_no_items() { 434 $u1 = self::factory()->user->create(); 435 436 $now = time(); 437 438 // Create a random activity 439 self::factory()->activity->create( array( 440 'user_id' => $u1, 441 'type' => 'activity_update', 442 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 443 ) ); 444 445 global $activities_template; 446 $reset_activities_template = $activities_template; 447 448 // grab activities from favorites scope 449 bp_has_activities( array( 450 'user_id' => $u1, 451 'scope' => 'favorites', 452 ) ); 453 454 // assert! 455 $this->assertEmpty( $activities_template->activities, 'When a user has not favorited any activity, no activities should be fetched when on favorites scope' ); 456 457 // clean up! 458 $activities_template = $reset_activities_template; 459 } 460 461 /** 462 * @group scope 463 * @group filter_query 464 * @group BP_Activity_Query 465 */ 466 function test_bp_has_activities_scope_groups_no_items() { 467 $u1 = self::factory()->user->create(); 468 469 $now = time(); 470 471 // Create a random activity 472 self::factory()->activity->create( array( 473 'user_id' => $u1, 474 'type' => 'activity_update', 475 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 476 ) ); 477 478 global $activities_template; 479 $reset_activities_template = $activities_template; 480 481 // grab activities from groups scope 482 bp_has_activities( array( 483 'user_id' => $u1, 484 'scope' => 'groups', 485 ) ); 486 487 // assert! 488 $this->assertEmpty( $activities_template->activities, 'When a user is not a member of any group, no activities should be fetched when on groups scope' ); 489 490 // clean up! 491 $activities_template = $reset_activities_template; 492 } 493 494 /** 495 * @group scope 496 * @group filter_query 497 * @group BP_Activity_Query 498 */ 499 function test_bp_has_activities_scope_mentions_no_items() { 500 $u1 = self::factory()->user->create(); 501 502 $now = time(); 503 504 // Create a random activity 505 self::factory()->activity->create( array( 506 'user_id' => $u1, 507 'type' => 'activity_update', 508 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 509 ) ); 510 511 global $activities_template; 512 $reset_activities_template = $activities_template; 513 514 // grab activities from mentions scope 515 bp_has_activities( array( 516 'user_id' => $u1, 517 'scope' => 'mentions', 518 ) ); 519 520 // assert! 521 $this->assertEmpty( $activities_template->activities, 'When a user has no mention, no activities should be fetched when on the mentions scope' ); 522 523 // clean up! 524 $activities_template = $reset_activities_template; 525 } 526 527 /** 528 * @group scope 529 * @ticket BP6720 530 */ 531 public function test_bp_has_activities_scope_friends_should_respect_id_order_when_record_dates_are_same() { 532 $u1 = self::factory()->user->create(); 533 $u2 = self::factory()->user->create(); 534 535 friends_add_friend( $u1, $u2, true ); 536 537 // Friend's very fast status updates. 538 $a1 = self::factory()->activity->create( array( 539 'user_id' => $u2, 540 'type' => 'activity_update', 541 'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ), 542 ) ); 543 $a2 = self::factory()->activity->create( array( 544 'user_id' => $u2, 545 'type' => 'activity_update', 546 'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ), 547 ) ); 548 549 global $activities_template; 550 $reset_activities_template = $activities_template; 551 552 // Get activities in 'friends' scope 553 bp_has_activities( array( 554 'user_id' => $u1, 555 'scope' => 'friends', 556 ) ); 557 558 $found = $activities_template->activities; 559 560 // Clean up! 561 $activities_template = $reset_activities_template; 562 563 $this->assertEquals( array( $a2, $a1 ), wp_list_pluck( $found, 'id' ) ); 564 } 565 566 /** 567 * @group scope 568 * @ticket BP6720 569 */ 570 public function test_bp_has_activities_scope_groups_should_respect_id_order_when_record_dates_are_same() { 571 $u1 = self::factory()->user->create(); 572 $u2 = self::factory()->user->create(); 573 $u3 = self::factory()->user->create(); 574 575 $g1 = self::factory()->group->create( array( 'creator_id' => $u1 ) ); 576 577 // Two user join first user's group same time 578 $a1 = self::factory()->activity->create( array( 579 'user_id' => $u2, 580 'component' => 'groups', 581 'item_id' => $g1, 582 'type' => 'joined_group', 583 'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ), 584 ) ); 585 $a2 = self::factory()->activity->create( array( 586 'user_id' => $u3, 587 'component' => 'groups', 588 'item_id' => $g1, 589 'type' => 'joined_group', 590 'recorded_time' => date( 'Y-m-d H:i:s', 1451944920 ), 591 ) ); 592 593 global $activities_template; 594 $reset_activities_template = $activities_template; 595 596 // Get activities in 'groups' scope 597 bp_has_activities( array( 598 'user_id' => $u1, 599 'scope' => 'groups', 600 ) ); 601 602 $found = $activities_template->activities; 603 604 // Clean up! 605 $activities_template = $reset_activities_template; 606 607 $this->assertEquals( array( $a2, $a1 ), wp_list_pluck( $found, 'id' ) ); 608 } 609 610 /** 611 * @group filter_query 612 * @group BP_Activity_Query 613 */ 614 function test_bp_has_activities_with_filter_query_nested_conditions() { 615 $u1 = self::factory()->user->create(); 616 $u2 = self::factory()->user->create(); 617 $u3 = self::factory()->user->create(); 618 619 $now = time(); 620 621 $a1 = self::factory()->activity->create( array( 622 'user_id' => $u3, 623 'component' => 'blogs', 624 'item_id' => 1, 625 'type' => 'new_blog_post', 626 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 627 ) ); 628 $a2 = self::factory()->activity->create( array( 629 'user_id' => $u2, 630 'component' => 'activity', 631 'type' => 'activity_update', 632 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 633 ) ); 634 635 // misc activity items 636 self::factory()->activity->create( array( 637 'user_id' => $u3, 638 'component' => 'activity', 639 'type' => 'activity_update', 640 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 641 ) ); 642 self::factory()->activity->create( array( 643 'user_id' => $u3, 644 'component' => 'groups', 645 'item_id' => 324, 646 'type' => 'activity_update', 647 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 648 ) ); 649 650 global $activities_template; 651 652 bp_has_activities( array( 653 'filter_query' => array( 654 'relation' => 'OR', 655 array( 656 'column' => 'component', 657 'value' => 'blogs', 658 ), 659 array( 660 'relation' => 'AND', 661 array( 662 'column' => 'type', 663 'value' => 'activity_update', 664 ), 665 array( 666 'column' => 'user_id', 667 'value' => $u2, 668 ), 669 ), 670 ) 671 ) ); 672 673 // assert! 674 $this->assertEqualSets( array( $a1, $a2 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 675 676 // clean up! 677 $activities_template = null; 678 } 679 680 /** 681 * @group filter_query 682 * @group BP_Activity_Query 683 */ 684 function test_bp_has_activities_with_filter_query_compare_not_in_operator() { 685 $u1 = self::factory()->user->create(); 686 $u2 = self::factory()->user->create(); 687 $u3 = self::factory()->user->create(); 688 689 $now = time(); 690 691 // misc activity items 692 $a1 = self::factory()->activity->create( array( 693 'user_id' => $u3, 694 'component' => 'blogs', 695 'item_id' => 1, 696 'type' => 'new_blog_post', 697 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 698 ) ); 699 $a2 = self::factory()->activity->create( array( 700 'user_id' => $u2, 701 'component' => 'activity', 702 'type' => 'activity_update', 703 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 704 ) ); 705 $a3 = self::factory()->activity->create( array( 706 'user_id' => $u3, 707 'component' => 'activity', 708 'type' => 'activity_update', 709 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 710 ) ); 711 $a4 = self::factory()->activity->create( array( 712 'user_id' => $u3, 713 'component' => 'groups', 714 'item_id' => 324, 715 'type' => 'activity_update', 716 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 717 ) ); 718 719 global $activities_template; 720 721 bp_has_activities( array( 722 'filter_query' => array( 723 array( 724 'column' => 'id', 725 'compare' => 'NOT IN', 726 'value' => array( $a1, $a4 ), 727 ), 728 ) 729 ) ); 730 731 // assert! 732 $this->assertEqualSets( array( $a2, $a3 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 733 734 // clean up! 735 $activities_template = null; 736 } 737 738 /** 739 * @group filter_query 740 * @group BP_Activity_Query 741 */ 742 function test_bp_has_activities_with_filter_query_compare_between_operator() { 743 $u1 = self::factory()->user->create(); 744 745 $now = time(); 746 747 // misc activity items 748 $a1 = self::factory()->activity->create( array( 749 'user_id' => $u1, 750 'component' => 'blogs', 751 'item_id' => 1, 752 'type' => 'new_blog_post', 753 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 754 ) ); 755 $a2 = self::factory()->activity->create( array( 756 'user_id' => $u1, 757 'component' => 'activity', 758 'type' => 'activity_update', 759 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 760 ) ); 761 $a3 = self::factory()->activity->create( array( 762 'user_id' => $u1, 763 'component' => 'activity', 764 'type' => 'activity_update', 765 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 766 ) ); 767 $a4 = self::factory()->activity->create( array( 768 'user_id' => $u1, 769 'component' => 'groups', 770 'item_id' => 324, 771 'type' => 'activity_update', 772 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 773 ) ); 774 775 global $activities_template; 776 777 bp_has_activities( array( 778 'filter_query' => array( 779 array( 780 'column' => 'id', 781 'compare' => 'BETWEEN', 782 'value' => array( $a3, $a4 ), 783 ), 784 ) 785 ) ); 786 787 // assert! 788 $this->assertEqualSets( array( $a3, $a4 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 789 790 // clean up! 791 $activities_template = null; 792 } 793 794 /** 795 * @group filter_query 796 * @group BP_Activity_Query 797 */ 798 function test_bp_has_activities_with_filter_query_compare_arithmetic_comparisons() { 799 $u1 = self::factory()->user->create(); 800 801 $now = time(); 802 803 // misc activity items 804 $a1 = self::factory()->activity->create( array( 805 'user_id' => $u1, 806 'component' => 'activity', 807 'item_id' => 1, 808 'type' => 'activity_update', 809 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 810 ) ); 811 $a2 = self::factory()->activity->create( array( 812 'user_id' => $u1, 813 'component' => 'activity', 814 'item_id' => 10, 815 'type' => 'activity_update', 816 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 817 ) ); 818 $a3 = self::factory()->activity->create( array( 819 'user_id' => $u1, 820 'component' => 'activity', 821 'item_id' => 25, 822 'type' => 'activity_update', 823 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 824 ) ); 825 $a4 = self::factory()->activity->create( array( 826 'user_id' => $u1, 827 'component' => 'activity', 828 'item_id' => 100, 829 'type' => 'activity_update', 830 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 831 ) ); 832 833 global $activities_template; 834 835 // greater than 836 bp_has_activities( array( 837 'filter_query' => array( 838 array( 839 'column' => 'item_id', 840 'compare' => '>', 841 'value' => 10, 842 ), 843 ) 844 ) ); 845 846 // assert! 847 $this->assertEqualSets( array( $a3, $a4 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 848 849 // greater or equal than 850 bp_has_activities( array( 851 'filter_query' => array( 852 array( 853 'column' => 'item_id', 854 'compare' => '>=', 855 'value' => 10, 856 ), 857 ) 858 ) ); 859 860 // assert! 861 $this->assertEqualSets( array( $a2, $a3, $a4 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 862 863 // less than 864 bp_has_activities( array( 865 'filter_query' => array( 866 array( 867 'column' => 'item_id', 868 'compare' => '<', 869 'value' => 10, 870 ), 871 ) 872 ) ); 873 874 // assert! 875 $this->assertEqualSets( array( $a1 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 876 877 // less or equal than 878 bp_has_activities( array( 879 'filter_query' => array( 880 array( 881 'column' => 'item_id', 882 'compare' => '<=', 883 'value' => 10, 884 ), 885 ) 886 ) ); 887 888 // assert! 889 $this->assertEqualSets( array( $a1, $a2 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 890 891 // not equal to 892 bp_has_activities( array( 893 'filter_query' => array( 894 array( 895 'column' => 'item_id', 896 'compare' => '!=', 897 'value' => 10, 898 ), 899 ) 900 ) ); 901 902 // assert! 903 $this->assertEqualSets( array( $a1, $a3, $a4 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 904 905 // clean up! 906 $activities_template = null; 907 } 908 909 /** 910 * @group filter_query 911 * @group BP_Activity_Query 912 * @group post_type_comment_activities 913 */ 914 function test_bp_has_activities_with_filter_query_compare_regex() { 915 $u1 = self::factory()->user->create(); 916 917 $now = time(); 918 919 // misc activity items 920 $a1 = self::factory()->activity->create( array( 921 'user_id' => $u1, 922 'component' => 'blogs', 923 'item_id' => 1, 924 'type' => 'new_blog_post', 925 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 926 ) ); 927 $a2 = self::factory()->activity->create( array( 928 'user_id' => $u1, 929 'component' => 'blogs', 930 'type' => 'new_blog_comment', 931 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 932 ) ); 933 $a3 = self::factory()->activity->create( array( 934 'user_id' => $u1, 935 'component' => 'activity', 936 'type' => 'activity_update', 937 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 938 ) ); 939 $a4 = self::factory()->activity->create( array( 940 'user_id' => $u1, 941 'component' => 'groups', 942 'item_id' => 324, 943 'type' => 'activity_update', 944 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 945 ) ); 946 947 global $activities_template; 948 949 // REGEXP 950 bp_has_activities( array( 951 'filter_query' => array( 952 array( 953 'column' => 'type', 954 'compare' => 'REGEXP', 955 'value' => '^new_blog_', 956 ), 957 ) 958 ) ); 959 960 // assert! 961 $this->assertEqualSets( array( $a1, $a2 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 962 963 // RLIKE is a synonym for REGEXP 964 bp_has_activities( array( 965 'filter_query' => array( 966 array( 967 'column' => 'type', 968 'compare' => 'RLIKE', 969 'value' => '^new_blog_', 970 ), 971 ) 972 ) ); 973 974 // assert! 975 $this->assertEqualSets( array( $a1, $a2 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 976 977 // NOT REGEXP 978 bp_has_activities( array( 979 'filter_query' => array( 980 array( 981 'column' => 'type', 982 'compare' => 'NOT REGEXP', 983 'value' => '^new_blog_', 984 ), 985 ) 986 ) ); 987 988 // assert! 989 $this->assertEqualSets( array( $a3, $a4 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 990 991 // clean up! 992 $activities_template = null; 993 } 994 995 /** 996 * @ticket BP6169 997 * @group bp_has_activities 998 */ 999 public function test_bp_has_activities_private_group_home_scope() { 1000 global $activities_template; 1001 $bp = buddypress(); 1002 $reset_current_group = $bp->groups->current_group; 1003 $reset_current_action = $bp->current_action; 1004 1005 $u1 = self::factory()->user->create(); 1006 $u2 = self::factory()->user->create(); 1007 $u3 = self::factory()->user->create(); 1008 1009 $this->set_current_user( $u1 ); 1010 1011 $g = self::factory()->group->create( array( 1012 'status' => 'private', 1013 ) ); 1014 1015 groups_join_group( $g, $u2 ); 1016 groups_join_group( $g, $u3 ); 1017 1018 $a1 = self::factory()->activity->create( array( 1019 'component' => $bp->groups->id, 1020 'item_id' => $g, 1021 'type' => 'activity_update', 1022 'user_id' => $u2, 1023 'content' => 'foo bar', 1024 ) ); 1025 1026 $a2 = self::factory()->activity->create( array( 1027 'component' => $bp->groups->id, 1028 'item_id' => $g, 1029 'type' => 'activity_update', 1030 'user_id' => $u3, 1031 'content' => 'bar foo', 1032 ) ); 1033 1034 $bp->groups->current_group = groups_get_group( $g ); 1035 1036 // On group's home the scope is set to 'home' 1037 $bp->current_action = 'home'; 1038 1039 bp_has_activities( array( 'action' => 'activity_update' ) ); 1040 1041 $this->assertEqualSets( array( $a1, $a2 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 1042 1043 // clean up! 1044 $activities_template = null; 1045 $bp->groups->current_group = $reset_current_group; 1046 $bp->current_action = $reset_current_action; 1047 } 1048 1049 /** 1050 * @ticket BP6169 1051 * @group bp_has_activities 1052 */ 1053 public function test_bp_has_activities_hidden_group_home_scope() { 1054 global $activities_template; 1055 $bp = buddypress(); 1056 $reset_current_group = $bp->groups->current_group; 1057 $reset_current_action = $bp->current_action; 1058 1059 $u1 = self::factory()->user->create(); 1060 $u2 = self::factory()->user->create(); 1061 $u3 = self::factory()->user->create(); 1062 1063 $this->set_current_user( $u1 ); 1064 1065 $g = self::factory()->group->create( array( 1066 'status' => 'hidden', 1067 ) ); 1068 1069 groups_join_group( $g, $u2 ); 1070 groups_join_group( $g, $u3 ); 1071 1072 $a1 = self::factory()->activity->create( array( 1073 'component' => $bp->groups->id, 1074 'item_id' => $g, 1075 'type' => 'activity_update', 1076 'user_id' => $u2, 1077 'content' => 'foo bar', 1078 ) ); 1079 1080 $a2 = self::factory()->activity->create( array( 1081 'component' => $bp->groups->id, 1082 'item_id' => $g, 1083 'type' => 'activity_update', 1084 'user_id' => $u3, 1085 'content' => 'bar foo', 1086 ) ); 1087 1088 $bp->groups->current_group = groups_get_group( $g ); 1089 1090 // On group's home the scope is set to 'home' 1091 $bp->current_action = 'home'; 1092 1093 bp_has_activities( array( 'action' => 'activity_update' ) ); 1094 1095 $this->assertEqualSets( array( $a1, $a2 ), wp_list_pluck( $activities_template->activities, 'id' ) ); 1096 1097 // clean up! 1098 $activities_template = null; 1099 $bp->groups->current_group = $reset_current_group; 1100 $bp->current_action = $reset_current_action; 1101 } 1102 1103 /** 1104 * Integration test for 'meta_query' param 1105 */ 1106 function test_bp_has_activities_with_meta_query() { 1107 $a1 = self::factory()->activity->create(); 1108 $a2 = self::factory()->activity->create(); 1109 bp_activity_update_meta( $a1, 'foo', 'bar' ); 1110 1111 global $activities_template; 1112 bp_has_activities( array( 1113 'meta_query' => array( 1114 array( 1115 'key' => 'foo', 1116 'value' => 'bar', 1117 ), 1118 ), 1119 ) ); 1120 1121 $ids = wp_list_pluck( $activities_template->activities, 'id' ); 1122 $this->assertEquals( $ids, array( $a1 ) ); 1123 } 1124 1125 /** 1126 * @ticket BP5029 1127 * @group bp_has_activities 1128 */ 1129 public function test_bp_has_activities_with_display_comments_false() { 1130 $now = time(); 1131 $a1 = self::factory()->activity->create( array( 1132 'content' => 'Life Rules', 1133 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 1134 ) ); 1135 $a2 = self::factory()->activity->create( array( 1136 'content' => 'Life Drools', 1137 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 1138 ) ); 1139 $a3 = bp_activity_new_comment( array( 1140 'activity_id' => $a1, 1141 'content' => 'Candy is good', 1142 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 1143 ) ); 1144 1145 global $activities_template; 1146 bp_has_activities( array( 1147 'display_comments' => false, 1148 ) ); 1149 $ids = wp_list_pluck( $activities_template->activities, 'id' ); 1150 1151 $this->assertEquals( array( $a1, $a2 ), wp_parse_id_list( $ids ) ); 1152 1153 } 1154 1155 /** 1156 * @ticket BP5029 1157 * @group bp_has_activities 1158 */ 1159 public function test_bp_has_activities_with_display_comments_0() { 1160 $now = time(); 1161 $a1 = self::factory()->activity->create( array( 1162 'content' => 'Life Rules', 1163 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 1164 ) ); 1165 $a2 = self::factory()->activity->create( array( 1166 'content' => 'Life Drools', 1167 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 1168 ) ); 1169 $a3 = bp_activity_new_comment( array( 1170 'activity_id' => $a1, 1171 'content' => 'Candy is good', 1172 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 1173 ) ); 1174 1175 global $activities_template; 1176 bp_has_activities( array( 1177 'display_comments' => 0, 1178 ) ); 1179 $ids = wp_list_pluck( $activities_template->activities, 'id' ); 1180 1181 $this->assertEquals( array( $a1, $a2 ), wp_parse_id_list( $ids ) ); 1182 1183 } 1184 1185 /** 1186 * @ticket BP5029 1187 * @group bp_has_activities 1188 */ 1189 public function test_bp_has_activities_with_display_comments_0_querystring() { 1190 $now = time(); 1191 $a1 = self::factory()->activity->create( array( 1192 'content' => 'Life Rules', 1193 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 1194 ) ); 1195 $a2 = self::factory()->activity->create( array( 1196 'content' => 'Life Drools', 1197 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 1198 ) ); 1199 $a3 = bp_activity_new_comment( array( 1200 'activity_id' => $a1, 1201 'content' => 'Candy is good', 1202 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 1203 ) ); 1204 1205 global $activities_template; 1206 bp_has_activities( 'display_comments=0' ); 1207 $ids = wp_list_pluck( $activities_template->activities, 'id' ); 1208 1209 $this->assertEquals( array( $a1, $a2 ), $ids ); 1210 1211 } 1212 1213 /** 1214 * @ticket BP5029 1215 * @group bp_has_activities 1216 */ 1217 public function test_bp_has_activities_with_display_comments_none_querystring() { 1218 $now = time(); 1219 $a1 = self::factory()->activity->create( array( 1220 'content' => 'Life Rules', 1221 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 1222 ) ); 1223 $a2 = self::factory()->activity->create( array( 1224 'content' => 'Life Drools', 1225 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 1226 ) ); 1227 $a3 = bp_activity_new_comment( array( 1228 'activity_id' => $a1, 1229 'content' => 'Candy is good', 1230 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 1231 ) ); 1232 1233 global $activities_template; 1234 bp_has_activities( 'display_comments=none' ); 1235 $ids = wp_list_pluck( $activities_template->activities, 'id' ); 1236 1237 $this->assertEquals( array( $a1, $a2 ), $ids ); 1238 1239 } 1240 1241 /** 1242 * @group bp_has_activities 1243 * @group cache 1244 */ 1245 public function test_bp_has_activities_with_update_meta_cache_false() { 1246 $now = time(); 1247 $a1 = self::factory()->activity->create( array( 1248 'content' => 'Life Rules', 1249 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 1250 ) ); 1251 $a2 = self::factory()->activity->create( array( 1252 'content' => 'Life Drools', 1253 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 1254 ) ); 1255 1256 bp_activity_add_meta( $a1, 'foo', 'bar' ); 1257 bp_activity_add_meta( $a2, 'foo1', 'bar2' ); 1258 1259 // prime 1260 bp_has_activities( array( 1261 'update_meta_cache' => false, 1262 ) ); 1263 1264 $this->assertFalse( wp_cache_get( $a1, 'activity_meta' ) ); 1265 $this->assertFalse( wp_cache_get( $a2, 'activity_meta' ) ); 1266 } 1267 1268 /** 1269 * @group bp_has_activities 1270 * @group cache 1271 */ 1272 public function test_bp_has_activities_with_update_meta_cache_true() { 1273 $now = time(); 1274 $a1 = self::factory()->activity->create( array( 1275 'content' => 'Life Rules', 1276 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 1277 ) ); 1278 $a2 = self::factory()->activity->create( array( 1279 'content' => 'Life Drools', 1280 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 1281 ) ); 1282 1283 bp_activity_add_meta( $a1, 'foo', 'bar' ); 1284 bp_activity_add_meta( $a2, 'foo1', 'bar2' ); 1285 1286 // prime 1287 bp_has_activities( array( 1288 'update_meta_cache' => true, 1289 ) ); 1290 1291 $this->assertNotEmpty( wp_cache_get( $a1, 'activity_meta' ) ); 1292 $this->assertNotEmpty( wp_cache_get( $a2, 'activity_meta' ) ); 1293 } 1294 1295 /** 1296 * @group bp_has_activities 1297 * @group post_type_comment_activities 1298 */ 1299 public function test_bp_has_activities_with_type_new_blog_comments() { 1300 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 1301 1302 $u = self::factory()->user->create(); 1303 1304 $now = time(); 1305 $a1 = self::factory()->activity->create( array( 1306 'content' => 'Life Rules', 1307 'component' => 'blogs', 1308 'type' => 'new_blog_post', 1309 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 1310 'user_id' => $u, 1311 ) ); 1312 $a2 = self::factory()->activity->create( array( 1313 'content' => 'Life Drools', 1314 'component' => 'blogs', 1315 'type' => 'new_blog_comment', 1316 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 1317 'user_id' => $u, 1318 ) ); 1319 1320 // This one will show up in the stream because it's a comment 1321 // on a blog post 1322 $a3 = bp_activity_new_comment( array( 1323 'activity_id' => $a1, 1324 'content' => 'Candy is good', 1325 'recorded_time' => date( 'Y-m-d H:i:s', $now - 200 ), 1326 'user_id' => $u, 1327 ) ); 1328 1329 $a4 = self::factory()->activity->create( array( 1330 'content' => 'Life Rulez', 1331 'component' => 'activity', 1332 'type' => 'activity_update', 1333 'recorded_time' => date( 'Y-m-d H:i:s', $now - 300 ), 1334 'user_id' => $u, 1335 ) ); 1336 1337 // This one should not show up in the stream because it's a 1338 // comment on an activity item 1339 $a5 = bp_activity_new_comment( array( 1340 'activity_id' => $a4, 1341 'content' => 'Candy is great', 1342 'recorded_time' => date( 'Y-m-d H:i:s', $now - 400 ), 1343 'user_id' => $u, 1344 ) ); 1345 global $activities_template; 1346 1347 // prime 1348 bp_has_activities( array( 1349 'component' => 'blogs', 1350 'action' => 'new_blog_comment', 1351 ) ); 1352 1353 $this->assertEquals( array( $a3, $a2 ), wp_parse_id_list( wp_list_pluck( $activities_template->activities, 'id' ) ) ); 1354 1355 // Clean up 1356 $activities_template = null; 1357 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 1358 } 1359 1360 /** 1361 * @group bp_activity_can_comment_reply 1362 */ 1363 public function test_bp_activity_can_comment_reply_thread_comments_on() { 1364 $tc = get_option( 'thread_comments' ); 1365 update_option( 'thread_comments', '1' ); 1366 1367 $tcd = get_option( 'thread_comments_depth' ); 1368 update_option( 'thread_comments_depth', '4' ); 1369 1370 // Fake the global 1371 global $activities_template; 1372 $activities_template = new stdClass; 1373 $activities_template->activity = new stdClass; 1374 $activities_template->activity->current_comment = new stdClass; 1375 1376 $comment = new stdClass; 1377 $comment->item_id = 4; 1378 1379 $activities_template->activity->current_comment->depth = 1; 1380 $this->assertTrue( bp_activity_can_comment_reply( $comment ) ); 1381 1382 $activities_template->activity->current_comment->depth = 3; 1383 $this->assertTrue( bp_activity_can_comment_reply( $comment ) ); 1384 1385 $activities_template->activity->current_comment->depth = 4; 1386 $this->assertFalse( bp_activity_can_comment_reply( $comment ) ); 1387 1388 $activities_template->activity->current_comment->depth = 5; 1389 $this->assertFalse( bp_activity_can_comment_reply( $comment ) ); 1390 1391 // Set right what once went wrong 1392 update_option( 'thread_comments', $tc ); 1393 update_option( 'thread_comments_depth', $tcd ); 1394 $activities_template = null; 1395 } 1396 1397 /** 1398 * @group bp_activity_can_comment_reply 1399 */ 1400 public function test_bp_activity_can_comment_reply_thread_comments_off() { 1401 $tc = get_option( 'thread_comments' ); 1402 update_option( 'thread_comments', '0' ); 1403 1404 $tcd = get_option( 'thread_comments_depth' ); 1405 update_option( 'thread_comments_depth', '4' ); 1406 1407 // Fake the global 1408 global $activities_template; 1409 $activities_template = new stdClass; 1410 $activities_template->activity = new stdClass; 1411 $activities_template->activity->current_comment = new stdClass; 1412 1413 $comment = new stdClass; 1414 $comment->item_id = 4; 1415 1416 $activities_template->activity->current_comment->depth = 1; 1417 $this->assertFalse( bp_activity_can_comment_reply( $comment ) ); 1418 1419 $activities_template->activity->current_comment->depth = 2; 1420 $this->assertFalse( bp_activity_can_comment_reply( $comment ) ); 1421 1422 // Set right what once went wrong 1423 update_option( 'thread_comments', $tc ); 1424 update_option( 'thread_comments_depth', $tcd ); 1425 $activities_template = null; 1426 } 1427 1428 /** 1429 * @group bp_activity_can_comment 1430 */ 1431 public function test_bp_activity_can_comment() { 1432 global $activities_template; 1433 $reset_activities_template = $activities_template; 1434 1435 $activities_template = new stdClass; 1436 $activities_template->disable_blogforum_replies = true; 1437 $activities_template->activity = (object) array( 'type' => 'activity_comment' ); 1438 1439 $this->assertFalse( bp_activity_can_comment(), 'bp_activity_can_comment() should return false if the activity type is activity_comment' ); 1440 1441 $types = array( 1442 'new_blog_post', 1443 'new_blog_comment', 1444 'new_forum_topic', 1445 'new_forum_post' 1446 ); 1447 1448 foreach ( $types as $type_false ) { 1449 $activities_template->activity->type = $type_false; 1450 $this->assertFalse( bp_activity_can_comment(), 'Comments about blog or forum posts/replies are disabled' ); 1451 } 1452 1453 $activities_template->disable_blogforum_replies = false; 1454 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 1455 1456 foreach ( $types as $type_true ) { 1457 $activities_template->activity->type = $type_true; 1458 $this->assertTrue( bp_activity_can_comment(), 'Comments about blog or forum posts/replies are enabled' ); 1459 } 1460 1461 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 1462 1463 // clean up! 1464 $activities_template = $reset_activities_template; 1465 } 1466 1467 /** 1468 * @group bp_activity_can_comment 1469 */ 1470 public function test_bp_activity_can_comment_post_type_activity() { 1471 global $activities_template; 1472 $bp = buddypress(); 1473 1474 $reset_activities_template = $activities_template; 1475 $reset_activity_track = $bp->activity->track; 1476 1477 $activities_template = new stdClass; 1478 $activities_template->disable_blogforum_replies = true; 1479 1480 register_post_type( 'foo', array( 1481 'label' => 'foo', 1482 'public' => true, 1483 'supports' => array( 'buddypress-activity' ), 1484 ) ); 1485 1486 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 1487 1488 $activities_template->activity = (object) array( 'type' => 'new_foo' ); 1489 1490 $this->assertTrue( bp_activity_can_comment(), 'If post type does not support comments, a post type activity can be commented' ); 1491 1492 add_post_type_support( 'foo', 'comments' ); 1493 1494 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 1495 1496 $this->assertFalse( bp_activity_can_comment(), 'If post type support comments, a post type activity cannot be commented' ); 1497 1498 $bp_activity_support = (array) $bp->activity->track['new_foo']; 1499 $bp_activity_support['activity_comment'] = true; 1500 1501 bp_activity_set_post_type_tracking_args( 'foo', $bp_activity_support ); 1502 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 1503 1504 $this->assertTrue( bp_activity_can_comment(), 'If post type supports activity comments, a post type activity can be commented' ); 1505 1506 // clean up! 1507 $activities_template = $reset_activities_template; 1508 $bp->activity->track = $reset_activity_track; 1509 } 1510 1511 /** 1512 * @group bp_activity_has_more_items 1513 */ 1514 public function test_bp_activity_has_more_items_no_count_total_false() { 1515 $a1 = self::factory()->activity->create(); 1516 $a2 = self::factory()->activity->create(); 1517 1518 $args = array( 1519 'count_total' => false, 1520 ); 1521 1522 if ( bp_has_activities( $args ) ) { 1523 global $activities_template; 1524 $this->assertFalse( bp_activity_has_more_items() ); 1525 $activities_template = null; 1526 } 1527 } 1528 1529 /** 1530 * @group bp_activity_has_more_items 1531 */ 1532 public function test_bp_activity_has_more_items_no_count_total_true() { 1533 $a1 = self::factory()->activity->create(); 1534 $a2 = self::factory()->activity->create(); 1535 $a3 = self::factory()->activity->create(); 1536 $a4 = self::factory()->activity->create(); 1537 1538 $args = array( 1539 'count_total' => false, 1540 'per_page' => 2, 1541 ); 1542 1543 if ( bp_has_activities( $args ) ) { 1544 global $activities_template; 1545 $this->assertTrue( bp_activity_has_more_items() ); 1546 $activities_template = null; 1547 } 1548 } 1549 1550 /** 1551 * @group bp_activity_has_more_items 1552 */ 1553 public function test_bp_activity_has_more_items_count_total_false() { 1554 $a1 = self::factory()->activity->create(); 1555 $a2 = self::factory()->activity->create(); 1556 $a3 = self::factory()->activity->create(); 1557 $a4 = self::factory()->activity->create(); 1558 1559 $args = array( 1560 'count_total' => 'count_query', 1561 ); 1562 1563 if ( bp_has_activities( $args ) ) { 1564 global $activities_template; 1565 $this->assertFalse( bp_activity_has_more_items() ); 1566 $activities_template = null; 1567 } 1568 } 1569 1570 /** 1571 * @group bp_activity_has_more_items 1572 */ 1573 public function test_bp_activity_has_more_items_count_total_true() { 1574 $a1 = self::factory()->activity->create(); 1575 $a2 = self::factory()->activity->create(); 1576 $a3 = self::factory()->activity->create(); 1577 $a4 = self::factory()->activity->create(); 1578 1579 $args = array( 1580 'count_total' => 'count_query', 1581 'per_page' => 2, 1582 ); 1583 1584 if ( bp_has_activities( $args ) ) { 1585 global $activities_template; 1586 $this->assertTrue( bp_activity_has_more_items() ); 1587 $activities_template = null; 1588 } 1589 } 1590 1591 /** 1592 * Integration test for 'date_query' param 1593 * 1594 * @group date_query 1595 * @requires PHP 5.3 1596 */ 1597 function test_bp_has_activities_with_date_query() { 1598 if ( ! class_exists( 'WP_Date_Query' ) ) { 1599 return; 1600 } 1601 1602 $a1 = self::factory()->activity->create(); 1603 $a2 = self::factory()->activity->create( array( 1604 'recorded_time' => '2001-01-01 12:00' 1605 ) ); 1606 $a3 = self::factory()->activity->create( array( 1607 'recorded_time' => '2005-01-01 12:00' 1608 ) ); 1609 1610 global $activities_template; 1611 bp_has_activities( array( 1612 'date_query' => array( array( 1613 'after' => '1 day ago' 1614 ) ) 1615 ) ); 1616 1617 $ids = wp_list_pluck( $activities_template->activities, 'id' ); 1618 $this->assertEquals( $ids, array( $a1 ) ); 1619 } 1620 1621 /** 1622 * @group pagination 1623 * @group BP_Activity_Template 1624 */ 1625 public function test_bp_activity_template_should_give_precedence_to_acpage_URL_param() { 1626 $request = $_REQUEST; 1627 $_REQUEST['acpage'] = '5'; 1628 1629 $at = new BP_Activity_Template( array( 1630 'page' => 8, 1631 ) ); 1632 1633 $this->assertEquals( 5, $at->pag_page ); 1634 1635 $_REQUEST = $request; 1636 } 1637 1638 /** 1639 * @group pagination 1640 * @group BP_Activity_Template 1641 */ 1642 public function test_bp_activity_template_should_reset_0_pag_page_URL_param_to_default_pag_page_value() { 1643 $request = $_REQUEST; 1644 $_REQUEST['acpage'] = '0'; 1645 1646 $at = new BP_Activity_Template( array( 1647 'page' => 8, 1648 ) ); 1649 1650 $this->assertEquals( 8, $at->pag_page ); 1651 1652 $_REQUEST = $request; 1653 } 1654 1655 /** 1656 * @group pagination 1657 * @group BP_Activity_Template 1658 */ 1659 public function test_bp_activity_template_should_give_precedence_to_num_URL_param() { 1660 $request = $_REQUEST; 1661 $_REQUEST['num'] = '14'; 1662 1663 $at = new BP_Activity_Template( array( 1664 'per_page' => 13, 1665 ) ); 1666 1667 $this->assertEquals( 14, $at->pag_num ); 1668 1669 $_REQUEST = $request; 1670 } 1671 1672 /** 1673 * @group pagination 1674 * @group BP_Activity_Template 1675 */ 1676 public function test_bp_activity_template_should_reset_0_pag_num_URL_param_to_default_pag_num_value() { 1677 $request = $_REQUEST; 1678 $_REQUEST['num'] = '0'; 1679 1680 $at = new BP_Activity_Template( array( 1681 'per_page' => 13, 1682 ) ); 1683 1684 $this->assertEquals( 13, $at->pag_num ); 1685 1686 $_REQUEST = $request; 1687 } 1688 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |