Skip to content
Snippets Groups Projects
Commit 1c6b172e authored by Bernd Oliver Suenderhauf's avatar Bernd Oliver Suenderhauf
Browse files

Issue #3050128 by Pancho: Fix regression in FillPdfRedirectAction

parent bf96aa2e
No related branches found
No related tags found
No related merge requests found
...@@ -28,8 +28,8 @@ class FillPdfRedirectAction extends FillPdfSaveAction { ...@@ -28,8 +28,8 @@ class FillPdfRedirectAction extends FillPdfSaveAction {
*/ */
public function execute() { public function execute() {
$saved_file = $this->savePdf(); $saved_file = $this->savePdf();
$url = ($saved_file !== FALSE) ? $saved_file->toUrl() : Url::fromRoute('<front>'); $url = ($saved_file !== FALSE) ? $saved_file->createFileUrl() : Url::fromRoute('<front>')->toString();
return new RedirectResponse($url->toString()); return new RedirectResponse($url);
} }
} }
...@@ -17,6 +17,97 @@ use Drupal\file\Entity\File; ...@@ -17,6 +17,97 @@ use Drupal\file\Entity\File;
*/ */
class HandlePdfControllerTest extends FillPdfUploadTestBase { class HandlePdfControllerTest extends FillPdfUploadTestBase {
/**
* Tests DownloadAction.
*/
public function testDownloadAction() {
$this->uploadTestPdf('fillpdf_test_v3.pdf');
$form_id = $this->getLatestFillPdfForm();
$fid_before = $this->getLastFileId();
$fillpdf_route = Url::fromRoute('fillpdf.populate_pdf', [], [
'query' => [
'fid' => $form_id,
'sample' => 1,
],
]);
$this->drupalGet($fillpdf_route);
$fid_after = $this->getLastFileId();
// Make sure the PDF file has not been saved.
$this->assertEquals($fid_before, $fid_after);
// Make sure we are seeing the downloaded PDF
$this->assertSession()->statusCodeEquals(200);
$maybe_pdf = $this->getSession()->getPage()->getContent();
$finfo = new \finfo(FILEINFO_MIME_TYPE);
static::assertEquals('application/pdf', $finfo->buffer($maybe_pdf), "The file has the correct MIME type.");
}
/**
* Tests SaveAction.
*/
public function testSaveAction() {
$this->uploadTestPdf('fillpdf_test_v3.pdf');
$form_id = $this->getLatestFillPdfForm();
$edit = [
'scheme' => 'public',
];
$this->drupalPostForm("admin/structure/fillpdf/{$form_id}", $edit, 'Save');
$fid_before = $this->getLastFileId();
$fillpdf_route = Url::fromRoute('fillpdf.populate_pdf', [], [
'query' => [
'fid' => $form_id,
'sample' => 1,
],
]);
$this->drupalGet($fillpdf_route);
$fid_after = $this->getLastFileId();
// Make sure the PDF file has been saved.
$this->assertEquals($fid_before + 1, $fid_after);
// Make sure we are /not/ redirected to the PDF.
$this->assertSession()->statusCodeEquals(200);
$maybe_pdf = $this->getSession()->getPage()->getContent();
$finfo = new \finfo(FILEINFO_MIME_TYPE);
static::assertNotEquals('application/pdf', $finfo->buffer($maybe_pdf), "The file has the correct MIME type.");
}
/**
* Tests RedirectAction.
*/
public function testRedirectAction() {
$this->uploadTestPdf('fillpdf_test_v3.pdf');
$form_id = $this->getLatestFillPdfForm();
$edit = [
'scheme' => 'public',
'destination_redirect[value]' => TRUE,
];
$this->drupalPostForm("admin/structure/fillpdf/{$form_id}", $edit, 'Save');
$fid_before = $this->getLastFileId();
$fillpdf_route = Url::fromRoute('fillpdf.populate_pdf', [], [
'query' => [
'fid' => $form_id,
'sample' => 1,
],
]);
$this->drupalGet($fillpdf_route);
$fid_after = $this->getLastFileId();
// Make sure the PDF file has been saved.
$this->assertEquals($fid_before + 1, $fid_after);
// Make sure we have been redirected to the PDF.
$this->assertSession()->statusCodeEquals(200);
$maybe_pdf = $this->getSession()->getPage()->getContent();
$finfo = new \finfo(FILEINFO_MIME_TYPE);
static::assertEquals('application/pdf', $finfo->buffer($maybe_pdf), "The file has the correct MIME type.");
}
/** /**
* Tests filename and destination of a populated PDF file. * Tests filename and destination of a populated PDF file.
*/ */
......
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