Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/07/2016 04:55:04 PM (10 years ago)
Author:
imath
Message:

Post Type Activities: add unit tests and improve existing ones.

See #6482
Fixes #6128

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/blogs/functions.php

    r10277 r10545  
    514514        /**
    515515         * @group bp_blogs_catch_transition_post_status
     516         * @group post_type_comment_activities
    516517         */
    517518        public function test_update_blog_post_and_new_blog_comment_and_activity_comment_meta() {
     
    597598        /**
    598599         * @group bp_blogs_transition_activity_status
    599          * @group bp_blogs_remove_comment
     600         * @group bp_blogs_post_type_remove_comment
     601         * @group post_type_comment_activities
    600602         */
    601603        public function test_bp_blogs_remove_comment_should_remove_spammed_activity_comment() {
     
    659661
    660662        /**
     663         * @group bp_blogs_post_type_remove_comment
     664         * @group post_type_comment_activities
     665         */
     666        public function test_bp_blogs_post_type_remove_comment() {
     667                $old_user = get_current_user_id();
     668                $u = $this->factory->user->create();
     669                $this->set_current_user( $u );
     670                $userdata = get_userdata( $u );
     671
     672                // create the blog post
     673                $p = $this->factory->post->create( array(
     674                        'post_status' => 'publish',
     675                        'post_type' => 'post',
     676                        'post_title' => 'First title',
     677                ) );
     678
     679                $c = wp_new_comment( array(
     680                        'comment_post_ID'      => $p,
     681                        'comment_author'       => $userdata->user_nicename,
     682                        'comment_author_url'   => 'http://buddypress.org',
     683                        'comment_author_email' => $userdata->user_email,
     684                        'comment_content'      => 'this comment will be removed',
     685                        'comment_type'         => '',
     686                        'comment_parent'       => 0,
     687                        'user_id'              => $u,
     688                ) );
     689
     690                // An activity should exist
     691                $a = bp_activity_get_activity_id( array(
     692                        'user_id' => $u,
     693                        'type'    => 'new_blog_comment'
     694                ) );
     695
     696                // now permanently delete the comment
     697                wp_delete_comment( $c, true );
     698
     699                // The activity comment should no longer exist
     700                $ac = bp_activity_get( array( 'in' => $a ) );
     701                $this->assertTrue( empty( $ac['activities'] ) );
     702        }
     703
     704        /**
    661705         * @group bp_blogs_catch_transition_post_status
    662706         */
     
    715759         * @group bp_blogs_record_comment
    716760         * @group unique
     761         * @group post_type_comment_activities
    717762         */
    718763        public function test_bp_blogs_record_comment_no_duplicate_activity_comments() {
     
    778823        /**
    779824         * @group bp_blogs_record_comment
     825         * @group post_type_comment_activities
    780826         */
    781827        public function test_bp_blogs_record_comment_should_record_parent_blog_post_activity_if_not_found() {
     
    827873                ) );
    828874
     875                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     876
    829877                // Assert that activity item for blog post was created after adding a comment
    830878                $this->assertNotNull( $a1, 'Activity item was not created for existing blog post when recording post comment.' );
    831879
    832880                $this->set_current_user( $old_user );
     881        }
     882
     883        /**
     884         * @group bp_blogs_comment_sync_activity_comment
     885         * @group post_type_comment_activities
     886         */
     887        public function test_bp_blogs_comment_sync_activity_comment_for_custom_post_type() {
     888                if ( is_multisite() ) {
     889                        $b = $this->factory->blog->create();
     890                        switch_to_blog( $b );
     891                        add_filter( 'comment_flood_filter', '__return_false' );
     892                } else {
     893                        $b = get_current_blog_id();
     894                }
     895
     896                $u = $this->factory->user->create();
     897                $userdata = get_userdata( $u );
     898
     899                $labels = array(
     900                        'name'                       => 'bars',
     901                        'singular_name'              => 'bar',
     902                );
     903
     904                register_post_type( 'foo', array(
     905                        'labels'   => $labels,
     906                        'public'   => true,
     907                        'supports' => array( 'comments' ),
     908                ) );
     909
     910                add_post_type_support( 'foo', 'buddypress-activity' );
     911
     912                bp_activity_set_post_type_tracking_args( 'foo', array(
     913                        'comment_action_id' => 'new_foo_comment',
     914                ) );
     915
     916                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     917
     918                $p = $this->factory->post->create( array(
     919                        'post_author' => $u,
     920                        'post_type'   => 'foo',
     921                ) );
     922
     923                $a1 = bp_activity_get_activity_id( array(
     924                        'type'      => 'new_foo',
     925                        'filter'    => array(
     926                                'item_id' => $b,
     927                                'secondary_item_id' => $p
     928                        ),
     929                ) );
     930
     931                $c = wp_new_comment( array(
     932                        'comment_post_ID'      => $p,
     933                        'comment_author'       => $userdata->user_nicename,
     934                        'comment_author_url'   => 'http://buddypress.org',
     935                        'comment_author_email' => $userdata->user_email,
     936                        'comment_content'      => 'this is a foo comment',
     937                        'comment_type'         => '',
     938                        'comment_parent'       => 0,
     939                        'user_id'              => $u,
     940                ) );
     941
     942                $a2 = bp_activity_new_comment( array(
     943                        'content'     => 'this should generate a new foo comment',
     944                        'user_id'     => $u,
     945                        'activity_id' => $a1,
     946                ) );
     947
     948                $activity_args = array(
     949                        'type'              => 'activity_comment',
     950                        'display_comments'  => 'stream',
     951                        'meta_query'        => array( array(
     952                                'key'       => 'bp_blogs_foo_comment_id',
     953                                'compare'   => 'exists',
     954                        ) )
     955                );
     956
     957                $a = bp_activity_get( $activity_args );
     958                $aids = wp_list_pluck( $a['activities'], 'id' );
     959                $cids = wp_list_pluck( get_approved_comments( $p ), 'comment_ID' );
     960
     961                foreach ( $aids as $aid ) {
     962                        $this->assertTrue( in_array( bp_activity_get_meta( $aid, 'bp_blogs_foo_comment_id' ), $cids ), 'The comment ID should be in the activity meta' );
     963                }
     964
     965                foreach ( $cids as $cid ) {
     966                        $this->assertTrue( in_array( get_comment_meta( $cid, 'bp_activity_comment_id', true ), $aids ), 'The activity ID should be in the comment meta' );
     967                }
     968
     969                _unregister_post_type( 'foo' );
     970
     971                if ( is_multisite() ) {
     972                        restore_current_blog();
     973                        remove_filter( 'comment_flood_filter', '__return_false' );
     974                }
     975
     976                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
    833977        }
    834978
Note: See TracChangeset for help on using the changeset viewer.