Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/18/2014 04:51:11 PM (10 years ago)
Author:
r-a-y
Message:

Add activity meta when recording a blog post or blog comment.

This commit:

  • Adds the post_title and post_url information as activity meta when recording a blog post or blog comment into the activity table.
  • Updates the post_title and post_url activity meta whenever a blog post is updated.
  • Adds a unit test.

This addresses issues with showing the correct blog post information in the
activity loop for blog post and blog comment activity items.

Props r-a-y, DJPaul, boonebgorges.

Fixes #5609.

File:
1 edited

Legend:

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

    r8491 r8944  
    395395    }
    396396
     397    /**
     398     * @group bp_blogs_catch_transition_post_status
     399     */
     400    public function test_update_blog_post_and_new_blog_comment_and_activity_comment_meta() {
     401        // save the current user and override logged-in user
     402        $old_user = get_current_user_id();
     403        $u = $this->create_user();
     404        $this->set_current_user( $u );
     405        $userdata = get_userdata( $u );
     406
     407        // create the blog post
     408        $post_id = $this->factory->post->create( array(
     409            'post_status' => 'publish',
     410            'post_type' => 'post',
     411            'post_title' => 'First title',
     412        ) );
     413
     414        // remove comment flood protection temporarily
     415        add_filter( 'comment_flood_filter', '__return_false' );
     416
     417        // let's use activity comments instead of single "new_blog_comment" activity items
     418        add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     419        $c1 = wp_new_comment( array(
     420            'comment_post_ID'      => $post_id,
     421            'comment_author'       => $userdata->user_nicename,
     422            'comment_author_url'   => 'http://buddypress.org',
     423            'comment_author_email' => $userdata->user_email,
     424            'comment_content'      => 'this is a blog comment',
     425            'comment_type'         => '',
     426            'comment_parent'       => 0,
     427            'user_id'              => $u,
     428        ) );
     429        remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     430
     431        // let's also add a "new_blog_comment" activity entry
     432        $c2 = wp_new_comment( array(
     433            'comment_post_ID'      => $post_id,
     434            'comment_author'       => $userdata->user_nicename,
     435            'comment_author_url'   => 'http://buddypress.org',
     436            'comment_author_email' => $userdata->user_email,
     437            'comment_content'      => 'this is another blog comment',
     438            'comment_type'         => '',
     439            'comment_parent'       => 0,
     440            'user_id'              => $u,
     441        ) );
     442
     443        // bring back flood protection
     444        remove_filter( 'comment_flood_filter', '__return_false' );
     445
     446        // update the initial blog post
     447        wp_update_post( array(
     448            'ID'        => $post_id,
     449            'post_title' => 'Second title',
     450        ) );
     451
     452        // grab the activity ID for the activity comment
     453        $a1 = bp_activity_get_activity_id( array(
     454            'type'              => 'activity_comment',
     455            'display_comments'  => 'stream',
     456            'meta_query'        => array( array(
     457                'key'     => 'bp_blogs_post_comment_id',
     458                'value'   => $c1,
     459            ) )
     460        ) );
     461
     462        // grab the activity ID for the blog comment
     463        $a2 = bp_activity_get_activity_id( array(
     464            'component'         => buddypress()->blogs->id,
     465            'type'              => 'new_blog_comment',
     466            'secondary_item_id' => $c2,
     467        ) );
     468
     469        // see if blog comment activity meta matches the post items
     470        $this->assertEquals( 'Second title', bp_activity_get_meta( $a1, 'post_title' ) );
     471        $this->assertEquals( add_query_arg( 'p', $post_id, home_url( '/' ) ), bp_activity_get_meta( $a1, 'post_url' ) );
     472
     473        $this->assertEquals( 'Second title', bp_activity_get_meta( $a2, 'post_title' ) );
     474        $this->assertEquals( add_query_arg( 'p', $post_id, home_url( '/' ) ), bp_activity_get_meta( $a2, 'post_url' ) );
     475
     476        // reset
     477        $this->set_current_user( $old_user );
     478    }
     479
    397480    protected function activity_exists_for_post( $post_id ) {
    398481        $a = bp_activity_get( array(
Note: See TracChangeset for help on using the changeset viewer.