You are here

public function CommentAlterImageTest::testImageFieldMultiple in Comment Alter 8

Tests for multi valued image field comment altering.

File

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

Class

CommentAlterImageTest
Tests the comment alter module functions for image fields.

Namespace

Drupal\Tests\comment_alter\Functional

Code

public function testImageFieldMultiple() {
  $field_name = $this
    ->addImageField(-1);
  $images = $this
    ->getImageFiles();
  $image1 = current($this
    ->getImageFiles());
  $image2 = end($images);

  // Create an entity object without the image.
  $this
    ->createEntityObject();

  // Now edit the entity to add an image to the image field.
  $this
    ->drupalGet('entity_test_rev/manage/' . $this->entity
    ->id() . '/edit');
  $img['files[' . $field_name . '_0][]'] = drupal_realpath($image1->uri);
  $this
    ->drupalPostForm(NULL, $img, t('Upload'));
  $edit[$field_name . '[0][alt]'] = $this
    ->randomString();
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->postCommentWithImage($field_name, [
    'files[comment_alter_fields_' . $field_name . '_1][]' => drupal_realpath($image2->uri),
  ], 1);
  $this
    ->assertCommentDiff([
    $field_name => [
      [
        'File ID: 1',
        'File ID: 1',
      ],
      [
        NULL,
        'Image: ' . $image2->filename,
      ],
      [
        NULL,
        'File ID: 2',
      ],
    ],
  ]);
  $this
    ->assertRevisionDelete();
}