You are here

public function DownloadTest::testAttachmentDownload in Media Entity Download 8.2

Tests if attachment download option created correct HTTP response headers.

File

tests/src/Functional/DownloadTest.php, line 184

Class

DownloadTest
Simple test to ensure that main page loads with module enabled.

Namespace

Drupal\Tests\media_entity_download\Functional

Code

public function testAttachmentDownload() {
  $media_owner = $this
    ->createUser([
    'download media',
  ]);
  $media = $this
    ->createMediaEntity(TRUE, $media_owner);
  $this
    ->drupalLogin($media_owner);
  $this
    ->drupalGet(Url::fromRoute('media_entity_download.download', [
    'media' => $media
      ->id(),
  ], [
    'query' => [
      ResponseHeaderBag::DISPOSITION_ATTACHMENT => '',
    ],
  ]));
  $this
    ->assertSession()
    ->statusCodeEquals(Response::HTTP_OK);
  $this
    ->assertSession()
    ->responseHeaderContains('Content-Disposition', ResponseHeaderBag::DISPOSITION_ATTACHMENT);
  $this
    ->drupalGet(Url::fromRoute('media_entity_download.download', [
    'media' => $media
      ->id(),
  ], [
    'query' => [
      ResponseHeaderBag::DISPOSITION_INLINE => '',
    ],
  ]));
  $this
    ->assertSession()
    ->statusCodeEquals(Response::HTTP_OK);
  $this
    ->assertSession()
    ->responseHeaderContains('Content-Disposition', ResponseHeaderBag::DISPOSITION_INLINE);
  $this
    ->drupalGet(Url::fromRoute('media_entity_download.download', [
    'media' => $media
      ->id(),
  ]));
  $this
    ->assertSession()
    ->statusCodeEquals(Response::HTTP_OK);
  $this
    ->assertSession()
    ->responseHeaderContains('Content-Disposition', ResponseHeaderBag::DISPOSITION_ATTACHMENT);
}