You are here

public function DownloadTest::testMediaDownloadContent 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::testMediaDownloadContent()
  2. 1.0.x tests/src/Functional/DownloadTest.php \Drupal\Tests\media_download\Functional\DownloadTest::testMediaDownloadContent()

Tests that the correct content is returned by Drupal on media download.

@covers \Drupal\media_download\DownloadController::save

File

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

Class

DownloadTest
Tests that the download functionality works as expected.

Namespace

Drupal\Tests\media_download\Functional

Code

public function testMediaDownloadContent() {
  $file = $this->media->field_media_document->entity;
  $this
    ->assertNotNull($file);
  $file_name = $file->filename->value ?? '';
  $this
    ->assertNotNull($file_name);
  $this
    ->assertGreaterThan(0, strlen($file_name));
  $file_name_regex = '/^' . preg_quote($file_name, '/') . '$/';
  $this
    ->drupalLogin($this->owner);

  // Ensure that the correct data is returned for this response.
  $this
    ->drupalGet($this->media
    ->toUrl('canonical')
    ->toString());
  $this
    ->assertSession()
    ->responseMatches($file_name_regex);
}