function CommentAdminTest::testEditComment

Same name in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testEditComment()
  2. 8.9.x core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testEditComment()
  3. 10 core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testEditComment()

Tests editing a comment as an admin.

File

core/modules/comment/tests/src/Functional/CommentAdminTest.php, line 206

Class

CommentAdminTest
Tests comment approval functionality.

Namespace

Drupal\Tests\comment\Functional

Code

public function testEditComment() : void {
    // Enable anonymous user comments.
    user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
        'access comments',
        'post comments',
        'skip comment approval',
    ]);
    // Log in as a web user.
    $this->drupalLogin($this->webUser);
    // Post a comment.
    $comment = $this->postComment($this->node, $this->randomMachineName());
    $this->drupalLogout();
    // Post anonymous comment.
    // Ensure that we need email id before posting comment.
    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MUST_CONTACT);
    // 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(), [
        'name' => $author_name,
        'mail' => $author_mail,
    ]);
    // Log in 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->assertSession()
        ->fieldNotExists('edit-mail');
    // Make sure the comment field is visible when
    // the comment was posted by an anonymous user.
    $this->drupalGet('comment/' . $anonymous_comment->id() . '/edit');
    $this->assertSession()
        ->fieldValueEquals('edit-mail', $anonymous_comment->getAuthorEmail());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.