Skip to:
Content

BuddyPress.org

Ticket #8007: 8007.unit-test.patch

File 8007.unit-test.patch, 2.6 KB (added by r-a-y, 6 years ago)
  • tests/phpunit/testcases/blogs/activity.php

     
    309309                $this->assertEquals( $this->comment_post_id, $p );
    310310        }
    311311
     312        /**
     313         * @group post_type_comment_activities
     314         * @group ray
     315         */
     316        public function test_bp_blogs_update_post_title_activity_meta_should_not_be_the_same_for_same_comment_id() {
     317                global $wpdb;
     318
     319                if ( ! is_multisite() ) {
     320                        $this->markTestSkipped();
     321                }
     322
     323                if ( function_exists( 'wp_initialize_site' ) ) {
     324                        $this->setExpectedDeprecated( 'wpmu_new_blog' );
     325                }
     326
     327                $b1 = self::factory()->blog->create();
     328                $b2 = self::factory()->blog->create();
     329                $b3 = self::factory()->blog->create();
     330                $u = self::factory()->user->create();
     331                $u2 = self::factory()->user->create();
     332                $commenter = self::factory()->user->get_object_by_id( $u2 );
     333
     334                $bids = array( $b1, $b2, $b3 );
     335                $pids = array();
     336
     337                foreach ( $bids as $bid ) {
     338                        switch_to_blog( $bid );
     339                       
     340                        // Ensure blog privacy is public so post activities are recorded.
     341                        update_option( 'blog_public', 1 );
     342
     343                        // Create the post.
     344                        $pids[ $bid ] = self::factory()->post->create( array(
     345                                'post_author' => $u,
     346                        ) );
     347
     348                        /*
     349                         * Create the post comment.
     350                         *
     351                         * Both user_id and comment_author_email are required for unit tests.
     352                         */
     353                        $c = self::factory()->comment->create( array(
     354                                'user_id'         => $u2,
     355                                'comment_author_email' => $commenter->user_email,
     356                                'comment_post_ID' => $pids[ $bid ],
     357                        ) );
     358
     359                        // Approve the comment so the activity item is generated.
     360                        self::factory()->comment->update_object( $c, array( 'comment_approved' => 1 ) );
     361
     362                        restore_current_blog();
     363                }
     364
     365                // Now update the post title on one blog only.
     366                switch_to_blog( $b1 );
     367                wp_update_post( array(
     368                        'ID' => $pids[ $b1 ],
     369                        'post_title' => 'Updated'
     370                ) );
     371                restore_current_blog();
     372
     373                // Check our activity meta to see if the post title is different.
     374                $aids = bp_activity_get( array(
     375                        'fields' => 'ids',
     376                        'filter' => array(
     377                                'action' => 'new_blog_comment'
     378                        )
     379                ) );
     380                $aids= $aids['activities'];
     381                foreach ( $aids as $aid ) {
     382                        // Skip the check for the correct blog.
     383                        $a = new BP_Activity_Activity( $aid );
     384                        if ( $a->item_id == $b1 ) {
     385                                continue;
     386                        }
     387
     388                        // Assert that post title is different.
     389                        $post_title = bp_activity_get_meta( $aid, 'post_title' );
     390                        $this->assertFalse( 'Updated' === $post_title, 'Post title should not be the same across all sites with the same post comment ID' );
     391                }
     392        }
     393
    312394        /**
    313395         * @ticket BP6126
    314396         */