function CommentNonNodeTest::testCommentSettingsNotRequired

Same name and namespace in other branches
  1. 10 core/modules/comment/tests/src/Functional/CommentNonNodeTest.php \Drupal\Tests\comment\Functional\CommentNonNodeTest::testCommentSettingsNotRequired()

Ensures that comment settings are not required.

File

core/modules/comment/tests/src/Functional/CommentNonNodeTest.php, line 529

Class

CommentNonNodeTest
Tests commenting on a test entity.

Namespace

Drupal\Tests\comment\Functional

Code

public function testCommentSettingsNotRequired() : void {
    $limited_user = $this->drupalCreateUser([
        'administer entity_test fields',
    ]);
    $this->drupalLogin($limited_user);
    $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
    // Change the comments to be displayed as hidden by default.
    $edit = [
        'default_value_input[comment][0][status]' => CommentItemInterface::HIDDEN,
        'settings[anonymous]' => CommentInterface::ANONYMOUS_MAY_CONTACT,
    ];
    $this->submitForm($edit, 'Save settings');
    // Ensure that the comment settings field is not required and can be saved
    // with the default value.
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('/entity_test/add');
    $this->assertSession()
        ->checkboxChecked('edit-comment-0-status-0');
    $edit = [
        "name[0][value]" => 'Comment test',
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->pageTextContains('entity_test 2 has been created.');
}

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