Skip to:
Content

BuddyPress.org

Ticket #6494: 6494.unittest.patch

File 6494.unittest.patch, 2.0 KB (added by imath, 9 years ago)
  • tests/phpunit/testcases/blogs/functions.php

    diff --git tests/phpunit/testcases/blogs/functions.php tests/phpunit/testcases/blogs/functions.php
    index d2e36b2..f213012 100644
    class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 
    648648                remove_filter( 'bp_is_blog_public', '__return_zero' );
    649649        }
    650650
     651        /**
     652         * @group bp_blogs_record_comment
     653         */
     654        public function test_bp_blogs_record_comment_no_duplicate_activity_comments() {
     655                // save the current user and override logged-in user
     656                $old_user = get_current_user_id();
     657                $u = $this->factory->user->create();
     658                $this->set_current_user( $u );
     659                $userdata = get_userdata( $u );
     660
     661                // let's use activity comments instead of single "new_blog_comment" activity items
     662                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     663
     664                // create the blog post
     665                $post_id = $this->factory->post->create( array(
     666                        'post_status' => 'publish',
     667                        'post_type'   => 'post',
     668                        'post_title'  => 'Test Duplicate activity comments',
     669                ) );
     670
     671                // grab the activity ID for the activity comment
     672                $a1 = bp_activity_get_activity_id( array(
     673                        'type'      => 'new_blog_post',
     674                        'component' => buddypress()->blogs->id,
     675                        'filter'    => array(
     676                                'item_id' => get_current_blog_id(),
     677                                'secondary_item_id' => $post_id
     678                        ),
     679                ) );
     680
     681                $a2 = bp_activity_new_comment( array(
     682                        'content'     => 'activity comment should be unique',
     683                        'user_id'     => $u,
     684                        'activity_id' => $a1,
     685                ) );
     686
     687                $activities = bp_activity_get( array(
     688                        'type'             => 'activity_comment',
     689                        'display_comments' => 'stream',
     690                        'search_terms'     => 'activity comment should be unique',
     691                ) );
     692
     693                $this->assertTrue( count( $activities['activities'] ) === 1, 'An activity comment should be unique' );
     694
     695                // reset
     696                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     697                $this->set_current_user( $old_user );
     698        }
     699
    651700        protected function activity_exists_for_post( $post_id ) {
    652701                $a = bp_activity_get( array(
    653702                        'component' => buddypress()->blogs->id,