Changeset 10252 for trunk/tests/phpunit/testcases/blogs/functions.php
- Timestamp:
- 10/11/2015 10:14:29 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/blogs/functions.php
r10034 r10252 712 712 } 713 713 714 /** 715 * @group bp_blogs_record_comment 716 * @group unique 717 */ 718 public function test_bp_blogs_record_comment_no_duplicate_activity_comments() { 719 // save the current user and override logged-in user 720 $old_user = get_current_user_id(); 721 $u = $this->factory->user->create(); 722 $this->set_current_user( $u ); 723 $userdata = get_userdata( $u ); 724 $this->activity_saved_comment_count = 0; 725 $this->comment_saved_count = 0; 726 727 // let's use activity comments instead of single "new_blog_comment" activity items 728 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 729 add_action( 'bp_activity_add', array( $this, 'count_activity_comment_saved' ) ); 730 add_action( 'wp_insert_comment', array( $this, 'count_post_comment_saved' ) ); 731 add_action( 'edit_comment', array( $this, 'count_post_comment_saved' ) ); 732 733 // create the blog post 734 $post_id = $this->factory->post->create( array( 735 'post_status' => 'publish', 736 'post_type' => 'post', 737 'post_title' => 'Test Duplicate activity comments', 738 ) ); 739 740 // grab the activity ID for the activity comment 741 $a1 = bp_activity_get_activity_id( array( 742 'type' => 'new_blog_post', 743 'component' => buddypress()->blogs->id, 744 'filter' => array( 745 'item_id' => get_current_blog_id(), 746 'secondary_item_id' => $post_id 747 ), 748 ) ); 749 750 $a2 = bp_activity_new_comment( array( 751 'content' => 'activity comment should be unique', 752 'user_id' => $u, 753 'activity_id' => $a1, 754 ) ); 755 756 $activities = bp_activity_get( array( 757 'type' => 'activity_comment', 758 'display_comments' => 'stream', 759 'search_terms' => 'activity comment should be unique', 760 ) ); 761 762 $this->assertTrue( count( $activities['activities'] ) === 1, 'An activity comment should be unique' ); 763 764 $this->assertTrue( 2 === $this->activity_saved_comment_count, 'An activity comment should be saved only twice' ); 765 $this->assertTrue( 1 === $this->comment_saved_count, 'A comment should be saved only once' ); 766 767 // reset 768 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 769 remove_action( 'bp_activity_add', array( $this, 'count_activity_comment_saved' ) ); 770 remove_action( 'wp_insert_comment', array( $this, 'count_post_comment_saved' ) ); 771 remove_action( 'edit_comment', array( $this, 'count_post_comment_saved' ) ); 772 773 $this->activity_saved_comment_count = 0; 774 $this->comment_saved_count = 0; 775 $this->set_current_user( $old_user ); 776 } 777 778 public function count_activity_comment_saved() { 779 $this->activity_saved_comment_count += 1; 780 } 781 782 public function count_post_comment_saved() { 783 $this->comment_saved_count += 1; 784 } 785 714 786 protected function activity_exists_for_post( $post_id ) { 715 787 $a = bp_activity_get( array(
Note: See TracChangeset
for help on using the changeset viewer.