public function CommentFieldsTest::testCommentFieldDelete in Drupal 9
Same name and namespace in other branches
- 8 core/modules/comment/tests/src/Functional/CommentFieldsTest.php \Drupal\Tests\comment\Functional\CommentFieldsTest::testCommentFieldDelete()
- 10 core/modules/comment/tests/src/Functional/CommentFieldsTest.php \Drupal\Tests\comment\Functional\CommentFieldsTest::testCommentFieldDelete()
Tests that you can remove a comment field.
File
- core/
modules/ comment/ tests/ src/ Functional/ CommentFieldsTest.php, line 71
Class
- CommentFieldsTest
- Tests fields on comments.
Namespace
Drupal\Tests\comment\FunctionalCode
public function testCommentFieldDelete() {
$this
->drupalCreateContentType([
'type' => 'test_node_type',
]);
$this
->addDefaultCommentField('node', 'test_node_type');
// We want to test the handling of removing the primary comment field, so we
// ensure there is at least one other comment field attached to a node type
// so that comment_entity_load() runs for nodes.
$this
->addDefaultCommentField('node', 'test_node_type', 'comment2');
// Create a sample node.
$node = $this
->drupalCreateNode([
'title' => 'Baloney',
'type' => 'test_node_type',
]);
$this
->drupalLogin($this->webUser);
$this
->drupalGet('node/' . $node->nid->value);
$elements = $this
->cssSelect('.field--type-comment');
$this
->assertCount(2, $elements, 'There are two comment fields on the node.');
// Delete the first comment field.
FieldStorageConfig::loadByName('node', 'comment')
->delete();
$this
->drupalGet('node/' . $node->nid->value);
$elements = $this
->cssSelect('.field--type-comment');
$this
->assertCount(1, $elements, 'There is one comment field on the node.');
}