ProtectedSubmissionsTest.php in Protected Submissions 8
File
tests/src/Functional/ProtectedSubmissionsTest.php
View source
<?php
namespace Drupal\Tests\protected_submissions\Functional;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\user\RoleInterface;
use Symfony\Component\HttpFoundation\Response;
class ProtectedSubmissionsTest extends BrowserTestBase {
use NodeCreationTrait, CommentTestTrait;
protected $defaultTheme = 'stark';
protected static $modules = [
'node',
'comment',
'protected_submissions',
];
public function testNodeCommentRejectedSubmissionPrintsCorrectMessage() {
$types = NodeType::loadMultiple();
if (empty($types['article'])) {
$this
->drupalCreateContentType([
'type' => 'article',
'name' => $this
->t('Article'),
]);
}
$this
->addDefaultCommentField('node', 'article');
$this
->drupalCreateNode([
'title' => $this
->t('An Article'),
'type' => 'article',
])
->save();
$permissions = [
'access content',
'access comments',
'post comments',
'skip comment approval',
];
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, $permissions);
$rejectPatterns = $this
->config('protected_submissions.settings')
->get('protected_submissions.reject_patterns');
$inputString = ' monkey';
$rejectPatterns .= ',' . $inputString;
$this
->config('protected_submissions.settings')
->set('protected_submissions.reject_patterns', $rejectPatterns)
->save();
$input = [
'edit-comment-body-0-value' => $inputString,
];
$this
->drupalPostForm('node/1', $input, $this
->t('Save'));
$this
->assertResponse(Response::HTTP_OK);
$message = $this
->config('protected_submissions.settings')
->get('protected_submissions.reject_message');
$this
->assertSession()
->responseContains($message);
$this
->assertSession()
->responseNotContains('Your comment has been posted.');
$input = [
'edit-comment-body-0-value' => 'a normal comment',
];
$this
->drupalPostForm('node/1', $input, $this
->t('Save'));
$this
->assertResponse(Response::HTTP_OK);
$this
->assertSession()
->responseContains('Your comment has been posted.');
$this
->assertSession()
->responseContains('a normal comment');
}
}