You are here

public function CommentAdminTest::testEditComment 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::testEditComment()

Tests editing a comment as an admin.

File

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

Class

CommentAdminTest
Tests comment approval functionality.

Namespace

Drupal\comment\Tests

Code

public function testEditComment() {

  // Enable anonymous user comments.
  user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array(
    'access comments',
    'post comments',
    'skip comment approval',
  ));

  // Login as a web user.
  $this
    ->drupalLogin($this->webUser);

  // Post a comment.
  $comment = $this
    ->postComment($this->node, $this
    ->randomMachineName());
  $this
    ->drupalLogout();

  // Post anonymous comment.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->setCommentAnonymous('2');

  // Ensure that we need email id before posting comment.
  $this
    ->drupalLogout();

  // Post comment with contact info (required).
  $author_name = $this
    ->randomMachineName();
  $author_mail = $this
    ->randomMachineName() . '@example.com';
  $anonymous_comment = $this
    ->postComment($this->node, $this
    ->randomMachineName(), $this
    ->randomMachineName(), array(
    'name' => $author_name,
    'mail' => $author_mail,
  ));

  // Login as an admin user.
  $this
    ->drupalLogin($this->adminUser);

  // Make sure the comment field is not visible when
  // the comment was posted by an authenticated user.
  $this
    ->drupalGet('comment/' . $comment
    ->id() . '/edit');
  $this
    ->assertNoFieldById('edit-mail', $comment
    ->getAuthorEmail());

  // Make sure the comment field is visible when
  // the comment was posted by an anonymous user.
  $this
    ->drupalGet('comment/' . $anonymous_comment
    ->id() . '/edit');
  $this
    ->assertFieldById('edit-mail', $anonymous_comment
    ->getAuthorEmail());
}