You are here

public function DocumentBundleTest::testDocumentItemThumbnail in D7 Media 8

Tests thumbnails of the document items.

File

src/Tests/DocumentBundleTest.php, line 84

Class

DocumentBundleTest
Ensures that media bundle for document can be created.

Namespace

Drupal\media\Tests

Code

public function testDocumentItemThumbnail() {

  // Array of test files and corresponding file icons.
  $files = [
    'Test.pdf' => 'public://media-icons/generic/application-pdf.png',
    'Test.doc' => 'public://media-icons/generic/application-msword.png',
    'Test.docx' => 'public://media-icons/generic/application-vnd.openxmlformats-officedocument.wordprocessingml.document.png',
    'Test.ods' => 'public://media-icons/generic/application-vnd.oasis.opendocument.spreadsheet.png',
    'Test.odt' => 'public://media-icons/generic/application-vnd.oasis.opendocument.text.png',
    'Test.ott' => 'public://media-icons/generic/application-vnd.oasis.opendocument.text-template.png',
    'Test.ppt' => 'public://media-icons/generic/application-vnd.ms-powerpoint.png',
    'Test.pptx' => 'public://media-icons/generic/application-vnd.openxmlformats-officedocument.presentationml.presentation.png',
    'Test.rtf' => 'public://media-icons/generic/application-rtf.png',
    'Test.txt' => 'public://media-icons/generic/text-plain.png',
    'Test.xls' => 'public://media-icons/generic/application-vnd.ms-excel.png',
    'Test.xlsx' => 'public://media-icons/generic/application-vnd.openxmlformats-officedocument.spreadsheetml.sheet.png',
  ];
  foreach ($files as $fileName => $thumbnail) {
    $file = drupal_get_path('module', 'media') . '/files/' . $fileName;
    $name = $this
      ->randomMachineName();
    $this
      ->drupalGet('media/add/document');
    $edit = [
      'files[field_document_0]' => $file,
    ];
    $this
      ->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
    $fid = (string) current($this
      ->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
    $edit = [
      'name[0][value]' => $name,
      'form_id' => 'media_document_form',
      'field_document[0][fids]' => $fid,
      'field_document[0][display]' => 1,
    ];
    $this
      ->drupalPostForm(NULL, $edit, t('Save and publish'));
    $recentThumbnail = $this
      ->getMostRecentThumbnail();
    $this
      ->assertEqual($thumbnail, $recentThumbnail, "Correct thumbnail detected for " . $fileName);
  }
}