function CommentTypeTest::testCommentTypeEditing

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

Tests editing a comment type using the UI.

File

core/modules/comment/tests/src/Functional/CommentTypeTest.php, line 124

Class

CommentTypeTest
Ensures that comment type functions work correctly.

Namespace

Drupal\Tests\comment\Functional

Code

public function testCommentTypeEditing() : void {
  $this->drupalLogin($this->adminUser);
  $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
  $this->assertEquals('Comment', $field->getLabel(), 'Comment body field was found.');
  // Change the comment type name.
  $this->drupalGet('admin/structure/comment');
  $edit = [
    'label' => 'Bar',
  ];
  $this->drupalGet('admin/structure/comment/manage/comment');
  $this->submitForm($edit, 'Save');
  $this->drupalGet('admin/structure/comment');
  $this->assertSession()
    ->pageTextContains('Bar');
  $this->clickLink('Manage fields');
  // Verify that the original machine name was used in the URL.
  $this->assertSession()
    ->addressEquals(Url::fromRoute('entity.comment.field_ui_fields', [
    'comment_type' => 'comment',
  ]));
  $this->assertCount(1, $this->cssSelect('tr#comment-body'), 'Body field exists.');
  // Remove the body field.
  $this->drupalGet('admin/structure/comment/manage/comment/fields/comment.comment.comment_body/delete');
  $this->submitForm([], 'Delete');
  // Resave the settings for this type.
  $this->drupalGet('admin/structure/comment/manage/comment');
  $this->submitForm([], 'Save');
  // Check that the body field doesn't exist.
  $this->drupalGet('admin/structure/comment/manage/comment/fields');
  $this->assertCount(0, $this->cssSelect('tr#comment-body'), 'Body field does not exist.');
}

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