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
e277f83f
Commit
e277f83f
authored
5 years ago
by
pancho
Committed by
Liam Morland
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue #3052757 by Pancho, Liam Morland: Make parsing of Boolean query parameters consistent
parent
096ea16a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fillpdf.info
+1
-0
1 addition, 0 deletions
fillpdf.info
fillpdf.module
+13
-10
13 additions, 10 deletions
fillpdf.module
tests/FillPdfLinkContextTestCase.test
+100
-0
100 additions, 0 deletions
tests/FillPdfLinkContextTestCase.test
with
114 additions
and
10 deletions
fillpdf.info
+
1
−
0
View file @
e277f83f
...
...
@@ -8,6 +8,7 @@ test_dependencies[] = webform
test_dependencies[] = features
test_dependencies[] = webform_features
; Note: Tests require PHP 5.4.
files[] = tests/FillPdfLinkContextTestCase.test
files[] = tests/FillPdfMergeTestCase.test
files[] = tests/FillPdfTestCase.test
files[] = tests/FillPdfTestHelper.test
...
...
This diff is collapsed.
Click to expand it.
fillpdf.module
+
13
−
10
View file @
e277f83f
...
...
@@ -365,9 +365,20 @@ function fillpdf_link_to_stub_context($uri) {
'flatten'
=>
NULL
,
);
$context
[
'sample'
]
=
$query_string
[
'sample'
];
$context
[
'fid'
]
=
$query_string
[
'fid'
];
if
(
isset
(
$query_string
[
'download'
])
&&
filter_var
(
$query_string
[
'download'
],
FILTER_VALIDATE_BOOLEAN
,
FILTER_NULL_ON_FAILURE
)
===
TRUE
)
{
$context
[
'force_download'
]
=
TRUE
;
}
if
(
isset
(
$query_string
[
'flatten'
])
&&
$query_string
[
'flatten'
]
!==
''
&&
filter_var
(
$query_string
[
'flatten'
],
FILTER_VALIDATE_BOOLEAN
,
FILTER_NULL_ON_FAILURE
)
===
FALSE
)
{
$context
[
'flatten'
]
=
FALSE
;
}
if
(
isset
(
$query_string
[
'sample'
])
&&
filter_var
(
$query_string
[
'sample'
],
FILTER_VALIDATE_BOOLEAN
,
FILTER_NULL_ON_FAILURE
)
===
TRUE
)
{
$context
[
'sample'
]
=
TRUE
;
}
if
(
$query_string
[
'nid'
]
||
$query_string
[
'nids'
])
{
$context
[
'nids'
]
=
(
$query_string
[
'nid'
]
?
array
(
$query_string
[
'nid'
])
:
$query_string
[
'nids'
]);
}
...
...
@@ -414,14 +425,6 @@ function fillpdf_link_to_stub_context($uri) {
$context
[
'entity_ids'
]
=
isset
(
$query_string
[
'entity_id'
])
?
array
(
$query_string
[
'entity_id'
])
:
$query_string
[
'entity_ids'
];
}
if
(
isset
(
$query_string
[
'download'
])
&&
(
int
)
$query_string
[
'download'
]
===
1
)
{
$context
[
'force_download'
]
=
TRUE
;
}
if
(
isset
(
$query_string
[
'flatten'
])
&&
(
int
)
$query_string
[
'flatten'
]
===
0
)
{
$context
[
'flatten'
]
=
FALSE
;
return
$context
;
}
return
$context
;
}
...
...
@@ -564,7 +567,7 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_array = NULL, $sample =
$transform_string
=
FALSE
;
// Fill a sample PDF & return.
if
(
$sample
==
'true'
)
{
if
(
$sample
)
{
$fields
[
$obj
->
pdf_key
]
=
$obj
->
pdf_key
;
// If sampling, return to the form edit page.
$_GET
[
'destination'
]
=
"admin/structure/fillpdf/
$fid
"
;
...
...
This diff is collapsed.
Click to expand it.
tests/FillPdfLinkContextTestCase.test
0 → 100644
+
100
−
0
View file @
e277f83f
<?php
/**
* Tests some unit test cases.
*/
class
FillPdfLinkContextTestCase
extends
DrupalWebTestCase
{
/**
* {@inheritdoc}
*/
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'FillPDF query parameter unit test'
,
'description'
=>
'Unit tests evaluation of query parameters.'
,
'group'
=>
'FillPDF'
,
);
}
/**
* {@inheritdoc}
*/
public
function
setUp
()
{
// Enable any modules required for the test. This should be an array of
// module names.
parent
::
setUp
(
array
(
'fillpdf'
));
}
/**
* Tests boolean query parameters.
*/
public
function
testBooleans
()
{
foreach
(
$this
->
dataProvider
()
as
$case
)
{
foreach
(
$case
as
$input
=>
$expected
)
{
$request_context
=
fillpdf_link_to_stub_context
(
$this
->
link
(
$input
));
$this
->
assertEqual
(
is_null
(
$expected
)
?
FALSE
:
$expected
,
$request_context
[
'sample'
]);
$this
->
assertEqual
(
is_null
(
$expected
)
?
FALSE
:
$expected
,
$request_context
[
'force_download'
]);
$this
->
assertEqual
(
is_null
(
$expected
)
?
TRUE
:
$expected
,
$request_context
[
'flatten'
]);
}
}
}
/**
* Input helper for testBooleans().
*
* @param string $input
* The string to set as the query parameter value.
*
* @return string
* The full URL.
*/
public
function
link
(
$input
)
{
return
fillpdf_pdf_link
(
1
,
1
)
.
'&sample='
.
$input
.
'&download='
.
$input
.
'&flatten='
.
$input
;
}
/**
* Data provider for testBooleans().
*
* @return array
* Array of test cases.
*/
public
function
dataProvider
()
{
return
array
(
array
(
'1'
=>
TRUE
),
array
(
'true'
=>
TRUE
),
array
(
'True'
=>
TRUE
),
array
(
'TRUE'
=>
TRUE
),
array
(
'on'
=>
TRUE
),
array
(
'On'
=>
TRUE
),
array
(
'ON'
=>
TRUE
),
array
(
'yes'
=>
TRUE
),
array
(
'Yes'
=>
TRUE
),
array
(
'YES'
=>
TRUE
),
array
(
'0'
=>
FALSE
),
array
(
'false'
=>
FALSE
),
array
(
'False'
=>
FALSE
),
array
(
'FALSE'
=>
FALSE
),
array
(
'off'
=>
FALSE
),
array
(
'Off'
=>
FALSE
),
array
(
'OFF'
=>
FALSE
),
array
(
'no'
=>
FALSE
),
array
(
'No'
=>
FALSE
),
array
(
'NO'
=>
FALSE
),
// These three are important, so should always be obeyed:
array
(
''
=>
NULL
),
array
(
'foo'
=>
NULL
),
array
(
'bar'
=>
NULL
),
// The following ones are less fortunate, so may be refactored:
array
(
'-1'
=>
NULL
),
array
(
'2'
=>
NULL
),
array
(
'y'
=>
NULL
),
array
(
'Y'
=>
NULL
),
array
(
'n'
=>
NULL
),
array
(
'N'
=>
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