[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @group activity 4 */ 5 class BP_Tests_Activity_Class extends BP_UnitTestCase { 6 7 /** 8 * @group check_exists_by_content 9 */ 10 public function test_check_exists_by_content() { 11 $content = 'A classy girl who know how to enjoy the freedom of a cup of coffee'; 12 $activity = self::factory()->activity->create( array( 13 'content' => $content, 14 'type' => 'activity_update', 15 ) ); 16 17 $result = BP_Activity_Activity::check_exists_by_content( $content ); 18 $this->assertEquals( $activity, $result ); 19 } 20 21 /** 22 * @group delete_activity_item_comments 23 */ 24 public function test_delete_activity_item_comments() { 25 $parent_activity = self::factory()->activity->create( array( 26 'type' => 'activity_update', 27 ) ); 28 29 $comments = self::factory()->activity->create_many( 3, array( 30 'item_id' => $parent_activity, 31 'type' => 'activity_comment', 32 ) ); 33 34 BP_Activity_Activity::delete_activity_item_comments( $parent_activity ); 35 36 $result = BP_Activity_Activity::get( array( 'in' => $comments ) ); 37 $this->assertEmpty( $result['activities'] ); 38 } 39 40 /** 41 * @ticket BP4804 42 * @group delete_activity_meta_entries 43 * @group activitymeta 44 */ 45 public function test_delete_activity_meta_entries() { 46 $activity = self::factory()->activity->create( array( 47 'type' => 'activity_update', 48 ) ); 49 50 bp_activity_update_meta( $activity, 'Paul', 'is cool' ); 51 BP_Activity_Activity::delete_activity_meta_entries( $activity ); 52 53 $meta = bp_activity_get_meta( $activity, 'Paul' ); 54 $this->assertSame( '', $meta ); 55 } 56 57 /** 58 * @group get 59 * @group fields 60 * @ticket BP6426 61 */ 62 public function test_get_with_fields_parameter_by_id() { 63 $a = self::factory()->activity->create_many( 3, array( 64 'type' => 'activity_update', 65 ) ); 66 67 $result = BP_Activity_Activity::get( array( 68 'fields' => 'ids', 69 ) ); 70 $this->assertEqualSets( $a, $result['activities'] ); 71 } 72 73 /** 74 * @group get 75 */ 76 public function test_hide_all_for_user() { 77 $activity = self::factory()->activity->create( array( 78 'type' => 'activity_update', 79 ) ); 80 81 BP_Activity_Activity::hide_all_for_user( get_current_user_id() ); 82 83 $activity = BP_Activity_Activity::get( array( 84 'in' => $activity, 85 'show_hidden' => true, 86 ) ); 87 $this->assertEquals( $activity['activities'][0]->hide_sitewide, 1 ); 88 } 89 90 /** 91 * @group get 92 * @group meta_query 93 */ 94 public function test_get_with_meta_query() { 95 $a1 = self::factory()->activity->create(); 96 $a2 = self::factory()->activity->create(); 97 bp_activity_update_meta( $a1, 'foo', 'bar' ); 98 99 $activity = BP_Activity_Activity::get( array( 100 'meta_query' => array( 101 array( 102 'key' => 'foo', 103 'value' => 'bar', 104 ), 105 ), 106 ) ); 107 $ids = wp_list_pluck( $activity['activities'], 'id' ); 108 $this->assertEquals( $ids, array( $a1 ) ); 109 } 110 111 /** 112 * @group get 113 */ 114 public function test_get_with_meta_query_two_clauses_with_or_relation() { 115 $now = time(); 116 $a1 = self::factory()->activity->create( array( 117 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 118 ) ); 119 $a2 = self::factory()->activity->create( array( 120 'recorded_time' => date( 'Y-m-d H:i:s', $now - 60 ), 121 ) ); 122 $a3 = self::factory()->activity->create( array( 123 'recorded_time' => date( 'Y-m-d H:i:s', $now - 120 ), 124 ) ); 125 bp_activity_update_meta( $a1, 'foo', 'bar' ); 126 bp_activity_update_meta( $a2, 'foo', 'bar' ); 127 bp_activity_update_meta( $a1, 'baz', 'barry' ); 128 129 $activity = BP_Activity_Activity::get( array( 130 'meta_query' => array( 131 'relation' => 'OR', 132 array( 133 'key' => 'foo', 134 'value' => 'bar', 135 ), 136 array( 137 'key' => 'baz', 138 'value' => 'barry', 139 ), 140 ), 141 'count_total' => 'count_query', 142 ) ); 143 144 $ids = wp_list_pluck( $activity['activities'], 'id' ); 145 $this->assertEquals( array( $a1, $a2 ), $ids ); 146 $this->assertEquals( 2, $activity['total'] ); 147 } 148 149 /** 150 * @group get 151 * @group date_query 152 * @requires PHP 5.3 153 */ 154 public function test_get_with_date_query_before() { 155 if ( ! class_exists( 'WP_Date_Query' ) ) { 156 return; 157 } 158 159 $a1 = self::factory()->activity->create(); 160 $a2 = self::factory()->activity->create( array( 161 'recorded_time' => '2001-01-01 12:00' 162 ) ); 163 $a3 = self::factory()->activity->create( array( 164 'recorded_time' => '2005-01-01 12:00' 165 ) ); 166 167 // 'date_query' before test 168 $query = BP_Activity_Activity::get( array( 169 'date_query' => array( array( 170 'before' => array( 171 'year' => 2004, 172 'month' => 1, 173 'day' => 1, 174 ), 175 ) ) 176 ) ); 177 $this->assertEquals( array( $a2 ), wp_list_pluck( $query['activities'], 'id' ) ); 178 } 179 180 /** 181 * @group get 182 * @group date_query 183 * @requires PHP 5.3 184 */ 185 public function test_get_with_date_query_range() { 186 if ( ! class_exists( 'WP_Date_Query' ) ) { 187 return; 188 } 189 190 $a1 = self::factory()->activity->create(); 191 $a2 = self::factory()->activity->create( array( 192 'recorded_time' => '2001-01-01 12:00' 193 ) ); 194 $a3 = self::factory()->activity->create( array( 195 'recorded_time' => '2005-01-01 12:00' 196 ) ); 197 198 // 'date_query' range test 199 $query = BP_Activity_Activity::get( array( 200 'date_query' => array( array( 201 'after' => 'January 2nd, 2001', 202 'before' => array( 203 'year' => 2013, 204 'month' => 1, 205 'day' => 1, 206 ), 207 'inclusive' => true, 208 ) ) 209 ) ); 210 $this->assertEquals( array( $a3 ), wp_list_pluck( $query['activities'], 'id' ) ); 211 } 212 213 /** 214 * @group get 215 * @group date_query 216 * @requires PHP 5.3 217 */ 218 public function test_get_with_date_query_after() { 219 if ( ! class_exists( 'WP_Date_Query' ) ) { 220 return; 221 } 222 223 $a1 = self::factory()->activity->create(); 224 $a2 = self::factory()->activity->create( array( 225 'recorded_time' => '2001-01-01 12:00' 226 ) ); 227 $a3 = self::factory()->activity->create( array( 228 'recorded_time' => '2005-01-01 12:00' 229 ) ); 230 231 // 'date_query' after and relative test 232 $query = BP_Activity_Activity::get( array( 233 'date_query' => array( array( 234 'after' => '1 day ago' 235 ) ) 236 ) ); 237 $this->assertEquals( array( $a1 ), wp_list_pluck( $query['activities'], 'id' ) ); 238 } 239 240 /** 241 * @group get 242 */ 243 public function test_get_with_search_terms() { 244 $a1 = self::factory()->activity->create( array( 245 'content' => 'Boone is a cool guy', 246 ) ); 247 $a2 = self::factory()->activity->create( array( 248 'content' => 'No he isn\'t', 249 ) ); 250 251 $activity = BP_Activity_Activity::get( array( 252 'search_terms' => 'cool', 253 ) ); 254 $ids = wp_list_pluck( $activity['activities'], 'id' ); 255 $this->assertEquals( $ids, array( $a1 ) ); 256 } 257 258 /** 259 * @group get 260 */ 261 public function test_get_with_display_comments_threaded() { 262 $u = self::factory()->user->create(); 263 264 $now = time(); 265 $a1 = self::factory()->activity->create( array( 266 'user_id' => $u, 267 'content' => 'Life Rules', 268 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 269 ) ); 270 $a2 = self::factory()->activity->create( array( 271 'user_id' => $u, 272 'content' => 'Life Drools', 273 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 274 ) ); 275 $a3 = bp_activity_new_comment( array( 276 'user_id' => $u, 277 'activity_id' => $a1, 278 'content' => 'Candy is good', 279 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 280 ) ); 281 282 $activity = BP_Activity_Activity::get( array( 283 'display_comments' => 'threaded', 284 ) ); 285 286 // Kinda crummy, but let's construct a skeleton 287 $expected = array( 288 $a1 => array( $a3 ), 289 $a2 => array(), 290 ); 291 292 $found = array(); 293 foreach ( $activity['activities'] as $a ) { 294 $found[ $a->id ] = ! empty( $a->children ) ? array_keys( $a->children ) : array(); 295 } 296 297 $this->assertEquals( $expected, $found ); 298 } 299 300 /** 301 * @group get 302 */ 303 public function test_get_with_display_comments_stream() { 304 $now = time(); 305 $a1 = self::factory()->activity->create( array( 306 'content' => 'Life Rules', 307 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 308 ) ); 309 $a2 = self::factory()->activity->create( array( 310 'content' => 'Life Drools', 311 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 312 ) ); 313 314 // bp_activity_new_comment() doesn't allow date_recorded 315 $a3 = bp_activity_add( array( 316 'action' => sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_get_loggedin_user_link() ) , 317 'content' => 'Candy is good', 318 'component' => buddypress()->activity->id, 319 'type' => 'activity_comment', 320 'user_id' => bp_loggedin_user_id(), 321 'item_id' => $a1, 322 'secondary_item_id' => $a1, 323 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 324 ) ); 325 326 $activity = BP_Activity_Activity::get( array( 327 'display_comments' => 'stream', 328 ) ); 329 $ids = wp_list_pluck( $activity['activities'], 'id' ); 330 $this->assertEquals( array( $a1, $a3, $a2 ), $ids ); 331 } 332 333 /** 334 * @group get 335 */ 336 public function test_get_with_display_comments_false() { 337 $now = time(); 338 $a1 = self::factory()->activity->create( array( 339 'content' => 'Life Rules', 340 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 341 ) ); 342 $a2 = self::factory()->activity->create( array( 343 'content' => 'Life Drools', 344 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 345 ) ); 346 $a3 = bp_activity_new_comment( array( 347 'activity_id' => $a1, 348 'content' => 'Candy is good', 349 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 350 ) ); 351 352 $activity = BP_Activity_Activity::get( array( 353 'display_comments' => false, 354 ) ); 355 $ids = wp_list_pluck( $activity['activities'], 'id' ); 356 $this->assertEquals( array( $a1, $a2 ), $ids ); 357 } 358 359 /** 360 * @group get 361 */ 362 public function test_get_with_offset() { 363 $now = time(); 364 $a1 = self::factory()->activity->create( array( 365 'content' => 'Life Rules', 366 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 367 ) ); 368 $a2 = self::factory()->activity->create( array( 369 'content' => 'Life Drools', 370 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 371 ) ); 372 $a3 = self::factory()->activity->create( array( 373 'content' => 'Life Drools', 374 'recorded_time' => date( 'Y-m-d H:i:s', $now - 10 ), 375 ) ); 376 377 $activity = BP_Activity_Activity::get( array( 378 'filter' => array( 379 'offset' => $a2, 380 ), 381 ) ); 382 $ids = wp_list_pluck( $activity['activities'], 'id' ); 383 $this->assertEquals( array( $a3, $a2 ), $ids ); 384 } 385 386 /** 387 * @group get 388 */ 389 public function test_get_with_since() { 390 $now = time(); 391 $a1 = self::factory()->activity->create( array( 392 'content' => 'Life Rules', 393 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 394 ) ); 395 $a2 = self::factory()->activity->create( array( 396 'content' => 'Life Drools', 397 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 398 ) ); 399 $a3 = self::factory()->activity->create( array( 400 'content' => 'Life Drools', 401 'recorded_time' => date( 'Y-m-d H:i:s', $now - 10 ), 402 ) ); 403 404 $activity = BP_Activity_Activity::get( array( 405 'filter' => array( 406 'since' => date( 'Y-m-d H:i:s', $now - 70 ), 407 ), 408 ) ); 409 $ids = wp_list_pluck( $activity['activities'], 'id' ); 410 $this->assertEquals( array( $a3, $a2 ), $ids ); 411 } 412 413 /** 414 * @group get 415 * @group count_total 416 */ 417 public function test_get_with_count_total() { 418 $a1 = self::factory()->activity->create(); 419 $a2 = self::factory()->activity->create(); 420 421 $activity = BP_Activity_Activity::get( array( 422 'count_total' => 'count_query', 423 ) ); 424 425 $this->assertEquals( 2, $activity['total'] ); 426 } 427 428 /** 429 * @group get 430 * @group count_total 431 */ 432 public function test_get_with_count_total_false() { 433 $a1 = self::factory()->activity->create(); 434 $a2 = self::factory()->activity->create(); 435 436 $activity = BP_Activity_Activity::get( array( 437 'count_total' => false, 438 ) ); 439 440 $this->assertSame( null, $activity['total'] ); 441 } 442 443 /** 444 * @group get 445 * @group count_total 446 */ 447 public function test_get_with_count_total_default_to_false() { 448 $a1 = self::factory()->activity->create(); 449 $a2 = self::factory()->activity->create(); 450 451 $activity = BP_Activity_Activity::get(); 452 453 $this->assertSame( null, $activity['total'] ); 454 } 455 456 /** 457 * @group get_id 458 */ 459 public function test_get_id_with_item_id() { 460 $a1 = self::factory()->activity->create( array( 461 'item_id' => 523, 462 ) ); 463 $a2 = self::factory()->activity->create( array( 464 'item_id' => 1888, 465 ) ); 466 467 $args = array( 468 'item_id' => 523, 469 ); 470 471 $activity = BP_Activity_Activity::get_id( $args ); 472 $this->assertEquals( $a1, $activity ); 473 } 474 475 /** 476 * @group get_id 477 * @group BP8596 478 * @expectedDeprecated BP_Activity_Activity::get_id 479 */ 480 public function test_get_id_with_deprecated_args() { 481 $a1 = self::factory()->activity->create( array( 482 'item_id' => 573, 483 ) ); 484 $a2 = self::factory()->activity->create( array( 485 'item_id' => 1098, 486 ) ); 487 488 $activity = BP_Activity_Activity::get_id( false, false, false, 1098, false, false, false, false ); 489 $this->assertEquals( $a2, $activity ); 490 } 491 492 /** 493 * @group get_id 494 */ 495 public function test_get_id_with_secondary_item_id() { 496 $a1 = self::factory()->activity->create( array( 497 'secondary_item_id' => 523, 498 ) ); 499 $a2 = self::factory()->activity->create( array( 500 'secondary_content' => 1888, 501 ) ); 502 503 $args = array( 504 'secondary_item_id' => 523, 505 ); 506 507 $activity = BP_Activity_Activity::get_id( $args ); 508 $this->assertEquals( $a1, $activity ); 509 } 510 511 /** 512 * @group delete 513 */ 514 public function test_delete_with_item_id() { 515 $a1 = self::factory()->activity->create( array( 516 'item_id' => 523, 517 ) ); 518 $a2 = self::factory()->activity->create( array( 519 'item_id' => 1888, 520 ) ); 521 522 $activity = BP_Activity_Activity::delete( array( 523 'item_id' => 523, 524 ) ); 525 $this->assertEquals( array( $a1 ), $activity ); 526 } 527 528 /** 529 * @group delete 530 */ 531 public function test_delete_with_secondary_item_id() { 532 $a1 = self::factory()->activity->create( array( 533 'secondary_item_id' => 523, 534 ) ); 535 $a2 = self::factory()->activity->create( array( 536 'secondary_item_id' => 1888, 537 ) ); 538 539 $activity = BP_Activity_Activity::delete( array( 540 'secondary_item_id' => 523, 541 ) ); 542 $this->assertEquals( array( $a1 ), $activity ); 543 } 544 545 /** 546 * @group get_activity_comments 547 * 548 * Verify the format of the activity comments array, for internal 549 * refactoring 550 */ 551 public function test_get_activity_comments_format() { 552 $now = time(); 553 554 $u1 = self::factory()->user->create(); 555 $u2 = self::factory()->user->create(); 556 557 $a1 = self::factory()->activity->create( array( 558 'content' => 'Life Rules', 559 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 560 'user_id' => $u1, 561 ) ); 562 $a2 = bp_activity_new_comment( array( 563 'activity_id' => $a1, 564 'content' => 'Candy is good', 565 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 566 'user_id' => $u1, 567 ) ); 568 $a3 = bp_activity_new_comment( array( 569 'activity_id' => $a1, 570 'content' => 'Bread is good', 571 'recorded_time' => date( 'Y-m-d H:i:s', $now - 25 ), 572 'user_id' => $u2, 573 ) ); 574 575 $keys = array( 'id', 'item_id', 'secondary_item_id', 'user_id', 'primary_link', 'component', 'type', 'action', 'content', 'date_recorded', 'hide_sitewide', 'mptt_left', 'mptt_right', 'is_spam' ); 576 577 $a2_obj = new BP_Activity_Activity( $a2 ); 578 579 $e2 = new stdClass; 580 581 foreach ( $keys as $key ) { 582 $e2->{$key} = $a2_obj->{$key}; 583 } 584 585 $e2_user = new WP_User( $a2_obj->user_id ); 586 587 $e2->user_email = $e2_user->user_email; 588 $e2->user_nicename = $e2_user->user_nicename; 589 $e2->user_login = $e2_user->user_login; 590 $e2->display_name = $e2_user->display_name; 591 $e2->user_fullname = bp_core_get_user_displayname( $e2->user_id ); 592 $e2->children = array(); 593 $e2->depth = 1; 594 595 $a3_obj = new BP_Activity_Activity( $a3 ); 596 597 $e3 = new stdClass; 598 599 foreach ( $keys as $key ) { 600 $e3->{$key} = $a3_obj->{$key}; 601 } 602 603 $e3_user = new WP_User( $e3->user_id ); 604 605 $e3->user_email = $e3_user->user_email; 606 $e3->user_nicename = $e3_user->user_nicename; 607 $e3->user_login = $e3_user->user_login; 608 $e3->display_name = $e3_user->display_name; 609 $e3->user_fullname = bp_core_get_user_displayname( $e3->user_id ); 610 $e3->children = array(); 611 $e3->depth = 1; 612 613 $expected = array( 614 $a2 => $e2, 615 $a3 => $e3, 616 ); 617 618 $a1_obj = new BP_Activity_Activity( $a1 ); 619 $comments = BP_Activity_Activity::get_activity_comments( $a1, $a1_obj->mptt_left, $a1_obj->mptt_right, 'ham_only', $a1 ); 620 621 $this->assertEquals( $expected, $comments ); 622 } 623 624 /** 625 * @group get_last_updated 626 */ 627 public function test_get_last_updated() { 628 $now = time(); 629 $a1 = self::factory()->activity->create( array( 630 'recorded_time' => date( 'Y-m-d H:i:s', $now - 500 ), 631 ) ); 632 $a2 = self::factory()->activity->create( array( 633 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 634 ) ); 635 $a3 = self::factory()->activity->create( array( 636 'recorded_time' => date( 'Y-m-d H:i:s', $now - 300 ), 637 ) ); 638 639 $this->assertSame( date( 'Y-m-d H:i:s', $now - 100 ), BP_Activity_Activity::get_last_updated() ); 640 } 641 642 /** 643 * @group get_recorded_components 644 */ 645 public function test_get_recorded_components_skip_last_activity_false() { 646 $a1 = self::factory()->activity->create( array( 647 'component' => 'members', 648 'action' => 'last_activity', 649 ) ); 650 $a2 = self::factory()->activity->create( array( 651 'component' => 'groups', 652 'action' => 'created_group', 653 ) ); 654 $a3 = self::factory()->activity->create( array( 655 'component' => 'friends', 656 'action' => 'friendship_accepted', 657 ) ); 658 659 $found = BP_Activity_Activity::get_recorded_components( false ); 660 sort( $found ); 661 662 $this->assertSame( array( 'friends', 'groups', 'members' ), BP_Activity_Activity::get_recorded_components( false ) ); 663 } 664 665 /** 666 * @group get_recorded_components 667 */ 668 public function test_get_recorded_components_skip_last_activity_true_filter_empty_component() { 669 $a1 = self::factory()->activity->create( array( 670 'component' => 'members', 671 'action' => 'last_activity', 672 ) ); 673 $a2 = self::factory()->activity->create( array( 674 'component' => 'groups', 675 'action' => 'created_group', 676 ) ); 677 $a3 = self::factory()->activity->create( array( 678 'component' => 'friends', 679 'action' => 'friendship_accepted', 680 ) ); 681 682 $found = BP_Activity_Activity::get_recorded_components( true ); 683 sort( $found ); 684 685 $this->assertSame( array( 'friends', 'groups' ), BP_Activity_Activity::get_recorded_components() ); 686 } 687 688 /** 689 * @group get_recorded_components 690 */ 691 public function test_get_recorded_components_skip_last_activity_true_members_component_not_empty() { 692 $a1 = self::factory()->activity->create( array( 693 'component' => 'members', 694 'action' => 'last_activity', 695 ) ); 696 $a2 = self::factory()->activity->create( array( 697 'component' => 'groups', 698 'action' => 'created_group', 699 ) ); 700 $a3 = self::factory()->activity->create( array( 701 'component' => 'friends', 702 'action' => 'friendship_accepted', 703 ) ); 704 $a4 = self::factory()->activity->create( array( 705 'component' => 'members', 706 'action' => 'foo', 707 ) ); 708 709 $found = BP_Activity_Activity::get_recorded_components( true ); 710 sort( $found ); 711 712 $this->assertSame( array( 'friends', 'groups', 'members' ), BP_Activity_Activity::get_recorded_components() ); 713 } 714 715 /** 716 * @group get_recorded_components 717 */ 718 public function test_get_recorded_components_skip_last_activity_true_la_in_multiple_components() { 719 $a1 = self::factory()->activity->create( array( 720 'component' => 'members', 721 'action' => 'last_activity', 722 ) ); 723 $a2 = self::factory()->activity->create( array( 724 'component' => 'groups', 725 'action' => 'created_group', 726 ) ); 727 $a3 = self::factory()->activity->create( array( 728 'component' => 'friends', 729 'action' => 'friendship_accepted', 730 ) ); 731 $a4 = self::factory()->activity->create( array( 732 'component' => 'groups', 733 'action' => 'last_activity', 734 ) ); 735 736 $found = BP_Activity_Activity::get_recorded_components( true ); 737 sort( $found ); 738 739 $this->assertSame( array( 'friends', 'groups', ), BP_Activity_Activity::get_recorded_components() ); 740 } 741 /** 742 * @group activity_action 743 */ 744 public function test_instantiated_action_with_dynamic_callback() { 745 bp_activity_set_action( 746 'foo', 747 'bar', 748 'Foo Bar', 749 array( $this, 'action_cb' ) 750 ); 751 752 // Create the activity item with a manual activity string 753 $a = self::factory()->activity->create( array( 754 'component' => 'foo', 755 'type' => 'bar', 756 'action' => 'baz', 757 ) ); 758 759 $a_obj = new BP_Activity_Activity( $a ); 760 761 $this->assertSame( 'Woo Hoo!', $a_obj->action ); 762 } 763 764 /** 765 * @group activity_action 766 */ 767 public function test_instantiated_action_without_dynamic_callback_but_with_stored_action() { 768 // No callback is registered - this mimics a legacy plugin 769 770 // Create the activity item with a manual activity string 771 $a = self::factory()->activity->create( array( 772 'component' => 'foo', 773 'type' => 'bar1', 774 'action' => 'baz', 775 ) ); 776 777 $a_obj = new BP_Activity_Activity( $a ); 778 779 $this->assertSame( 'baz', $a_obj->action ); 780 } 781 782 /** 783 * @group activity_action 784 */ 785 public function test_instantiated_action_without_dynamic_callback_but_with_no_stored_action() { 786 // No callback is registered - this mimics a legacy plugin 787 788 // Create the activity item with a manual activity string 789 $a = self::factory()->activity->create( array( 790 'component' => 'foo', 791 'type' => 'bar2', 792 ) ); 793 794 $a_obj = new BP_Activity_Activity( $a ); 795 796 $this->assertSame( '', $a_obj->action ); 797 } 798 799 /** 800 * @ticket BP7394 801 */ 802 public function test_nonexistent_activity_should_have_id_0_after_population() { 803 $a = self::factory()->activity->create(); 804 bp_activity_delete_by_activity_id( $a ); 805 806 $a_obj = new BP_Activity_Activity( $a ); 807 $this->assertSame( 0, $a_obj->id ); 808 } 809 810 public function action_cb( $activity ) { 811 return 'Woo Hoo!'; 812 } 813 814 /** 815 * @ticket BP8236 816 */ 817 public function test_save_activity_requires_component() { 818 $a = bp_activity_add( 819 array( 820 'component' => '', 821 'content' => 'Activity without component content %s', 822 'type' => 'activity_update', 823 'error_type' => 'wp_error', 824 ) 825 ); 826 827 $this->assertInstanceOf( 'WP_Error', $a ); 828 $this->assertEquals( 'bp_activity_missing_component', $a->get_error_code() ); 829 } 830 831 /** 832 * @ticket BP8236 833 */ 834 public function test_save_activity_requires_type() { 835 $a = bp_activity_add( 836 array( 837 'component' => 'foobar', 838 'content' => 'Activity without type content %s', 839 'type' => '', 840 'error_type' => 'wp_error', 841 ) 842 ); 843 844 $this->assertInstanceOf( 'WP_Error', $a ); 845 $this->assertEquals( 'bp_activity_missing_type', $a->get_error_code() ); 846 } 847 848 /** 849 * @ticket BP8236 850 */ 851 public function test_save_activity_requires_content() { 852 $a = bp_activity_add( 853 array( 854 'component' => buddypress()->activity->id, 855 'content' => '', 856 'type' => 'activity_update', 857 'error_type' => 'wp_error', 858 ) 859 ); 860 861 $this->assertInstanceOf( 'WP_Error', $a ); 862 $this->assertEquals( 'bp_activity_missing_content', $a->get_error_code() ); 863 } 864 865 /** 866 * @ticket BP8236 867 */ 868 public function test_save_activity_does_not_require_content() { 869 $a = bp_activity_add( 870 array( 871 'component' => buddypress()->members->id, 872 'content' => '', 873 'type' => 'new_member', 874 'error_type' => 'wp_error', 875 ) 876 ); 877 878 $this->assertFalse( is_wp_error( $a ) ); 879 } 880 881 /** 882 * @ticket BP8236 883 */ 884 public function test_save_activity_custom_type_requires_content() { 885 add_filter( 'bp_activity_type_requires_content', '__return_true' ); 886 887 $a = bp_activity_add( 888 array( 889 'component' => 'foo', 890 'content' => '', 891 'type' => 'bar', 892 'error_type' => 'wp_error', 893 ) 894 ); 895 896 remove_filter( 'bp_activity_type_requires_content', '__return_true' ); 897 898 $this->assertInstanceOf( 'WP_Error', $a ); 899 $this->assertEquals( 'bp_activity_missing_content', $a->get_error_code() ); 900 } 901 }
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 |