Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fillpdf
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
fillpdf
Commits
1c6b172e
Commit
1c6b172e
authored
5 years ago
by
Bernd Oliver Suenderhauf
Browse files
Options
Downloads
Patches
Plain Diff
Issue #3050128 by Pancho: Fix regression in FillPdfRedirectAction
parent
bf96aa2e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/FillPdfActionPlugin/FillPdfRedirectAction.php
+2
-2
2 additions, 2 deletions
src/Plugin/FillPdfActionPlugin/FillPdfRedirectAction.php
tests/src/Functional/HandlePdfControllerTest.php
+91
-0
91 additions, 0 deletions
tests/src/Functional/HandlePdfControllerTest.php
with
93 additions
and
2 deletions
src/Plugin/FillPdfActionPlugin/FillPdfRedirectAction.php
+
2
−
2
View file @
1c6b172e
...
@@ -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
->
to
Url
()
:
Url
::
fromRoute
(
'<front>'
);
$url
=
(
$saved_file
!==
FALSE
)
?
$saved_file
->
createFile
Url
()
:
Url
::
fromRoute
(
'<front>'
)
->
toString
()
;
return
new
RedirectResponse
(
$url
->
toString
()
);
return
new
RedirectResponse
(
$url
);
}
}
}
}
This diff is collapsed.
Click to expand it.
tests/src/Functional/HandlePdfControllerTest.php
+
91
−
0
View file @
1c6b172e
...
@@ -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.
*/
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment