Skip to:
Content

BuddyPress.org

Changeset 10550


Ignore:
Timestamp:
02/07/2016 06:13:27 PM (9 years ago)
Author:
imath
Message:

Post Type Activities: make sure an activity is generated when the post is edited.

Props r-a-y

Fixes #6834

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-actions.php

    r10544 r10550  
    798798        // An edit of an existing post should update the existing activity item.
    799799        if ( $new_status == 'publish' ) {
    800             bp_activity_post_type_update( $post );
     800            $edit = bp_activity_post_type_update( $post );
     801
     802            // Post was never recorded into activity stream, so record it now!
     803            if ( null === $edit ) {
     804                bp_activity_post_type_publish( $post->ID, $post );
     805            }
    801806        }
    802807
  • trunk/tests/phpunit/testcases/activity/actions.php

    r10545 r10550  
    5050        $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' );
    5151
    52         // Delete the activity
    53         bp_activity_post_type_unpublish( $post_id, $post );
     52        _unregister_post_type( 'foo' );
     53    }
    5454
    55         $post->post_status = 'publish';
    56         $post->post_content .= ' foo';
     55    /**
     56     * @group bp_activity_catch_transition_post_type_status
     57     * @group activity_tracking
     58     */
     59    public function test_bp_activity_catch_transition_post_type_status_publish_existing_post() {
     60        $u = $this->factory->user->create();
    5761
    58         wp_update_post( $post );
     62        $labels = array(
     63            'bp_activity_admin_filter' => 'New Foo',
     64            'bp_activity_front_filter' => 'Foos',
     65                'bp_activity_new_post'    => '%1$s posted a new <a href="%2$s">foo</a>',
     66                'bp_activity_new_post_ms' => '%1$s posted a new <a href="%2$s">foo</a>, on the site %3$s',
     67        );
    5968
    60         $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Updating a post type should not create a new activity' );
     69        /**
     70         * 'public' must be set to true, otherwise bp_activity_get_post_types_tracking_args() fails.
     71         */
     72        register_post_type( 'foo', array(
     73            'labels'      => $labels,
     74            'public'      => true,
     75            'supports'    => array( 'buddypress-activity' ),
     76            'bp_activity' => array(
     77                'action_id'    => 'new_foo',
     78                'contexts'     => array( 'activity' ),
     79                'position'     => 40,
     80            )
     81        ) );
    6182
     83        // Temporarily remove post type activity hook so activity item isn't created.
     84        remove_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 );
     85
     86        // Create the initial post.
     87        $p = $this->factory->post->create( array(
     88            'post_author' => $u,
     89            'post_type'   => 'foo',
     90        ) );
     91
     92        $this->assertEmpty( bp_activity_get_activity_id( array( 'type' => 'new_foo' ) ) );
     93
     94        // Add the post type activity hook back.
     95        add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 );
     96
     97        // Emulate updating a post; this should create an activity item.
     98        wp_update_post( array(
     99            'ID'     => $p,
     100            'post_title' => 'This is an edit',
     101        ) );
     102
     103        // Assert!
     104        $this->assertNotEmpty( bp_activity_get_activity_id( array( 'type' => 'new_foo' ) ), 'Activity item was not created during an edit of an existing WordPress post.' );
     105
     106        // Clean up.
    62107        _unregister_post_type( 'foo' );
    63108    }
Note: See TracChangeset for help on using the changeset viewer.