Skip to content
Snippets Groups Projects
Commit d3f7b6cc authored by wizonesolutions's avatar wizonesolutions Committed by Kevin Kaland
Browse files

Issue #2883481 by wizonesolutions, ovi.indrei, carstenG: PDF file gets downloaded as HTML file

parent b5a016b6
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,8 @@ class FillPdfDownloadAction extends FillPdfActionPluginBase {
$this->configuration['filename']
);
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Length', strlen($this->configuration['data']));
return $response;
}
......
......@@ -4,6 +4,7 @@ namespace Drupal\Tests\fillpdf\Functional;
use Drupal\Core\Url;
use Drupal\file\Entity\File;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
/**
* @coversDefaultClass \Drupal\fillpdf\Controller\HandlePdfController
......@@ -35,6 +36,8 @@ class HandlePdfControllerTest extends FillPdfUploadTestBase {
/**
* Tests DownloadAction.
*
* @throws \Behat\Mink\Exception\ExpectationException
*/
public function testDownloadAction() {
$this->uploadTestPdf('fillpdf_test_v3.pdf');
......@@ -58,6 +61,10 @@ class HandlePdfControllerTest extends FillPdfUploadTestBase {
$maybe_pdf = $this->getSession()->getPage()->getContent();
static::assertEquals('application/pdf', $this->getMimeType($maybe_pdf), 'The file has the correct MIME type.');
// Ensure the headers are set to make the PDF download.
$this->assertSession()->responseHeaderContains('Content-Disposition', ResponseHeaderBag::DISPOSITION_ATTACHMENT);
$this->assertSession()->responseHeaderContains('Content-Type', 'application/pdf');
$this->assertSession()->responseHeaderContains('Content-Length', (string) strlen(file_get_contents($this->getTestPdfPath('fillpdf_test_v3.pdf'))));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment