Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/01/2021 05:43:00 PM (3 years ago)
Author:
imath
Message:

Activity: make sure Activity author is synced with Post Type author

When the author of a Post has been updated, the corresponding user_id into the related Post Type Activity needs to be updated as well.

Props rigsbyx

Fixes #8579

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/activity/actions.php

    r11737 r13135  
    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,
     
    176252        ) );
    177253
     254        if ( $get_object ) {
     255            return reset( $a['activities'] );
     256        }
     257
    178258        return ! empty( $a['activities'] );
    179259    }
Note: See TracChangeset for help on using the changeset viewer.