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
1d5501b7
Commit
1d5501b7
authored
5 years ago
by
Bernd Oliver Suenderhauf
Browse files
Options
Downloads
Patches
Plain Diff
Followup to: Issue #3052757 by Pancho: Fix inconsistent parsing of boolean query parameters
parent
0f6cbf48
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/Service/FillPdfLinkManipulator.php
+8
-7
8 additions, 7 deletions
src/Service/FillPdfLinkManipulator.php
tests/src/Unit/LinkManipulator/ParseLinkBooleansTest.php
+10
-22
10 additions, 22 deletions
tests/src/Unit/LinkManipulator/ParseLinkBooleansTest.php
with
18 additions
and
29 deletions
src/Service/FillPdfLinkManipulator.php
+
8
−
7
View file @
1d5501b7
...
...
@@ -72,6 +72,14 @@ class FillPdfLinkManipulator implements FillPdfLinkManipulatorInterface {
throw
new
\InvalidArgumentException
(
'No FillPdfForm was specified in the query string, so failing.'
);
}
if
(
isset
(
$query
[
'download'
])
&&
filter_var
(
$query
[
'download'
],
FILTER_VALIDATE_BOOLEAN
,
FILTER_NULL_ON_FAILURE
)
===
TRUE
)
{
$request_context
[
'force_download'
]
=
TRUE
;
}
if
(
isset
(
$query
[
'flatten'
])
&&
$query
[
'flatten'
]
!==
''
&&
filter_var
(
$query
[
'flatten'
],
FILTER_VALIDATE_BOOLEAN
,
FILTER_NULL_ON_FAILURE
)
===
FALSE
)
{
$request_context
[
'flatten'
]
=
FALSE
;
}
// Is this just the PDF populated with sample data?
if
(
isset
(
$query
[
'sample'
])
&&
filter_var
(
$query
[
'sample'
],
FILTER_VALIDATE_BOOLEAN
,
FILTER_NULL_ON_FAILURE
)
===
TRUE
)
{
$request_context
[
'sample'
]
=
TRUE
;
...
...
@@ -132,13 +140,6 @@ class FillPdfLinkManipulator implements FillPdfLinkManipulatorInterface {
// We've processed the shorthand forms, so unset them.
unset
(
$request_context
[
'entity_id'
],
$request_context
[
'entity_type'
]);
if
(
isset
(
$query
[
'download'
])
&&
filter_var
(
$query
[
'download'
],
FILTER_VALIDATE_BOOLEAN
,
FILTER_NULL_ON_FAILURE
)
===
TRUE
)
{
$request_context
[
'force_download'
]
=
TRUE
;
}
if
(
isset
(
$query
[
'flatten'
])
&&
filter_var
(
$query
[
'flatten'
],
FILTER_VALIDATE_BOOLEAN
,
FILTER_NULL_ON_FAILURE
)
===
FALSE
)
{
$request_context
[
'flatten'
]
=
FALSE
;
}
return
$request_context
;
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Unit/LinkManipulator/ParseLinkTest.php
→
tests/src/Unit/LinkManipulator/ParseLink
Booleans
Test.php
+
10
−
22
View file @
1d5501b7
...
...
@@ -11,40 +11,25 @@ use Drupal\Tests\UnitTestCase;
*
* @group fillpdf
*/
class
ParseLinkTest
extends
UnitTestCase
{
class
ParseLink
Booleans
Test
extends
UnitTestCase
{
/**
* Tests &sample= query parameter.
* Tests &sample=
, &download= and &flatten=
query parameter
s
.
*
* @dataProvider dataProvider
*/
public
function
test
Sample
(
$input
,
$expected
)
{
public
function
test
Booleans
(
$input
,
$expected
)
{
$request_context
=
FillPdfLinkManipulator
::
parseLink
(
$this
->
link
(
$input
));
$this
->
assertEquals
(
is_null
(
$expected
)
?
FALSE
:
$expected
,
$request_context
[
'sample'
]);
}
/**
* Tests &download= query parameter.
*
* @dataProvider dataProvider
*/
public
function
testDownload
(
$input
,
$expected
)
{
$request_context
=
FillPdfLinkManipulator
::
parseLink
(
$this
->
link
(
$input
));
$this
->
assertEquals
(
is_null
(
$expected
)
?
FALSE
:
$expected
,
$request_context
[
'force_download'
]);
}
/**
* Tests &flatten= query parameter.
*
* @dataProvider dataProvider
*/
public
function
testFlatten
(
$input
,
$expected
)
{
$request_context
=
FillPdfLinkManipulator
::
parseLink
(
$this
->
link
(
$input
));
$this
->
assertEquals
(
is_null
(
$expected
)
?
TRUE
:
$expected
,
$request_context
[
'flatten'
]);
}
/**
*
Data provider for testValueCallback
().
*
Input helper for testBooleans
().
*/
public
function
link
(
$input
)
{
return
Url
::
fromRoute
(
'fillpdf.populate_pdf'
,
[],
[
...
...
@@ -60,7 +45,7 @@ class ParseLinkTest extends UnitTestCase {
}
/**
* Data provider for test
ValueCallback
().
* Data provider for test
Booleans
().
*/
public
function
dataProvider
()
{
return
[
...
...
@@ -86,9 +71,12 @@ class ParseLinkTest extends UnitTestCase {
[
'No'
,
FALSE
],
[
'NO'
,
FALSE
],
// These three are important, so should always be obeyed:
[
''
,
NULL
],
[
'foo'
,
NULL
],
[
'bar'
,
NULL
],
// The following mappings are a bit unfortunate, so are no requirements:
// The following ones are less fortunate, so may be refactored:
[
'-1'
,
NULL
],
[
'2'
,
NULL
],
[
'y'
,
NULL
],
...
...
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