[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @group blogs 5 * @group activity 6 */ 7 class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 8 /** 9 * @group bp_blogs_register_activity_actions 10 * @group activity_tracking 11 */ 12 public function test_bp_blogs_loader_post_tracking_args_filter() { 13 $bp = buddypress(); 14 15 $expected = array( 'new_blog_post', 'new_blog_comment' ); 16 17 if ( is_multisite() ) { 18 $expected = array_merge( array( 'new_blog' ), $expected ); 19 } 20 21 $actions = bp_activity_get_actions(); 22 $actions = array_keys( (array) $actions->blogs ); 23 24 $this->assertEquals( $expected, $actions ); 25 } 26 27 /** 28 * @group activity_action 29 * @group bp_blogs_format_activity_action_new_blog 30 */ 31 public function test_bp_blogs_format_activity_action_new_blog() { 32 if ( ! is_multisite() ) { 33 $this->markTestSkipped(); 34 } 35 36 $b = self::factory()->blog->create(); 37 $u = self::factory()->user->create(); 38 $a = self::factory()->activity->create( array( 39 'component' => buddypress()->blogs->id, 40 'type' => 'new_blog', 41 'user_id' => $u, 42 'item_id' => $b, 43 ) ); 44 45 $a_obj = new BP_Activity_Activity( $a ); 46 47 $expected = sprintf( '%s created the site %s', bp_core_get_userlink( $u ), '<a href="' . get_blog_option( $b, 'home' ) . '">' . get_blog_option( $b, 'blogname' ) . '</a>' ); 48 49 $this->assertSame( $expected, $a_obj->action ); 50 } 51 52 /** 53 * @group activity_action 54 * @group bp_blogs_format_activity_action_new_blog_post 55 */ 56 public function test_bp_blogs_format_activity_action_new_blog_post_nonms() { 57 if ( is_multisite() ) { 58 $this->markTestSkipped(); 59 } 60 61 $u = self::factory()->user->create(); 62 $p = self::factory()->post->create( array( 63 'post_author' => $u, 64 ) ); 65 $a = self::factory()->activity->create( array( 66 'component' => buddypress()->blogs->id, 67 'type' => 'new_blog_post', 68 'user_id' => $u, 69 'item_id' => 1, 70 'secondary_item_id' => $p, 71 ) ); 72 73 $a_obj = new BP_Activity_Activity( $a ); 74 75 $user_link = bp_core_get_userlink( $u ); 76 $blog_url = get_home_url(); 77 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 78 $post_title = bp_activity_get_meta( $a, 'post_title' ); 79 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; 80 81 $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link ); 82 83 $this->assertSame( $expected, $a_obj->action ); 84 } 85 86 /** 87 * @group activity_action 88 * @group bp_blogs_format_activity_action_new_blog_post 89 */ 90 public function test_bp_blogs_format_activity_action_new_blog_post_ms_rootblog() { 91 if ( ! is_multisite() ) { 92 $this->markTestSkipped(); 93 } 94 95 $u = self::factory()->user->create(); 96 $p = self::factory()->post->create( array( 97 'post_author' => $u, 98 ) ); 99 $a = self::factory()->activity->create( array( 100 'component' => buddypress()->blogs->id, 101 'type' => 'new_blog_post', 102 'user_id' => $u, 103 'item_id' => 1, 104 'secondary_item_id' => $p, 105 ) ); 106 107 $a_obj = new BP_Activity_Activity( $a ); 108 109 $user_link = bp_core_get_userlink( $u ); 110 $blog_url = get_home_url(); 111 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 112 $post_title = bp_activity_get_meta( $a, 'post_title' ); 113 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; 114 115 $expected = sprintf( '%s wrote a new post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . bp_blogs_get_blogmeta( $a_obj->item_id, 'name' ) . '</a>' ); 116 117 $this->assertSame( $expected, $a_obj->action ); 118 } 119 120 /** 121 * @group activity_action 122 * @group bp_blogs_format_activity_action_new_blog_post 123 */ 124 public function test_bp_blogs_format_activity_action_new_blog_post_ms_nonrootblog() { 125 if ( ! is_multisite() ) { 126 $this->markTestSkipped(); 127 } 128 129 $b = self::factory()->blog->create(); 130 $u = self::factory()->user->create(); 131 132 switch_to_blog( $b ); 133 $p = self::factory()->post->create( array( 134 'post_author' => $u, 135 ) ); 136 $p_obj = get_post( $p ); 137 restore_current_blog(); 138 139 $a = self::factory()->activity->create( array( 140 'component' => buddypress()->blogs->id, 141 'type' => 'new_blog_post', 142 'user_id' => $u, 143 'item_id' => $b, 144 'secondary_item_id' => $p, 145 ) ); 146 147 $a_obj = new BP_Activity_Activity( $a ); 148 149 $user_link = bp_core_get_userlink( $u ); 150 $blog_url = get_blog_option( $a_obj->item_id, 'home' ); 151 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 152 $post_title = $p_obj->post_title; 153 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; 154 155 $expected = sprintf( '%s wrote a new post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' ); 156 157 $this->assertSame( $expected, $a_obj->action ); 158 } 159 160 /** 161 * @group activity_action 162 * @group bp_blogs_format_activity_action_new_blog_comment 163 * @group post_type_comment_activities 164 */ 165 public function test_bp_blogs_format_activity_action_new_blog_comment_ms_nonrootblog() { 166 if ( ! is_multisite() ) { 167 $this->markTestSkipped(); 168 } 169 170 $b = self::factory()->blog->create(); 171 $u = self::factory()->user->create(); 172 173 switch_to_blog( $b ); 174 $p = self::factory()->post->create( array( 175 'post_author' => $u, 176 ) ); 177 $p_obj = get_post( $p ); 178 $c = self::factory()->comment->create( array( 179 'comment_post_ID' => $p, 180 ) ); 181 $c_obj = get_comment( $c ); 182 restore_current_blog(); 183 184 $a = self::factory()->activity->create( array( 185 'component' => buddypress()->blogs->id, 186 'type' => 'new_blog_comment', 187 'user_id' => $u, 188 'item_id' => $b, 189 'secondary_item_id' => $c, 190 ) ); 191 192 $a_obj = new BP_Activity_Activity( $a ); 193 194 $user_link = bp_core_get_userlink( $u ); 195 $blog_url = get_blog_option( $a_obj->item_id, 'home' ); 196 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 197 $post_title = $p_obj->post_title; 198 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; 199 200 $expected = sprintf( '%s commented on the post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' ); 201 202 $this->assertSame( $expected, $a_obj->action ); 203 } 204 205 /** 206 * @group bp_blogs_format_activity_action_new_blog 207 */ 208 public function test_bp_activity_format_activity_action_new_blog_backpat() { 209 if ( ! is_multisite() ) { 210 $this->markTestSkipped(); 211 } 212 213 add_filter( 'bp_blogs_activity_created_blog_action', array( $this, 'created_blog_passthrough' ), 10, 2 ); 214 215 $b = self::factory()->blog->create(); 216 $u = self::factory()->user->create(); 217 218 $recorded_blog = new BP_Blogs_Blog; 219 $recorded_blog->user_id = $u; 220 $recorded_blog->blog_id = $b; 221 $recorded_blog_id = $recorded_blog->save(); 222 223 $a = self::factory()->activity->create( array( 224 'component' => buddypress()->blogs->id, 225 'type' => 'new_blog', 226 'user_id' => $u, 227 'item_id' => $b, 228 ) ); 229 230 $this->assertEquals( $this->userblog_id, $recorded_blog_id ); 231 } 232 233 /** 234 * @group bp_blogs_format_activity_action_new_blog_post 235 */ 236 public function test_bp_activity_format_activity_action_new_blog_post_backpat() { 237 if ( ! is_multisite() ) { 238 $this->markTestSkipped(); 239 } 240 241 add_filter( 'bp_blogs_activity_new_post_action', array( $this, 'new_post_passthrough' ), 10, 2 ); 242 243 $b = self::factory()->blog->create(); 244 245 switch_to_blog( $b ); 246 $p = self::factory()->post->create(); 247 restore_current_blog(); 248 249 $u = self::factory()->user->create(); 250 $a = self::factory()->activity->create( array( 251 'component' => buddypress()->blogs->id, 252 'type' => 'new_blog_post', 253 'user_id' => $u, 254 'item_id' => $b, 255 'secondary_item_id' => $p, 256 ) ); 257 258 $this->assertEquals( $this->post_id, $p ); 259 } 260 261 /** 262 * @group bp_blogs_format_activity_action_new_blog_comment 263 */ 264 public function test_bp_activity_format_activity_action_new_blog_comment_backpat() { 265 if ( ! is_multisite() ) { 266 $this->markTestSkipped(); 267 } 268 269 add_filter( 'bp_blogs_activity_new_comment_action', array( $this, 'new_comment_passthrough' ), 10, 2 ); 270 271 $b = self::factory()->blog->create(); 272 273 switch_to_blog( $b ); 274 $p = self::factory()->post->create(); 275 $c = self::factory()->comment->create( array( 276 'comment_post_ID' => $p, 277 ) ); 278 restore_current_blog(); 279 280 $u = self::factory()->user->create(); 281 $a = self::factory()->activity->create( array( 282 'component' => buddypress()->blogs->id, 283 'type' => 'new_blog_comment', 284 'user_id' => $u, 285 'item_id' => $b, 286 'secondary_item_id' => $c, 287 ) ); 288 289 $this->assertEquals( $this->comment_post_id, $p ); 290 } 291 292 /** 293 * @group post_type_comment_activities 294 */ 295 public function test_bp_blogs_update_post_title_activity_meta_should_not_be_the_same_for_same_comment_id() { 296 global $wpdb; 297 298 if ( ! is_multisite() ) { 299 $this->markTestSkipped(); 300 } 301 302 $b1 = self::factory()->blog->create(); 303 $b2 = self::factory()->blog->create(); 304 $b3 = self::factory()->blog->create(); 305 $u = self::factory()->user->create(); 306 $u2 = self::factory()->user->create(); 307 $commenter = self::factory()->user->get_object_by_id( $u2 ); 308 309 $bids = array( $b1, $b2, $b3 ); 310 $pids = array(); 311 312 foreach ( $bids as $bid ) { 313 switch_to_blog( $bid ); 314 315 // Ensure blog privacy is public so post activities are recorded. 316 update_option( 'blog_public', 1 ); 317 318 // Create the post. 319 $pids[ $bid ] = self::factory()->post->create( array( 320 'post_author' => $u, 321 ) ); 322 323 /* 324 * Create the post comment. 325 * 326 * Both user_id and comment_author_email are required for unit tests. 327 */ 328 $c = self::factory()->comment->create( array( 329 'user_id' => $u2, 330 'comment_author_email' => $commenter->user_email, 331 'comment_post_ID' => $pids[ $bid ], 332 ) ); 333 334 // Approve the comment so the activity item is generated. 335 self::factory()->comment->update_object( $c, array( 'comment_approved' => 1 ) ); 336 337 restore_current_blog(); 338 } 339 340 // Now update the post title on one blog only. 341 switch_to_blog( $b1 ); 342 wp_update_post( array( 343 'ID' => $pids[ $b1 ], 344 'post_title' => 'Updated' 345 ) ); 346 restore_current_blog(); 347 348 // Check our activity meta to see if the post title is different. 349 $aids = bp_activity_get( array( 350 'fields' => 'ids', 351 'filter' => array( 352 'action' => 'new_blog_comment' 353 ) 354 ) ); 355 $aids= $aids['activities']; 356 foreach ( $aids as $aid ) { 357 // Skip the check for the correct blog. 358 $a = new BP_Activity_Activity( $aid ); 359 if ( $a->item_id == $b1 ) { 360 continue; 361 } 362 363 // Assert that post title is different. 364 $post_title = bp_activity_get_meta( $aid, 'post_title' ); 365 $this->assertFalse( 'Updated' === $post_title, 'Post title should not be the same across all sites with the same post comment ID' ); 366 } 367 } 368 369 /** 370 * @ticket BP6126 371 */ 372 public function test_check_activity_actions_are_set_when_creating_activity_object() { 373 $bp = buddypress(); 374 375 if ( isset( $bp->activity->actions ) ) { 376 unset( $bp->activity->actions ); 377 } 378 379 $u = self::factory()->user->create(); 380 $p = self::factory()->post->create( array( 'post_author' => $u, ) ); 381 $a = self::factory()->activity->create( array( 382 'component' => buddypress()->blogs->id, 383 'item_id' => 1, 384 'secondary_item_id' => $p, 385 'type' => 'new_blog_post', 386 'user_id' => $u, 387 ) ); 388 389 $a_obj = new BP_Activity_Activity( $a ); 390 $this->assertTrue( ! empty( $a_obj->action ) ); 391 392 } 393 394 /** 395 * @group activity_action 396 * @group bp_blogs_format_activity_action_new_blog_post 397 */ 398 public function test_bp_blogs_format_activity_action_new_blog_post_no_title() { 399 if ( is_multisite() ) { 400 $this->markTestSkipped(); 401 } 402 403 buddypress()->activity->actions = new stdClass(); 404 405 $u = self::factory()->user->create(); 406 $p = wp_insert_post( array( 407 'post_author' => $u, 408 'post_title' => '', // no title: the object of the test 409 'post_status' => 'publish', 410 'post_content' => 'foo bar', 411 ) ); 412 413 $user_link = bp_core_get_userlink( $u ); 414 $blog_url = get_home_url(); 415 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 416 $post_link = '<a href="' . $post_url . '">(no title)</a>'; 417 418 // Set activity actions 419 bp_activity_get_actions(); 420 421 $a_obj = bp_activity_get( array( 422 'item_id' => 1, 423 'secondary_item_id' => $p, 424 ) ); 425 426 $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link ); 427 428 $this->assertSame( $expected, $a_obj['activities'][0]->action ); 429 } 430 431 /** 432 * @group activity_action 433 * @group bp_blogs_format_activity_action_new_blog_post 434 */ 435 public function test_bp_blogs_format_activity_action_new_blog_post_updated_without_title() { 436 if ( is_multisite() ) { 437 $this->markTestSkipped(); 438 } 439 440 buddypress()->activity->actions = new stdClass(); 441 442 $u = self::factory()->user->create(); 443 $p = wp_insert_post( array( 444 'post_author' => $u, 445 'post_title' => 'foo', 446 'post_status' => 'publish', 447 'post_content' => 'foo bar', 448 ) ); 449 450 $user_link = bp_core_get_userlink( $u ); 451 $blog_url = get_home_url(); 452 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 453 $post_title = get_the_title( $p ); 454 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; 455 456 // Set actions 457 bp_activity_get_actions(); 458 459 $a_obj = bp_activity_get( array( 460 'item_id' => 1, 461 'secondary_item_id' => $p, 462 ) ); 463 464 $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link ); 465 466 $this->assertSame( $expected, $a_obj['activities'][0]->action ); 467 468 // Update the post by removing its title 469 wp_update_post( array( 470 'ID' => $p, 471 'post_title' => '', 472 ) ); 473 474 // we now expect the (no title) post link 475 $post_link = '<a href="' . $post_url . '">(no title)</a>'; 476 $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link ); 477 478 $a_obj = bp_activity_get( array( 479 'item_id' => 1, 480 'secondary_item_id' => $p, 481 ) ); 482 483 $this->assertSame( $expected, $a_obj['activities'][0]->action ); 484 } 485 486 /** 487 * @group bp_blogs_sync_add_from_activity_comment 488 * @group post_type_comment_activities 489 */ 490 public function test_bp_blogs_sync_add_from_activity_comment() { 491 $old_user = get_current_user_id(); 492 $u = self::factory()->user->create(); 493 $this->set_current_user( $u ); 494 $userdata = get_userdata( $u ); 495 496 // let's use activity comments instead of single "new_blog_comment" activity items 497 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 498 499 // create the blog post 500 $post_id = self::factory()->post->create( array( 501 'post_status' => 'publish', 502 'post_type' => 'post', 503 'post_title' => 'Test activity comment to post comment', 504 ) ); 505 506 // grab the activity ID for the activity comment 507 $a1 = bp_activity_get_activity_id( array( 508 'type' => 'new_blog_post', 509 'component' => buddypress()->blogs->id, 510 'filter' => array( 511 'item_id' => get_current_blog_id(), 512 'secondary_item_id' => $post_id 513 ), 514 ) ); 515 516 $a2 = bp_activity_new_comment( array( 517 'content' => 'this content shoud be in a new post comment', 518 'user_id' => $u, 519 'activity_id' => $a1, 520 ) ); 521 522 $approved_comments = get_approved_comments( $post_id ); 523 $comment = reset( $approved_comments ); 524 525 $this->assertTrue( (int) $comment->comment_ID === (int) bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ), 'The comment ID should be in the activity meta' ); 526 $this->assertTrue( (int) $a2 === (int) get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ), 'The activity ID should be in the comment meta' ); 527 528 // reset 529 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 530 531 $this->set_current_user( $old_user ); 532 } 533 534 /** 535 * @group bp_blogs_sync_delete_from_activity_comment 536 * @group post_type_comment_activities 537 */ 538 public function test_bp_blogs_sync_delete_from_activity_comment() { 539 $old_user = get_current_user_id(); 540 $u = self::factory()->user->create(); 541 $this->set_current_user( $u ); 542 $userdata = get_userdata( $u ); 543 544 // let's use activity comments instead of single "new_blog_comment" activity items 545 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 546 547 // create the blog post 548 $post_id = self::factory()->post->create( array( 549 'post_status' => 'publish', 550 'post_type' => 'post', 551 'post_title' => 'Test activity comment to post comment', 552 ) ); 553 554 // grab the activity ID for the activity comment 555 $a1 = bp_activity_get_activity_id( array( 556 'type' => 'new_blog_post', 557 'component' => buddypress()->blogs->id, 558 'filter' => array( 559 'item_id' => get_current_blog_id(), 560 'secondary_item_id' => $post_id 561 ), 562 ) ); 563 564 $a2 = bp_activity_new_comment( array( 565 'content' => 'the generated comment should be deleted once the activity comment is removed', 566 'user_id' => $u, 567 'activity_id' => $a1, 568 ) ); 569 570 bp_activity_delete_comment( $a1, $a2 ); 571 572 $post_comments = get_comments( array( 'post_id' => $post_id ) ); 573 574 $this->assertEmpty( $post_comments, 'A post comment should be deleted when the corresponding activity is' ); 575 576 // reset 577 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 578 579 $this->set_current_user( $old_user ); 580 } 581 582 /** 583 * @group bp_blogs_sync_activity_edit_to_post_comment 584 * @group post_type_comment_activities 585 */ 586 public function test_bp_blogs_sync_activity_edit_to_post_comment_spam_unspam_activity_comment() { 587 $old_user = get_current_user_id(); 588 $u = self::factory()->user->create(); 589 $this->set_current_user( $u ); 590 $userdata = get_userdata( $u ); 591 592 // let's use activity comments instead of single "new_blog_comment" activity items 593 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 594 595 // create the blog post 596 $post_id = self::factory()->post->create( array( 597 'post_status' => 'publish', 598 'post_type' => 'post', 599 'post_title' => 'Test activity comment to post comment', 600 ) ); 601 602 // grab the activity ID for the activity comment 603 $a1 = bp_activity_get_activity_id( array( 604 'type' => 'new_blog_post', 605 'component' => buddypress()->blogs->id, 606 'filter' => array( 607 'item_id' => get_current_blog_id(), 608 'secondary_item_id' => $post_id 609 ), 610 ) ); 611 612 $a2 = bp_activity_new_comment( array( 613 'content' => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed', 614 'user_id' => $u, 615 'activity_id' => $a1, 616 ) ); 617 618 $activity = new BP_Activity_Activity( $a2 ); 619 620 bp_activity_mark_as_spam( $activity ); 621 $activity->save(); 622 623 $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) ); 624 625 $this->assertEmpty( $post_comments, 'A post comment should be spammed when the corresponding activity is spammed' ); 626 627 bp_activity_mark_as_ham( $activity ); 628 $activity->save(); 629 630 $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) ); 631 $comment = reset( $post_comments ); 632 633 $this->assertTrue( (int) $comment->comment_ID === (int) bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ), 'The comment ID should be in the activity meta' ); 634 $this->assertTrue( (int) $a2 === (int) get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ), 'The activity ID should be in the comment meta' ); 635 636 // reset 637 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 638 639 $this->set_current_user( $old_user ); 640 } 641 642 /** 643 * @group bp_blogs_sync_activity_edit_to_post_comment 644 * @group post_type_comment_activities 645 */ 646 public function test_bp_blogs_sync_activity_edit_to_post_comment_spam_activity_comment_unspam_post_comment() { 647 $old_user = get_current_user_id(); 648 $u = self::factory()->user->create(); 649 $this->set_current_user( $u ); 650 $userdata = get_userdata( $u ); 651 652 // let's use activity comments instead of single "new_blog_comment" activity items 653 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 654 655 // create the blog post 656 $post_id = self::factory()->post->create( array( 657 'post_status' => 'publish', 658 'post_type' => 'post', 659 'post_title' => 'Test activity comment to post comment', 660 ) ); 661 662 // grab the activity ID for the activity comment 663 $a1 = bp_activity_get_activity_id( array( 664 'type' => 'new_blog_post', 665 'component' => buddypress()->blogs->id, 666 'filter' => array( 667 'item_id' => get_current_blog_id(), 668 'secondary_item_id' => $post_id 669 ), 670 ) ); 671 672 $a2 = bp_activity_new_comment( array( 673 'content' => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed', 674 'user_id' => $u, 675 'activity_id' => $a1, 676 ) ); 677 678 $c = bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ); 679 680 $activity = new BP_Activity_Activity( $a2 ); 681 682 bp_activity_mark_as_spam( $activity ); 683 $activity->save(); 684 685 wp_unspam_comment( $c ); 686 687 $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) ); 688 $comment = reset( $post_comments ); 689 690 $this->assertTrue( (int) $comment->comment_ID === (int) bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ), 'The comment ID should be in the activity meta' ); 691 $this->assertTrue( (int) $a2 === (int) get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ), 'The activity ID should be in the comment meta' ); 692 693 // reset 694 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 695 696 $this->set_current_user( $old_user ); 697 } 698 699 /** 700 * @group bp_blogs_sync_activity_edit_to_post_comment 701 * @group post_type_comment_activities 702 */ 703 public function test_bp_blogs_sync_activity_edit_to_post_comment_trash_comment_ham_activity() { 704 $old_user = get_current_user_id(); 705 $u = self::factory()->user->create(); 706 $this->set_current_user( $u ); 707 $userdata = get_userdata( $u ); 708 709 // let's use activity comments instead of single "new_blog_comment" activity items 710 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 711 712 // create the blog post 713 $post_id = self::factory()->post->create( array( 714 'post_status' => 'publish', 715 'post_type' => 'post', 716 'post_title' => 'Test activity comment to post comment', 717 ) ); 718 719 // grab the activity ID for the activity comment 720 $a1 = bp_activity_get_activity_id( array( 721 'type' => 'new_blog_post', 722 'component' => buddypress()->blogs->id, 723 'filter' => array( 724 'item_id' => get_current_blog_id(), 725 'secondary_item_id' => $post_id 726 ), 727 ) ); 728 729 $a2 = bp_activity_new_comment( array( 730 'content' => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed', 731 'user_id' => $u, 732 'activity_id' => $a1, 733 ) ); 734 735 $c = bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ); 736 737 wp_trash_comment( $c ); 738 739 $activity = new BP_Activity_Activity( $a2 ); 740 741 bp_activity_mark_as_ham( $activity ); 742 $activity->save(); 743 744 $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) ); 745 $comment = reset( $post_comments ); 746 747 $this->assertTrue( (int) $comment->comment_ID === (int) bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ), 'The comment ID should be in the activity meta' ); 748 $this->assertTrue( (int) $a2 === (int) get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ), 'The activity ID should be in the comment meta' ); 749 750 // reset 751 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 752 753 $this->set_current_user( $old_user ); 754 } 755 756 /** 757 * @group bp_blogs_sync_activity_edit_to_post_comment 758 * @group post_type_comment_activities 759 */ 760 public function test_spammed_activity_comment_should_not_create_post_comment() { 761 $old_user = get_current_user_id(); 762 $u = self::factory()->user->create(); 763 $this->set_current_user( $u ); 764 $userdata = get_userdata( $u ); 765 766 // let's use activity comments instead of single "new_blog_comment" activity items. 767 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 768 769 // create the blog post. 770 $post_id = self::factory()->post->create( array( 771 'post_status' => 'publish', 772 'post_type' => 'post', 773 'post_title' => 'Test activity comment to post comment', 774 ) ); 775 776 // Grab the activity ID for the activity comment. 777 $a1 = bp_activity_get_activity_id( array( 778 'type' => 'new_blog_post', 779 'component' => buddypress()->blogs->id, 780 'filter' => array( 781 'item_id' => get_current_blog_id(), 782 'secondary_item_id' => $post_id 783 ), 784 ) ); 785 786 // Set activity item to spam. 787 add_action( 'bp_activity_before_save', array( $this, 'set_activity_to_spam' ) ); 788 789 // Create spammed activity comment. 790 $a2 = bp_activity_new_comment( array( 791 'content' => 'this activity comment shoud not be created as a new post comment. yolo.', 792 'user_id' => $u, 793 'activity_id' => $a1, 794 ) ); 795 796 // Grab post comments. 797 $approved_comments = get_approved_comments( $post_id ); 798 $comment = reset( $approved_comments ); 799 800 // Assert that post comment wasn't created. 801 $this->assertEmpty( $comment ); 802 803 // Reset. 804 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 805 remove_action( 'bp_activity_before_save', array( $this, 'set_activity_to_spam' ) ); 806 807 $this->set_current_user( $old_user ); 808 } 809 810 /** 811 * Dopey passthrough method so we can check that the correct values 812 * are being passed to the filter 813 */ 814 public function created_blog_passthrough( $a, $b ) { 815 $this->userblog_id = isset( $b->id ) ? $b->id : ''; 816 return $a; 817 } 818 819 /** 820 * Dopey passthrough method so we can check that the correct values 821 * are being passed to the filter 822 */ 823 public function new_post_passthrough( $a, $b ) { 824 $this->post_id = isset( $b->ID ) ? $b->ID : ''; 825 return $a; 826 } 827 828 /** 829 * Dopey passthrough method so we can check that the correct values 830 * are being passed to the filter 831 */ 832 public function new_comment_passthrough( $a, $b ) { 833 $this->comment_post_id = isset( $b->comment_post_ID ) ? $b->comment_post_ID : ''; 834 return $a; 835 } 836 837 /** 838 * Explicitly set activity to spam. 839 */ 840 public function set_activity_to_spam( $activity ) { 841 $activity->is_spam = 1; 842 } 843 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Dec 26 01:01:04 2024 | Cross-referenced by PHPXref 0.7.1 |