You are here

public function CommentTypeTest::testCommentTypeEditing in Drupal 9

Same name and namespace in other branches
  1. 8 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 102

Class

CommentTypeTest
Ensures that comment type functions work correctly.

Namespace

Drupal\Tests\comment\Functional

Code

public function testCommentTypeEditing() {
  $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.');
}