You are here

public function CommentTypeTest::testCommentTypeCreation in Zircon Profile 8

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

Tests creating a comment type programmatically and via a form.

File

core/modules/comment/src/Tests/CommentTypeTest.php, line 55
Contains \Drupal\comment\Tests\CommentTypeTest.

Class

CommentTypeTest
Ensures that comment type functions work correctly.

Namespace

Drupal\comment\Tests

Code

public function testCommentTypeCreation() {

  // Create a comment type programmatically.
  $type = $this
    ->createCommentType('other');
  $comment_type = CommentType::load('other');
  $this
    ->assertTrue($comment_type, 'The new comment type has been created.');

  // Login a test user.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/structure/comment/manage/' . $type
    ->id());
  $this
    ->assertResponse(200, 'The new comment type can be accessed at the edit form.');

  // Create a comment type via the user interface.
  $edit = array(
    'id' => 'foo',
    'label' => 'title for foo',
    'description' => '',
    'target_entity_type_id' => 'node',
  );
  $this
    ->drupalPostForm('admin/structure/comment/types/add', $edit, t('Save'));
  $comment_type = CommentType::load('foo');
  $this
    ->assertTrue($comment_type, 'The new comment type has been created.');

  // Check that the comment type was created in site default language.
  $default_langcode = \Drupal::languageManager()
    ->getDefaultLanguage()
    ->getId();
  $this
    ->assertEqual($comment_type
    ->language()
    ->getId(), $default_langcode);

  // Edit the comment-type and ensure that we cannot change the entity-type.
  $this
    ->drupalGet('admin/structure/comment/manage/foo');
  $this
    ->assertNoField('target_entity_type_id', 'Entity type file not present');
  $this
    ->assertText(t('Target entity type'));

  // Save the form and ensure the entity-type value is preserved even though
  // the field isn't present.
  $this
    ->drupalPostForm(NULL, array(), t('Save'));
  \Drupal::entityManager()
    ->getStorage('comment_type')
    ->resetCache(array(
    'foo',
  ));
  $comment_type = CommentType::load('foo');
  $this
    ->assertEqual($comment_type
    ->getTargetEntityTypeId(), 'node');
}