function CommentAdminTest::testApprovalAdminInterface
Same name in this branch
- 10 core/modules/comment/tests/src/Functional/Views/CommentAdminTest.php \Drupal\Tests\comment\Functional\Views\CommentAdminTest::testApprovalAdminInterface()
Same name in other branches
- 9 core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testApprovalAdminInterface()
- 9 core/modules/comment/tests/src/Functional/Views/CommentAdminTest.php \Drupal\Tests\comment\Functional\Views\CommentAdminTest::testApprovalAdminInterface()
- 8.9.x core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testApprovalAdminInterface()
- 8.9.x core/modules/comment/tests/src/Functional/Views/CommentAdminTest.php \Drupal\Tests\comment\Functional\Views\CommentAdminTest::testApprovalAdminInterface()
- 11.x core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testApprovalAdminInterface()
- 11.x core/modules/comment/tests/src/Functional/Views/CommentAdminTest.php \Drupal\Tests\comment\Functional\Views\CommentAdminTest::testApprovalAdminInterface()
Tests comment approval functionality through admin/content/comment.
File
-
core/
modules/ comment/ tests/ src/ Functional/ CommentAdminTest.php, line 38
Class
- CommentAdminTest
- Tests comment approval functionality.
Namespace
Drupal\Tests\comment\FunctionalCode
public function testApprovalAdminInterface() : void {
// Set anonymous comments to require approval.
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
'access comments' => TRUE,
'post comments' => TRUE,
'skip comment approval' => FALSE,
]);
$this->drupalLogin($this->adminUser);
// Ensure that doesn't require contact info.
$this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAYNOT_CONTACT);
// Test that the comments page loads correctly when there are no comments
$this->drupalGet('admin/content/comment');
$this->assertSession()
->pageTextContains('No comments available.');
$this->drupalLogout();
// Post anonymous comment without contact info.
$subject = $this->randomMachineName();
$body = $this->randomMachineName();
// Set $contact to true so that it won't check for id and message.
$this->postComment($this->node, $body, $subject, TRUE);
$this->assertSession()
->pageTextContains('Your comment has been queued for review by site administrators and will be published after approval.');
// Get unapproved comment id.
$this->drupalLogin($this->adminUser);
$anonymous_comment4 = $this->getUnapprovedComment($subject);
$anonymous_comment4 = Comment::create([
'cid' => $anonymous_comment4,
'subject' => $subject,
'comment_body' => $body,
'entity_id' => $this->node
->id(),
'entity_type' => 'node',
'field_name' => 'comment',
]);
$this->drupalLogout();
$this->assertFalse($this->commentExists($anonymous_comment4), 'Anonymous comment was not published.');
// Approve comment.
$this->drupalLogin($this->adminUser);
$this->performCommentOperation($anonymous_comment4, 'publish', TRUE);
$this->drupalLogout();
$this->drupalGet('node/' . $this->node
->id());
$this->assertTrue($this->commentExists($anonymous_comment4), 'Anonymous comment visible.');
// Post 2 anonymous comments without contact info.
$comments[] = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName(), TRUE);
$comments[] = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName(), TRUE);
// Publish multiple comments in one operation.
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/content/comment/approval');
$this->assertSession()
->pageTextContains('Unapproved comments (2)');
$edit = [
"comments[{$comments[0]->id()}]" => 1,
"comments[{$comments[1]->id()}]" => 1,
];
$this->submitForm($edit, 'Update');
$this->assertSession()
->pageTextContains('Unapproved comments (0)');
// Delete multiple comments in one operation.
$edit = [
'operation' => 'delete',
"comments[{$comments[0]->id()}]" => 1,
"comments[{$comments[1]->id()}]" => 1,
"comments[{$anonymous_comment4->id()}]" => 1,
];
$this->submitForm($edit, 'Update');
$this->assertSession()
->pageTextContains('Are you sure you want to delete these comments and all their children?');
$this->submitForm([], 'Delete');
$this->assertSession()
->pageTextContains('No comments available.');
// Test message when no comments selected.
$edit = [
'operation' => 'delete',
];
$this->submitForm($edit, 'Update');
$this->assertSession()
->pageTextContains('Select one or more comments to perform the update on.');
// Make sure the label of unpublished node is not visible on listing page.
$this->drupalGet('admin/content/comment');
$this->postComment($this->node, $this->randomMachineName());
$this->drupalGet('admin/content/comment');
$this->assertSession()
->pageTextContains(Html::escape($this->node
->label()));
$this->node
->setUnpublished()
->save();
$this->drupalGet('admin/content/comment');
$this->assertSession()
->pageTextNotContains(Html::escape($this->node
->label()));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.