You are here

public function WebformElementMediaFileTest::testMediaFileUpload in Webform 6.x

Same name and namespace in other branches
  1. 8.5 tests/src/Functional/Element/WebformElementMediaFileTest.php \Drupal\Tests\webform\Functional\Element\WebformElementMediaFileTest::testMediaFileUpload()

Test media file upload elements.

File

tests/src/Functional/Element/WebformElementMediaFileTest.php, line 32

Class

WebformElementMediaFileTest
Test for webform element managed file handling.

Namespace

Drupal\Tests\webform\Functional\Element

Code

public function testMediaFileUpload() {

  /* Element render */

  // Get test webform.
  $this
    ->drupalGet('/webform/test_element_media_file');

  // Check document file.
  $this
    ->assertRaw('<input data-drupal-selector="edit-document-file-upload" type="file" id="edit-document-file-upload" name="files[document_file]" size="22" class="js-form-file form-file" />');

  // Check audio file.
  $this
    ->assertRaw('<input data-drupal-selector="edit-audio-file-upload" accept="audio/*" type="file" id="edit-audio-file-upload" name="files[audio_file]" size="22" class="js-form-file form-file" />');

  // Check image file.
  $this
    ->assertRaw('<input data-drupal-selector="edit-image-file-upload" accept="image/*" type="file" id="edit-image-file-upload" name="files[image_file]" size="22" class="js-form-file form-file" />');

  // Check video file.
  $this
    ->assertRaw('<input data-drupal-selector="edit-video-file-upload" accept="video/mp4,video/x-m4v,video/*" type="file" id="edit-video-file-upload" name="files[video_file]" size="22" class="js-form-file form-file" />');

  /* Element processing */

  // Get test webform preview with test values.
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalPostForm('/webform/test_element_media_file/test', [], 'Preview');

  // Check audio file preview.
  $this
    ->assertRaw('<source src="' . $this
    ->getAbsoluteUrl('/system/files/webform/test_element_media_file/_sid_/audio_file_mp3.mp3') . '" type="audio/mpeg">');

  // Check image file preview.
  $this
    ->assertRaw('<img class="webform-image-file" alt="image_file_jpg.jpg" title="image_file_jpg.jpg" src="' . $this
    ->getAbsoluteUrl('/system/files/webform/test_element_media_file/_sid_/image_file_jpg.jpg') . '" />');

  // Check image file link to modal.
  $this
    ->assertRaw('/system/files/webform/test_element_media_file/_sid_/image_file_jpg_modal.jpg" class="js-webform-image-file-modal webform-image-file-modal">');
  $this
    ->assertRaw('/system/files/styles/thumbnail/private/webform/test_element_media_file/_sid_/image_file_jpg_modal.jpg?itok=');

  // Check video file preview.
  $this
    ->assertRaw('<source src="' . $this
    ->getAbsoluteUrl('/system/files/webform/test_element_media_file/_sid_/video_file_mp4.mp4') . '" type="video/mp4">');
}