You are here

protected function CommentAlterImageTest::postCommentWithImage in Comment Alter 8

Posts a comment with image using the psuedo browser.

Parameters

string $field_name: Name of the image field. This field comes from the parent entity where it is comment alterable.

array $img_field: The image field value which is to be uploaded.

int $field_number: (optional) The field number for multi-valued image field.

2 calls to CommentAlterImageTest::postCommentWithImage()
CommentAlterImageTest::testImageFieldMultiple in tests/src/Functional/CommentAlterImageTest.php
Tests for multi valued image field comment altering.
CommentAlterImageTest::testImageFieldSingle in tests/src/Functional/CommentAlterImageTest.php
Tests for single valued image field comment altering.

File

tests/src/Functional/CommentAlterImageTest.php, line 61

Class

CommentAlterImageTest
Tests the comment alter module functions for image fields.

Namespace

Drupal\Tests\comment_alter\Functional

Code

protected function postCommentWithImage($field_name, $img_field, $field_number = 0) {

  // Upload the image first.
  $this
    ->drupalGet('comment/reply/' . $this->entityType . '/' . $this->entity
    ->id() . '/comment');
  $this
    ->drupalPostForm(NULL, $img_field, t('Upload'));

  // Now fill other fields including the alt field of the image in the comment
  // form and save it to post a comment.
  $edit['comment_alter_fields[' . $field_name . '][' . $field_number . '][alt]'] = $this
    ->randomString();
  $edit['comment_body[0][value]'] = $this
    ->randomString();
  $edit['subject[0][value]'] = $this
    ->randomString();
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
}