Skip to content

Commit dcb4fa3

Browse files
Test that all descendants including grandchildren are trashed
1 parent fc017d8 commit dcb4fa3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/phpunit/tests/comment.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,5 +1947,49 @@ public function test_wp_delete_comment_deletes_descendants_when_empty_trash_days
19471947
$this->assertNull( get_comment( $child_note_1 ) );
19481948
$this->assertNull( get_comment( $child_note_2 ) );
19491949
$this->assertNull( get_comment( $child_note_3 ) );
1950+
1951+
}
1952+
1953+
/**
1954+
* Test that all descendants including grandchildren are trashed when
1955+
* a parent note is trashed. Note that grandchildren are not currently
1956+
* possible, but the code should support them.
1957+
*/
1958+
public function test_wp_trash_comment_trashes_all_descendants_including_grandchildren() {
1959+
// Create a parent note.
1960+
$parent_note = self::factory()->comment->create(
1961+
array(
1962+
'comment_post_ID' => self::$post_id,
1963+
'comment_type' => 'note',
1964+
'comment_parent' => 0,
1965+
'comment_approved' => '1',
1966+
)
1967+
);
1968+
// Create a child note.
1969+
$child_note = self::factory()->comment->create(
1970+
array(
1971+
'comment_post_ID' => self::$post_id,
1972+
'comment_type' => 'note',
1973+
'comment_parent' => $parent_note,
1974+
'comment_approved' => '1',
1975+
)
1976+
);
1977+
// Create a grandchild note.
1978+
$grandchild_note = self::factory()->comment->create(
1979+
array(
1980+
'comment_post_ID' => self::$post_id,
1981+
'comment_type' => 'note',
1982+
'comment_parent' => $child_note,
1983+
'comment_approved' => '1',
1984+
)
1985+
);
1986+
1987+
// Trash the parent note.
1988+
wp_trash_comment( $parent_note );
1989+
1990+
// Verify that all notes are trashed.
1991+
$this->assertSame( 'trash', get_comment( $parent_note )->comment_approved );
1992+
$this->assertSame( 'trash', get_comment( $child_note )->comment_approved );
1993+
$this->assertSame( 'trash', get_comment( $grandchild_note )->comment_approved );
19501994
}
19511995
}

0 commit comments

Comments
 (0)