public function CommentNotifyConfigPageTest::testsAnonymousProblemsAreReported in Comment Notify 8
Tests the warning message when anonymous users have configuration problems.
File
- tests/
src/ Functional/ CommentNotifyConfigPageTest.php, line 137
Class
- CommentNotifyConfigPageTest
- Tests for the comment_notify module.
Namespace
Drupal\Tests\comment_notify\FunctionalCode
public function testsAnonymousProblemsAreReported() {
// Tests that the anonymous users have the permission to use comment notify
// but aren't allowed to leave posts.
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, [
'access comments',
'access content',
'subscribe to comments',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("admin/config/people/comment_notify");
// Test that a warning error is displayed when anonymous users have the
// permission to use comment notify but cannot post posts.
$this
->assertSession()
->responseContains('Anonymous commenters have the permission to subscribe to comments but they need to be allowed to:');
$this
->assertSession()
->responseContains('Post comments');
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, [
'post comments',
]);
$this
->drupalGet("admin/config/people/comment_notify");
$this
->assertSession()
->responseNotContains('Anonymous commenters have the permission to subscribe to comments but they need to be allowed to:');
$this
->assertSession()
->responseNotContains('Post comments');
// Tests that a warning error is displayed when anonymous users haven't
// permission to leave their contact information.
$comment_field = FieldConfig::loadByName('node', 'article', 'comment');
$comment_field
->setSetting('anonymous', CommentInterface::ANONYMOUS_MAYNOT_CONTACT);
$comment_field
->save();
$this
->drupalGet("admin/config/people/comment_notify");
$this
->assertSession()
->responseContains('Anonymous commenters have the permission to subscribe to comments but they need to be allowed to:');
$this
->assertSession()
->responseContains('Leave their contact information on the following fields:');
$this
->assertSession()
->responseContains('node--article--comment');
// If the field_ui module is installed then the field with the problem must
// be a link.
$this->container
->get('module_installer')
->install([
'field_ui',
], TRUE);
$this
->rebuildContainer();
$this
->drupalGet("admin/config/people/comment_notify");
$this
->assertSession()
->responseContains('Anonymous commenters have the permission to subscribe to comments but they need to be allowed to:');
$this
->assertSession()
->responseContains('Leave their contact information on the following fields:');
$this
->assertSession()
->responseContains('node--article--comment');
$this
->assertSession()
->linkByHrefExists('/admin/structure/types/manage/article/fields/node.article.comment');
}