function CommentFieldsTest::testCommentDefaultFields

Same name and namespace in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentFieldsTest.php \Drupal\Tests\comment\Functional\CommentFieldsTest::testCommentDefaultFields()
  2. 8.9.x core/modules/comment/tests/src/Functional/CommentFieldsTest.php \Drupal\Tests\comment\Functional\CommentFieldsTest::testCommentDefaultFields()
  3. 10 core/modules/comment/tests/src/Functional/CommentFieldsTest.php \Drupal\Tests\comment\Functional\CommentFieldsTest::testCommentDefaultFields()
  4. 11.x core/modules/comment/tests/src/Functional/CommentFieldsTest.php \Drupal\Tests\comment\Functional\CommentFieldsTest::testCommentDefaultFields()

Tests that the default 'comment_body' field is correctly added.

File

modules/comment/comment.test, line 2121

Class

CommentFieldsTest
Test fields on comments.

Code

function testCommentDefaultFields() {
  // Do not make assumptions on default node types created by the test
  // installation profile, and create our own.
  $this->drupalCreateContentType(array(
    'type' => 'test_node_type',
  ));
  // Check that the 'comment_body' field is present on all comment bundles.
  $instances = field_info_instances('comment');
  foreach (node_type_get_types() as $type_name => $info) {
    $this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), format_string('The comment_body field is present for comments on type @type', array(
      '@type' => $type_name,
    )));
    // Delete the instance along the way.
    field_delete_instance($instances['comment_node_' . $type_name]['comment_body']);
  }
  // Check that the 'comment_body' field is deleted.
  $field = field_info_field('comment_body');
  $this->assertTrue(empty($field), 'The comment_body field was deleted');
  // Create a new content type.
  $type_name = 'test_node_type_2';
  $this->drupalCreateContentType(array(
    'type' => $type_name,
  ));
  // Check that the 'comment_body' field exists and has an instance on the
  // new comment bundle.
  $field = field_info_field('comment_body');
  $this->assertTrue($field, 'The comment_body field exists');
  $instances = field_info_instances('comment');
  $this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), format_string('The comment_body field is present for comments on type @type', array(
    '@type' => $type_name,
  )));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.