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/activity/functions.php

    r10515 r10545  
    764764        }
    765765
    766         $bp = buddypress();
    767 
    768766        register_post_type( 'foo', array(
    769767            'label'   => 'foo',
     
    801799
    802800        _unregister_post_type( 'foo' );
    803 
    804         // Reset globals
    805         unset( $bp->activity->actions->activity->new_foo );
    806         $bp->activity->track = array();
    807801    }
    808802
     
    816810            return;
    817811        }
    818 
    819         $bp = buddypress();
    820812
    821813        $b = $this->factory->blog->create();
     
    864856
    865857        $this->assertSame( $expected, $a_obj->action );
    866 
    867         // Reset globals
    868         unset( $bp->activity->actions->activity->new_foo );
    869         $bp->activity->track = array();
    870858    }
    871859
     
    879867            return;
    880868        }
    881 
    882         $bp = buddypress();
    883869
    884870        $labels = array(
     
    925911
    926912        _unregister_post_type( 'foo' );
    927 
    928         // Reset globals
    929         unset( $bp->activity->actions->activity->foo_bar );
    930         $bp->activity->track = array();
    931913    }
    932914
     
    940922            return;
    941923        }
    942 
    943         $bp = buddypress();
    944         $reset = $bp->activity->actions;
    945924
    946925        $b = $this->factory->blog->create();
     
    992971
    993972        $this->assertSame( $expected, $a_obj->action );
    994 
    995         // Reset globals
    996         unset( $bp->activity->actions->activity->new_foo );
    997         $bp->activity->track = array();
    998973    }
    999974
     
    10321007
    10331008        remove_post_type_support( 'page', 'buddypress-activity' );
    1034 
    1035         // Reset globals
    1036         unset( $bp->activity->actions->blogs->new_page );
    1037         $bp->activity->track = array();
    10381009    }
    10391010
     
    10741045
    10751046        $this->assertSame( $set_bp_activity, $register_bp_activity );
     1047    }
     1048
     1049    /**
     1050     * @group activity_action
     1051     * @group bp_activity_format_activity_action_custom_post_type_post_ms
     1052     * @group post_type_comment_activities
     1053     */
     1054    public function test_bp_activity_format_activity_action_custom_post_type_comment() {
     1055        if ( is_multisite() ) {
     1056            $b = $this->factory->blog->create();
     1057            switch_to_blog( $b );
     1058            add_filter( 'comment_flood_filter', '__return_false' );
     1059        } else {
     1060            $b = get_current_blog_id();
     1061        }
     1062
     1063        $u = $this->factory->user->create();
     1064        $userdata = get_userdata( $u );
     1065
     1066        $labels = array(
     1067            'name'                       => 'bars',
     1068            'singular_name'              => 'bar',
     1069            'bp_activity_new_comment'    => __( '%1$s commented on the <a href="%2$s">bar</a>', 'buddypress' ),
     1070            'bp_activity_new_comment_ms' => __( '%1$s commented on the <a href="%2$s">bar</a>, on the site %3$s', 'buddypress' ),
     1071        );
     1072
     1073        register_post_type( 'foo', array(
     1074            'labels'   => $labels,
     1075            'public'   => true,
     1076            'supports' => array( 'buddypress-activity', 'comments' ),
     1077            'bp_activity' => array(
     1078                'action_id'         => 'new_bar',
     1079                'comment_action_id' => 'new_bar_comment',
     1080            ),
     1081        ) );
     1082
     1083        // Build the actions to fetch the tracking args
     1084        bp_activity_get_actions();
     1085
     1086        $p = $this->factory->post->create( array(
     1087            'post_author' => $u,
     1088            'post_type'   => 'foo',
     1089        ) );
     1090
     1091        $c = wp_new_comment( array(
     1092            'comment_post_ID'      => $p,
     1093            'comment_author'       => $userdata->user_nicename,
     1094            'comment_author_url'   => 'http://buddypress.org',
     1095            'comment_author_email' => $userdata->user_email,
     1096            'comment_content'      => 'this is a blog comment',
     1097            'comment_type'         => '',
     1098            'comment_parent'       => 0,
     1099            'user_id'              => $u,
     1100        ) );
     1101
     1102        $a = bp_activity_get_activity_id( array( 'type' => 'new_bar_comment' ) );
     1103
     1104        $a_obj = new BP_Activity_Activity( $a );
     1105
     1106        $user_link    = bp_core_get_userlink( $u );
     1107        $comment_url  = get_comment_link( $c );
     1108
     1109        _unregister_post_type( 'foo' );
     1110
     1111        if ( is_multisite() ) {
     1112            $blog_url  = get_blog_option( $a_obj->item_id, 'home' );
     1113            restore_current_blog();
     1114            remove_filter( 'comment_flood_filter', '__return_false' );
     1115
     1116            $expected = sprintf( $labels['bp_activity_new_comment_ms'], $user_link, $comment_url, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
     1117        } else {
     1118            $expected = sprintf( $labels['bp_activity_new_comment'], $user_link, $comment_url );
     1119        }
     1120
     1121        $this->assertSame( $expected, $a_obj->action );
    10761122    }
    10771123
Note: See TracChangeset for help on using the changeset viewer.