[ 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 $activity = BP_Activity_Activity::get_id( false, false, false, 523, false, false, false, false ); 468 $this->assertEquals( $a1, $activity ); 469 } 470 471 /** 472 * @group get_id 473 */ 474 public function test_get_id_with_secondary_item_id() { 475 $a1 = self::factory()->activity->create( array( 476 'secondary_item_id' => 523, 477 ) ); 478 $a2 = self::factory()->activity->create( array( 479 'secondary_content' => 1888, 480 ) ); 481 482 $activity = BP_Activity_Activity::get_id( false, false, false, false, 523, false, false, false ); 483 $this->assertEquals( $a1, $activity ); 484 } 485 486 /** 487 * @group delete 488 */ 489 public function test_delete_with_item_id() { 490 $a1 = self::factory()->activity->create( array( 491 'item_id' => 523, 492 ) ); 493 $a2 = self::factory()->activity->create( array( 494 'item_id' => 1888, 495 ) ); 496 497 $activity = BP_Activity_Activity::delete( array( 498 'item_id' => 523, 499 ) ); 500 $this->assertEquals( array( $a1 ), $activity ); 501 } 502 503 /** 504 * @group delete 505 */ 506 public function test_delete_with_secondary_item_id() { 507 $a1 = self::factory()->activity->create( array( 508 'secondary_item_id' => 523, 509 ) ); 510 $a2 = self::factory()->activity->create( array( 511 'secondary_item_id' => 1888, 512 ) ); 513 514 $activity = BP_Activity_Activity::delete( array( 515 'secondary_item_id' => 523, 516 ) ); 517 $this->assertEquals( array( $a1 ), $activity ); 518 } 519 520 /** 521 * @group get_activity_comments 522 * 523 * Verify the format of the activity comments array, for internal 524 * refactoring 525 */ 526 public function test_get_activity_comments_format() { 527 $now = time(); 528 529 $u1 = self::factory()->user->create(); 530 $u2 = self::factory()->user->create(); 531 532 $a1 = self::factory()->activity->create( array( 533 'content' => 'Life Rules', 534 'recorded_time' => date( 'Y-m-d H:i:s', $now ), 535 'user_id' => $u1, 536 ) ); 537 $a2 = bp_activity_new_comment( array( 538 'activity_id' => $a1, 539 'content' => 'Candy is good', 540 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 541 'user_id' => $u1, 542 ) ); 543 $a3 = bp_activity_new_comment( array( 544 'activity_id' => $a1, 545 'content' => 'Bread is good', 546 'recorded_time' => date( 'Y-m-d H:i:s', $now - 25 ), 547 'user_id' => $u2, 548 ) ); 549 550 $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' ); 551 552 $a2_obj = new BP_Activity_Activity( $a2 ); 553 554 $e2 = new stdClass; 555 556 foreach ( $keys as $key ) { 557 $e2->{$key} = $a2_obj->{$key}; 558 } 559 560 $e2_user = new WP_User( $a2_obj->user_id ); 561 562 $e2->user_email = $e2_user->user_email; 563 $e2->user_nicename = $e2_user->user_nicename; 564 $e2->user_login = $e2_user->user_login; 565 $e2->display_name = $e2_user->display_name; 566 $e2->user_fullname = bp_core_get_user_displayname( $e2->user_id ); 567 $e2->children = array(); 568 $e2->depth = 1; 569 570 $a3_obj = new BP_Activity_Activity( $a3 ); 571 572 $e3 = new stdClass; 573 574 foreach ( $keys as $key ) { 575 $e3->{$key} = $a3_obj->{$key}; 576 } 577 578 $e3_user = new WP_User( $e3->user_id ); 579 580 $e3->user_email = $e3_user->user_email; 581 $e3->user_nicename = $e3_user->user_nicename; 582 $e3->user_login = $e3_user->user_login; 583 $e3->display_name = $e3_user->display_name; 584 $e3->user_fullname = bp_core_get_user_displayname( $e3->user_id ); 585 $e3->children = array(); 586 $e3->depth = 1; 587 588 $expected = array( 589 $a2 => $e2, 590 $a3 => $e3, 591 ); 592 593 $a1_obj = new BP_Activity_Activity( $a1 ); 594 $comments = BP_Activity_Activity::get_activity_comments( $a1, $a1_obj->mptt_left, $a1_obj->mptt_right, 'ham_only', $a1 ); 595 596 $this->assertEquals( $expected, $comments ); 597 } 598 599 /** 600 * @group get_last_updated 601 */ 602 public function test_get_last_updated() { 603 $now = time(); 604 $a1 = self::factory()->activity->create( array( 605 'recorded_time' => date( 'Y-m-d H:i:s', $now - 500 ), 606 ) ); 607 $a2 = self::factory()->activity->create( array( 608 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 609 ) ); 610 $a3 = self::factory()->activity->create( array( 611 'recorded_time' => date( 'Y-m-d H:i:s', $now - 300 ), 612 ) ); 613 614 $this->assertSame( date( 'Y-m-d H:i:s', $now - 100 ), BP_Activity_Activity::get_last_updated() ); 615 } 616 617 /** 618 * @group get_recorded_components 619 */ 620 public function test_get_recorded_components_skip_last_activity_false() { 621 $a1 = self::factory()->activity->create( array( 622 'component' => 'members', 623 'action' => 'last_activity', 624 ) ); 625 $a2 = self::factory()->activity->create( array( 626 'component' => 'groups', 627 'action' => 'created_group', 628 ) ); 629 $a3 = self::factory()->activity->create( array( 630 'component' => 'friends', 631 'action' => 'friendship_accepted', 632 ) ); 633 634 $found = BP_Activity_Activity::get_recorded_components( false ); 635 sort( $found ); 636 637 $this->assertSame( array( 'friends', 'groups', 'members' ), BP_Activity_Activity::get_recorded_components( false ) ); 638 } 639 640 /** 641 * @group get_recorded_components 642 */ 643 public function test_get_recorded_components_skip_last_activity_true_filter_empty_component() { 644 $a1 = self::factory()->activity->create( array( 645 'component' => 'members', 646 'action' => 'last_activity', 647 ) ); 648 $a2 = self::factory()->activity->create( array( 649 'component' => 'groups', 650 'action' => 'created_group', 651 ) ); 652 $a3 = self::factory()->activity->create( array( 653 'component' => 'friends', 654 'action' => 'friendship_accepted', 655 ) ); 656 657 $found = BP_Activity_Activity::get_recorded_components( true ); 658 sort( $found ); 659 660 $this->assertSame( array( 'friends', 'groups' ), BP_Activity_Activity::get_recorded_components() ); 661 } 662 663 /** 664 * @group get_recorded_components 665 */ 666 public function test_get_recorded_components_skip_last_activity_true_members_component_not_empty() { 667 $a1 = self::factory()->activity->create( array( 668 'component' => 'members', 669 'action' => 'last_activity', 670 ) ); 671 $a2 = self::factory()->activity->create( array( 672 'component' => 'groups', 673 'action' => 'created_group', 674 ) ); 675 $a3 = self::factory()->activity->create( array( 676 'component' => 'friends', 677 'action' => 'friendship_accepted', 678 ) ); 679 $a4 = self::factory()->activity->create( array( 680 'component' => 'members', 681 'action' => 'foo', 682 ) ); 683 684 $found = BP_Activity_Activity::get_recorded_components( true ); 685 sort( $found ); 686 687 $this->assertSame( array( 'friends', 'groups', 'members' ), BP_Activity_Activity::get_recorded_components() ); 688 } 689 690 /** 691 * @group get_recorded_components 692 */ 693 public function test_get_recorded_components_skip_last_activity_true_la_in_multiple_components() { 694 $a1 = self::factory()->activity->create( array( 695 'component' => 'members', 696 'action' => 'last_activity', 697 ) ); 698 $a2 = self::factory()->activity->create( array( 699 'component' => 'groups', 700 'action' => 'created_group', 701 ) ); 702 $a3 = self::factory()->activity->create( array( 703 'component' => 'friends', 704 'action' => 'friendship_accepted', 705 ) ); 706 $a4 = self::factory()->activity->create( array( 707 'component' => 'groups', 708 'action' => 'last_activity', 709 ) ); 710 711 $found = BP_Activity_Activity::get_recorded_components( true ); 712 sort( $found ); 713 714 $this->assertSame( array( 'friends', 'groups', ), BP_Activity_Activity::get_recorded_components() ); 715 } 716 /** 717 * @group activity_action 718 */ 719 public function test_instantiated_action_with_dynamic_callback() { 720 bp_activity_set_action( 721 'foo', 722 'bar', 723 'Foo Bar', 724 array( $this, 'action_cb' ) 725 ); 726 727 // Create the activity item with a manual activity string 728 $a = self::factory()->activity->create( array( 729 'component' => 'foo', 730 'type' => 'bar', 731 'action' => 'baz', 732 ) ); 733 734 $a_obj = new BP_Activity_Activity( $a ); 735 736 $this->assertSame( 'Woo Hoo!', $a_obj->action ); 737 } 738 739 /** 740 * @group activity_action 741 */ 742 public function test_instantiated_action_without_dynamic_callback_but_with_stored_action() { 743 // No callback is registered - this mimics a legacy plugin 744 745 // Create the activity item with a manual activity string 746 $a = self::factory()->activity->create( array( 747 'component' => 'foo', 748 'type' => 'bar1', 749 'action' => 'baz', 750 ) ); 751 752 $a_obj = new BP_Activity_Activity( $a ); 753 754 $this->assertSame( 'baz', $a_obj->action ); 755 } 756 757 /** 758 * @group activity_action 759 */ 760 public function test_instantiated_action_without_dynamic_callback_but_with_no_stored_action() { 761 // No callback is registered - this mimics a legacy plugin 762 763 // Create the activity item with a manual activity string 764 $a = self::factory()->activity->create( array( 765 'component' => 'foo', 766 'type' => 'bar2', 767 ) ); 768 769 $a_obj = new BP_Activity_Activity( $a ); 770 771 $this->assertSame( '', $a_obj->action ); 772 } 773 774 /** 775 * @ticket BP7394 776 */ 777 public function test_nonexistent_activity_should_have_id_0_after_population() { 778 $a = self::factory()->activity->create(); 779 bp_activity_delete_by_activity_id( $a ); 780 781 $a_obj = new BP_Activity_Activity( $a ); 782 $this->assertSame( 0, $a_obj->id ); 783 } 784 785 public function action_cb( $activity ) { 786 return 'Woo Hoo!'; 787 } 788 789 /** 790 * @ticket BP8236 791 */ 792 public function test_save_activity_requires_component() { 793 $a = bp_activity_add( 794 array( 795 'component' => '', 796 'content' => 'Activity without component content %s', 797 'type' => 'activity_update', 798 'error_type' => 'wp_error', 799 ) 800 ); 801 802 $this->assertInstanceOf( 'WP_Error', $a ); 803 $this->assertEquals( 'bp_activity_missing_component', $a->get_error_code() ); 804 } 805 806 /** 807 * @ticket BP8236 808 */ 809 public function test_save_activity_requires_type() { 810 $a = bp_activity_add( 811 array( 812 'component' => 'foobar', 813 'content' => 'Activity without type content %s', 814 'type' => '', 815 'error_type' => 'wp_error', 816 ) 817 ); 818 819 $this->assertInstanceOf( 'WP_Error', $a ); 820 $this->assertEquals( 'bp_activity_missing_type', $a->get_error_code() ); 821 } 822 823 /** 824 * @ticket BP8236 825 */ 826 public function test_save_activity_requires_content() { 827 $a = bp_activity_add( 828 array( 829 'component' => buddypress()->activity->id, 830 'content' => '', 831 'type' => 'activity_update', 832 'error_type' => 'wp_error', 833 ) 834 ); 835 836 $this->assertInstanceOf( 'WP_Error', $a ); 837 $this->assertEquals( 'bp_activity_missing_content', $a->get_error_code() ); 838 } 839 840 /** 841 * @ticket BP8236 842 */ 843 public function test_save_activity_does_not_require_content() { 844 $a = bp_activity_add( 845 array( 846 'component' => buddypress()->members->id, 847 'content' => '', 848 'type' => 'new_member', 849 'error_type' => 'wp_error', 850 ) 851 ); 852 853 $this->assertFalse( is_wp_error( $a ) ); 854 } 855 856 /** 857 * @ticket BP8236 858 */ 859 public function test_save_activity_custom_type_requires_content() { 860 add_filter( 'bp_activity_type_requires_content', '__return_true' ); 861 862 $a = bp_activity_add( 863 array( 864 'component' => 'foo', 865 'content' => '', 866 'type' => 'bar', 867 'error_type' => 'wp_error', 868 ) 869 ); 870 871 remove_filter( 'bp_activity_type_requires_content', '__return_true' ); 872 873 $this->assertInstanceOf( 'WP_Error', $a ); 874 $this->assertEquals( 'bp_activity_missing_content', $a->get_error_code() ); 875 } 876 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Mar 4 01:01:38 2021 | Cross-referenced by PHPXref 0.7.1 |