| 778 | /** |
| 779 | * @group bp_blogs_record_comment |
| 780 | */ |
| 781 | public function test_bp_blogs_record_comment_should_record_parent_blog_post_activity_if_not_found() { |
| 782 | // Save the current user and override logged-in user |
| 783 | $old_user = get_current_user_id(); |
| 784 | $u = $this->factory->user->create(); |
| 785 | $this->set_current_user( $u ); |
| 786 | |
| 787 | // Get user details |
| 788 | $user = get_userdata( $u ); |
| 789 | |
| 790 | // Let's use activity comments instead of single "new_blog_comment" activity items |
| 791 | add_filter( 'bp_disable_blogforum_comments', '__return_false' ); |
| 792 | |
| 793 | // Create the blog post |
| 794 | $post_id = $this->factory->post->create( array( |
| 795 | 'post_status' => 'publish', |
| 796 | 'post_type' => 'post', |
| 797 | ) ); |
| 798 | |
| 799 | // Grab the activity ID for the blog post |
| 800 | $a1 = bp_activity_get_activity_id( array( |
| 801 | 'type' => 'new_blog_post', |
| 802 | 'component' => buddypress()->blogs->id, |
| 803 | 'filter' => array( |
| 804 | 'item_id' => get_current_blog_id(), |
| 805 | 'secondary_item_id' => $post_id |
| 806 | ), |
| 807 | ) ); |
| 808 | |
| 809 | // Now, delete the activity item for the blog post |
| 810 | bp_activity_delete( array( 'id' => $a1 ) ); |
| 811 | |
| 812 | // Add a comment to blog post |
| 813 | wp_new_comment( array( |
| 814 | 'comment_post_ID' => $post_id, |
| 815 | 'user_id' => $u, |
| 816 | 'comment_content' => 'Dummy comment', |
| 817 | 'comment_author' => 'Dumbo', |
| 818 | 'comment_author_url' => 'http://buddypress.org', |
| 819 | |
| 820 | // Important to pass check in bp_blogs_record_comment() |
| 821 | 'comment_author_email' => $user->user_email |
| 822 | ) ); |
| 823 | |
| 824 | // Now, re-fetch the activity ID for the blog post to see if it exists |
| 825 | $a1 = bp_activity_get_activity_id( array( |
| 826 | 'type' => 'new_blog_post', |
| 827 | 'component' => buddypress()->blogs->id, |
| 828 | 'filter' => array( |
| 829 | 'item_id' => get_current_blog_id(), |
| 830 | 'secondary_item_id' => $post_id |
| 831 | ), |
| 832 | ) ); |
| 833 | |
| 834 | // Assert that activity item for blog post was created after adding a comment |
| 835 | $this->assertNotNull( $a1, 'Activity item was not created for existing blog post when recording post comment.' ); |
| 836 | |
| 837 | $this->set_current_user( $old_user ); |
| 838 | } |
| 839 | |