You are here

public function DownloadTest::testMediaDownloadAsAttachment in Media Download 1.1.x

Same name and namespace in other branches
  1. 1.2.x tests/src/Functional/DownloadTest.php \Drupal\Tests\media_download\Functional\DownloadTest::testMediaDownloadAsAttachment()

Tests that media can be downloaded as an attachment.

@covers \Drupal\media_download\DownloadController::save

File

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

Class

DownloadTest
Tests that the download functionality works as expected.

Namespace

Drupal\Tests\media_download\Functional

Code

public function testMediaDownloadAsAttachment() {
  $this
    ->drupalLogin($this->owner);
  $url = $this->media
    ->toUrl('canonical', [
    'query' => [
      'dl' => 1,
    ],
  ]);
  $this
    ->drupalGet($url);
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->responseHeaderContains('Content-Disposition', 'attachment');
  $assert_session
    ->responseHeaderContains('Content-Disposition', 'filename=');
  $this
    ->assertCacheContext('url.query_args:dl');

  // Ensure that the download is inline if the 'dl' query string parameter is
  // anything other than 1.
  $url = $this->media
    ->toUrl('canonical', [
    'query' => [
      'dl' => 'yes',
    ],
  ]);
  $this
    ->drupalGet($url);
  $assert_session
    ->responseHeaderContains('Content-Disposition', 'inline');
}