You are here

function CommentAdminTest::testApprovalNodeInterface in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/CommentAdminTest.php \Drupal\comment\Tests\CommentAdminTest::testApprovalNodeInterface()

Tests comment approval functionality through the node interface.

File

core/modules/comment/src/Tests/CommentAdminTest.php, line 110
Contains \Drupal\comment\Tests\CommentAdminTest.

Class

CommentAdminTest
Tests comment approval functionality.

Namespace

Drupal\comment\Tests

Code

function testApprovalNodeInterface() {

  // Set anonymous comments to require approval.
  user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
    'access comments' => TRUE,
    'post comments' => TRUE,
    'skip comment approval' => FALSE,
  ));
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->setCommentAnonymous('0');

  // Ensure that doesn't require contact info.
  $this
    ->drupalLogout();

  // Post anonymous comment without contact info.
  $subject = $this
    ->randomMachineName();
  $body = $this
    ->randomMachineName();
  $this
    ->postComment($this->node, $body, $subject, TRUE);

  // Set $contact to true so that it won't check for id and message.
  $this
    ->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), 'Comment requires approval.');

  // Get unapproved comment id.
  $this
    ->drupalLogin($this->adminUser);
  $anonymous_comment4 = $this
    ->getUnapprovedComment($subject);
  $anonymous_comment4 = entity_create('comment', array(
    '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
    ->drupalGet('comment/1/approve');
  $this
    ->assertResponse(403, 'Forged comment approval was denied.');
  $this
    ->drupalGet('comment/1/approve', array(
    'query' => array(
      'token' => 'forged',
    ),
  ));
  $this
    ->assertResponse(403, 'Forged comment approval was denied.');
  $this
    ->drupalGet('comment/1/edit');
  $this
    ->assertFieldChecked('edit-status-0');
  $this
    ->drupalGet('node/' . $this->node
    ->id());
  $this
    ->clickLink(t('Approve'));
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $this->node
    ->id());
  $this
    ->assertTrue($this
    ->commentExists($anonymous_comment4), 'Anonymous comment visible.');
}