3 namespace Drupal\Tests\comment\Functional;
5 use Drupal\comment\Entity\Comment;
6 use Drupal\field\Entity\FieldConfig;
7 use Drupal\field\Entity\FieldStorageConfig;
10 * Tests that comments behave correctly when the node is changed.
14 class CommentNodeChangesTest extends CommentTestBase {
17 * Tests that comments are deleted with the node.
19 public function testNodeDeletion() {
20 $this->drupalLogin($this->webUser);
21 $comment = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
22 $this->assertTrue($comment->id(), 'The comment could be loaded.');
23 $this->node->delete();
24 $this->assertFalse(Comment::load($comment->id()), 'The comment could not be loaded after the node was deleted.');
25 // Make sure the comment field storage and all its fields are deleted when
26 // the node type is deleted.
27 $this->assertNotNull(FieldStorageConfig::load('node.comment'), 'Comment field storage exists');
28 $this->assertNotNull(FieldConfig::load('node.article.comment'), 'Comment field exists');
29 // Delete the node type.
30 entity_delete_multiple('node_type', [$this->node->bundle()]);
31 $this->assertNull(FieldStorageConfig::load('node.comment'), 'Comment field storage deleted');
32 $this->assertNull(FieldConfig::load('node.article.comment'), 'Comment field deleted');