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
7874f2da
Commit
7874f2da
authored
5 years ago
by
wizonesolutions
Committed by
Kevin Kaland
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue #3118306 by wizonesolutions: Fix local-only tests
parent
444036ef
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/src/Functional/PdfParseTest.php
+34
-14
34 additions, 14 deletions
tests/src/Functional/PdfParseTest.php
tests/src/Traits/TestFillPdfTrait.php
+4
-1
4 additions, 1 deletion
tests/src/Traits/TestFillPdfTrait.php
with
38 additions
and
15 deletions
tests/src/Functional/PdfParseTest.php
+
34
−
14
View file @
7874f2da
...
...
@@ -18,15 +18,11 @@ class PdfParseTest extends FillPdfTestBase {
/**
* Tests PDF population using local service.
*
* @throws \
PHPUnit_Framework_Skipped
Te
s
tE
rror
*
T
hrow
n when test had to be skipped as FillPDF LocalServer is not
*
available.
* @throws \
Behat\Mink\Exception\Response
Te
x
tE
xception
*
@t
hrow
s \Drupal\Component\Plugin\Exception\PluginException
*
@throws \Drupal\Core\Entity\EntityStorageException
*/
public
function
testParseLocalService
()
{
// For local container testing, we require the Docker container to be
// running on port 8085. If http://127.0.0.1:8085/ping does not return a
// 200, we assume that we're not in an environment where we can run this
// test.
$this
->
configureLocalServiceBackend
();
$config
=
$this
->
config
(
'fillpdf.settings'
);
...
...
@@ -40,9 +36,9 @@ class PdfParseTest extends FillPdfTestBase {
/**
* Tests PDF population using a local install of pdftk.
*
* @throws \
PHPUnit_Framework_Skipped
Te
s
tE
rror
*
T
hrow
n when test had to be skipped as local pdftk install is not
*
available.
* @throws \
Behat\Mink\Exception\Response
Te
x
tE
xception
*
@t
hrow
s \Drupal\Component\Plugin\Exception\PluginException
*
@throws \Drupal\Core\Entity\EntityStorageException
*/
public
function
testParsePdftk
()
{
$this
->
configureFillPdf
([
'backend'
=>
'pdftk'
]);
...
...
@@ -63,7 +59,12 @@ class PdfParseTest extends FillPdfTestBase {
* @return \Drupal\fillpdf\FillPdfFormInterface
* The created FillPdfForm.
*
* @throws \Behat\Mink\Exception\ResponseTextException
* @throws \Drupal\Component\Plugin\Exception\PluginException
* @throws \Drupal\Core\Entity\EntityStorageException
*
* @internal
*
* @todo Consolidate duplicate code with PdfPopulationTest.
* @todo This may be significantly simplified once we're initializing a
* FillPdfForm with the parsed values.
...
...
@@ -75,7 +76,7 @@ class PdfParseTest extends FillPdfTestBase {
$fillpdf_form
=
FillPdfForm
::
load
(
$this
->
getLatestFillPdfForm
());
$fields
=
$fillpdf_form
->
getFormFields
();
$this
->
assertCount
(
12
,
$fields
);
$this
->
assertCount
(
$this
->
getExpectedFieldCount
(
$fillpdf_config
->
get
(
'backend'
))
,
$fields
);
// Get the uploaded template's file ID.
$previous_file_id
=
$fillpdf_form
->
file
->
target_id
;
...
...
@@ -110,16 +111,35 @@ class PdfParseTest extends FillPdfTestBase {
$backend_manager
=
$this
->
container
->
get
(
'plugin.manager.fillpdf.pdf_backend'
);
$backend
=
$backend_manager
->
createInstance
(
$fillpdf_config
->
get
(
'backend'
),
$fillpdf_config
->
get
());
// Reparse the sample PDF file and check for each text field that the
// field value equals the field name.
// Re-parse the sample PDF file and check for each text field that the
// field value equals the field name (now in angle brackets, since the
// sample functionality does that).
foreach
(
$backend
->
parseFile
(
$file
)
as
$field
)
{
if
(
$field
[
'type'
]
==
'Text'
)
{
$value
=
isset
(
$field
[
'value'
])
?
$field
[
'value'
]
:
NULL
;
static
::
assertEquals
(
$field
[
'name'
],
$value
);
static
::
assertEquals
(
"<
{
$field
[
'name'
]
}
>"
,
$value
);
}
}
return
$fillpdf_form
;
}
/**
* Different backends process different types of fields. This method is used
* by ::backendTest() to assert against the correct value.
*
* @param $backend
*/
protected
function
getExpectedFieldCount
(
$backend
)
{
// NOTE: Other bugs led me to believe this was the case, but it's kind of a
// useful method, so I'm just leaving it for now.
switch
(
$backend
)
{
case
'local_service'
:
case
'pdftk'
:
return
12
;
}
throw
new
\LogicException
(
"Unexpected call to PdfParseTest::getExpectedFieldCount() with
\$
backend =
$backend
"
);
}
}
This diff is collapsed.
Click to expand it.
tests/src/Traits/TestFillPdfTrait.php
+
4
−
1
View file @
7874f2da
...
...
@@ -39,7 +39,10 @@ trait TestFillPdfTrait {
// PDFtk needs to have the correct locale set in the environment or the
// test will fail.
if
(
$configuration
[
'backend'
]
===
'pdftk'
)
{
$config
->
set
(
'shell_locale'
,
'en_US.UTF-8'
);
/** @var \Drupal\fillpdf\ShellManagerInterface $shell_manager */
$shell_manager
=
$this
->
container
->
get
(
'fillpdf.shell_manager'
);
$locales
=
$shell_manager
->
getInstalledLocales
();
$config
->
set
(
'shell_locale'
,
isset
(
$locales
[
'en_US.UTF-8'
])
?
'en_US.UTF-8'
:
'en_US.utf8'
);
}
$config
->
save
();
...
...
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