You are here

public function CommentFieldsTest::testCommentFieldDelete in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/CommentFieldsTest.php \Drupal\comment\Tests\CommentFieldsTest::testCommentFieldDelete()

Tests that you can remove a comment field.

File

core/modules/comment/src/Tests/CommentFieldsTest.php, line 70
Contains \Drupal\comment\Tests\CommentFieldsTest.

Class

CommentFieldsTest
Tests fields on comments.

Namespace

Drupal\comment\Tests

Code

public function testCommentFieldDelete() {
  $this
    ->drupalCreateContentType(array(
    '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(array(
    'title' => 'Baloney',
    'type' => 'test_node_type',
  ));
  $this
    ->drupalLogin($this->webUser);
  $this
    ->drupalGet('node/' . $node->nid->value);
  $elements = $this
    ->cssSelect('.field--type-comment');
  $this
    ->assertEqual(2, count($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
    ->assertEqual(1, count($elements), 'There is one comment field on the node.');
}