Skip to:
Content

BuddyPress.org

Ticket #8579: 8579.2.patch

File 8579.2.patch, 3.5 KB (added by imath, 3 years ago)
  • src/bp-activity/bp-activity-functions.php

    diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php
    index e8487a78f..255e4f0f3 100644
    function bp_activity_post_type_update( $post = null ) { 
    23112311        // Update the activity entry.
    23122312        $activity = new BP_Activity_Activity( $activity_id );
    23132313
     2314        // Check if the Post author has changed.
     2315        if ( (int) $post->post_author !== (int) $activity->user_id ) {
     2316                $activity->user_id = (int) $post->post_author;
     2317        }
     2318
    23142319        if ( ! empty( $post->post_content ) ) {
    23152320                $activity_summary = bp_activity_create_summary( $post->post_content, (array) $activity );
    23162321
  • tests/phpunit/testcases/activity/actions.php

    diff --git tests/phpunit/testcases/activity/actions.php tests/phpunit/testcases/activity/actions.php
    index 2b2b00a93..2bf82399e 100644
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    168168                _unregister_post_type( 'foo' );
    169169        }
    170170
    171         protected function activity_exists_for_post( $post_id, $action ) {
     171        /**
     172         * @ticket BP8579
     173         * @group bp_activity_catch_transition_post_type_status
     174         * @group activity_tracking
     175         */
     176        public function test_bp_activity_catch_transition_post_type_status_publish_publish_author_changed() {
     177                $u1 = self::factory()->user->create(
     178                        array(
     179                                'role' => 'auhor',
     180                        )
     181                );
     182
     183                $u2 = self::factory()->user->create(
     184                        array(
     185                                'role' => 'auhor',
     186                        )
     187                );
     188
     189                $post_id = self::factory()->post->create( array(
     190                        'post_status' => 'publish',
     191                        'post_author' => $u1,
     192                        'post_type'   => 'post',
     193                ) );
     194
     195                $post = get_post( $post_id );
     196
     197                // 'new' => 'publish'
     198                $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_post' ), 'Published post type should have activity' );
     199
     200                $post->post_author = $u2;
     201
     202                wp_update_post( $post );
     203
     204                $a = $this->activity_exists_for_post( $post_id, 'new_post', true );
     205
     206                $this->assertSame( $u2, $a->user_id, 'The Activity about a published post type should be updated when the post author has changed.' );
     207        }
     208
     209        /**
     210         * @ticket BP8579
     211         * @group bp_activity_catch_transition_post_type_status
     212         * @group activity_tracking
     213         */
     214        public function test_bp_activity_catch_transition_post_type_status_publish_publish_content_changed() {
     215                $u1 = self::factory()->user->create(
     216                        array(
     217                                'role' => 'auhor',
     218                        )
     219                );
     220
     221                $u2 = self::factory()->user->create(
     222                        array(
     223                                'role' => 'auhor',
     224                        )
     225                );
     226
     227                $post_id = self::factory()->post->create( array(
     228                        'post_status' => 'publish',
     229                        'post_author' => $u1,
     230                        'post_type'   => 'post',
     231                ) );
     232
     233                $post = get_post( $post_id );
     234
     235                // 'new' => 'publish'
     236                $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_post' ), 'Published post type should have activity' );
     237
     238                $post->post_content = "This time {$u2} has not edited the post";
     239
     240                wp_update_post( $post );
     241
     242                $a = $this->activity_exists_for_post( $post_id, 'new_post', true );
     243
     244                $this->assertSame( $post->post_content, $a->content, 'The Activity about a published post type should be updated when the post content has changed.' );
     245        }
     246
     247        protected function activity_exists_for_post( $post_id, $action, $get_object = false ) {
    172248                $a = bp_activity_get( array(
    173249                        'action'            => $action,
    174250                        'item_id'           => get_current_blog_id(),
    175251                        'secondary_item_id' => $post_id,
    176252                ) );
    177253
     254                if ( $get_object) {
     255                        return reset( $a['activities'] );
     256                }
     257
    178258                return ! empty( $a['activities'] );
    179259        }
    180260}