You are here

public function CommentTestBase::performCommentOperation in Drupal 8

Same name in this branch
  1. 8 core/modules/comment/src/Tests/CommentTestBase.php \Drupal\comment\Tests\CommentTestBase::performCommentOperation()
  2. 8 core/modules/comment/tests/src/Functional/CommentTestBase.php \Drupal\Tests\comment\Functional\CommentTestBase::performCommentOperation()

Performs the specified operation on the specified comment.

Parameters

\Drupal\comment\CommentInterface $comment: Comment to perform operation on.

string $operation: Operation to perform.

bool $approval: Operation is found on approval page.

File

core/modules/comment/src/Tests/CommentTestBase.php, line 367

Class

CommentTestBase
Provides setup and helper methods for comment tests.

Namespace

Drupal\comment\Tests

Code

public function performCommentOperation(CommentInterface $comment, $operation, $approval = FALSE) {
  $edit = [];
  $edit['operation'] = $operation;
  $edit['comments[' . $comment
    ->id() . ']'] = TRUE;
  $this
    ->drupalPostForm('admin/content/comment' . ($approval ? '/approval' : ''), $edit, t('Update'));
  if ($operation == 'delete') {
    $this
      ->drupalPostForm(NULL, [], t('Delete'));
    $this
      ->assertRaw(\Drupal::translation()
      ->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), new FormattableMarkup('Operation "@operation" was performed on comment.', [
      '@operation' => $operation,
    ]));
  }
  else {
    $this
      ->assertText(t('The update has been performed.'), new FormattableMarkup('Operation "@operation" was performed on comment.', [
      '@operation' => $operation,
    ]));
  }
}