You are here

function CommentFieldsTest::testCommentDefaultFields in Drupal 7

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

File

modules/comment/comment.test, line 2057
Tests for comment.module.

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,
  )));
}