Skip to:
Content

BuddyPress.org

Ticket #7450: 7450.02.patch

File 7450.02.patch, 2.7 KB (added by r-a-y, 6 years ago)
  • src/bp-activity/bp-activity-functions.php

     
    29632963                return $deleted;
    29642964        }
    29652965
     2966        // Check if comment still exists.
     2967        $comment = new BP_Activity_Activity( $comment_id );
     2968        if ( empty( $comment->id ) ) {
     2969                return false;
     2970        }
     2971
    29662972        // Delete any children of this comment.
    29672973        bp_activity_delete_children( $activity_id, $comment_id );
    29682974
     
    30013007         * @param int $activity_id The ID of the "root" activity, ie the
    30023008         *                         comment's oldest ancestor.
    30033009         * @param int $comment_id  The ID of the comment to be deleted.
     3010         * @return void|bool
    30043011         */
    30053012        function bp_activity_delete_children( $activity_id, $comment_id ) {
     3013                // Check if comment still exists.
     3014                $comment = new BP_Activity_Activity( $comment_id );
     3015                if ( empty( $comment->id ) ) {
     3016                        return false;
     3017                }
    30063018
    30073019                // Get activity children to delete.
    30083020                $children = BP_Activity_Activity::get_child_comments( $comment_id );
  • tests/phpunit/testcases/activity/functions.php

     
    12781278        }
    12791279
    12801280        /**
     1281         * @group  bp_activity_delete_comment
     1282         * @ticket BP7450
     1283         */
     1284        public function test_bp_activity_delete_comment_shouldnt_delete_all_comments_when_parameters_are_empty() {
     1285                $u = $this->factory->user->create();
     1286
     1287                // create an activity update
     1288                $parent_activity = $this->factory->activity->create( array(
     1289                        'type'    => 'activity_update',
     1290                        'user_id' => $u
     1291                ) );
     1292
     1293                // create some activity comments
     1294                $comment_one = bp_activity_new_comment( array(
     1295                        'user_id'     => $u,
     1296                        'activity_id' => $parent_activity,
     1297                        'content'     => 'depth 1'
     1298                ) );
     1299
     1300                $comment_one_one = bp_activity_new_comment( array(
     1301                        'user_id'     => $u,
     1302                        'activity_id' => $parent_activity,
     1303                        'parent_id'   => $comment_one,
     1304                        'content'     => 'depth 2'
     1305                ) );
     1306
     1307                $comment_two = bp_activity_new_comment( array(
     1308                        'user_id'     => $u,
     1309                        'activity_id' => $parent_activity,
     1310                        'content'     => 'depth 1'
     1311                ) );
     1312
     1313                // Pass empty values to bp_activity_delete_comment()
     1314                $retval = bp_activity_delete_comment( 0, 0 );
     1315                $this->assertFalse( $retval );
     1316
     1317                // Instantiate activity loop, which also includes activity comments.
     1318                bp_has_activities( 'display_comments=stream' );
     1319
     1320                // Activity comments should not be deleted.
     1321                $this->assertSame( 4, $GLOBALS['activities_template']->activity_count );
     1322
     1323                // Clean up after ourselves!
     1324                $GLOBALS['activities_template'] = null;
     1325        }
     1326
     1327        /**
    12811328         * @group bp_activity_new_comment
    12821329         * @group BP5907
    12831330         */