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
e0b13b34
Commit
e0b13b34
authored
5 years ago
by
Bernd Oliver Suenderhauf
Browse files
Options
Downloads
Patches
Plain Diff
Issue #3055244 by Pancho: Fix PdfPopulationTest, implementing it for pdftk
parent
9fd30984
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/src/Functional/PdfPopulationTest.php
+22
-16
22 additions, 16 deletions
tests/src/Functional/PdfPopulationTest.php
with
22 additions
and
16 deletions
tests/src/Functional/PdfPopulationTest.php
+
22
−
16
View file @
e0b13b34
...
...
@@ -18,13 +18,6 @@ use Drupal\node\Entity\Node;
*/
class
PdfPopulationTest
extends
FillPdfTestBase
{
/**
* A test node.
*
* @var \Drupal\node\NodeInterface[]
*/
protected
$testNodes
;
/**
* Modules to enable.
*
...
...
@@ -56,7 +49,7 @@ class PdfPopulationTest extends FillPdfTestBase {
$fillpdf_form
=
FillPdfForm
::
load
(
$this
->
getLatestFillPdfForm
());
$
this
->
testNodes
[
1
]
=
$this
->
createNode
([
$
node
=
$this
->
createNode
([
'title'
=>
'Hello & how are you?'
,
'type'
=>
'article'
,
'body'
=>
[[
...
...
@@ -74,7 +67,7 @@ class PdfPopulationTest extends FillPdfTestBase {
$fillpdf_route
=
Url
::
fromRoute
(
'fillpdf.populate_pdf'
,
[],
[
'query'
=>
[
'fid'
=>
$fillpdf_form
->
id
(),
'entity_id'
=>
"node:
{
$
this
->
testNodes
[
1
]
->
id
()
}
"
,
'entity_id'
=>
"node:
{
$
node
->
id
()
}
"
,
],
]);
$this
->
drupalGet
(
$fillpdf_route
);
...
...
@@ -106,7 +99,7 @@ class PdfPopulationTest extends FillPdfTestBase {
$this
->
assertSession
()
->
pageTextContains
(
'New FillPDF form has been created.'
);
$fillpdf_form
=
FillPdfForm
::
load
(
$this
->
getLatestFillPdfForm
());
$
this
->
testNodes
[
2
]
=
Node
::
load
(
$
node
=
Node
::
load
(
$this
->
uploadNodeImage
(
$this
->
testImage
,
'field_fillpdf_test_image'
,
...
...
@@ -123,7 +116,7 @@ class PdfPopulationTest extends FillPdfTestBase {
$fillpdf_route
=
Url
::
fromRoute
(
'fillpdf.populate_pdf'
,
[],
[
'query'
=>
[
'fid'
=>
$fillpdf_form
->
id
(),
'entity_id'
=>
"node:
{
$
this
->
testNodes
[
2
]
->
id
()
}
"
,
'entity_id'
=>
"node:
{
$
node
->
id
()
}
"
,
],
]);
$this
->
drupalGet
(
$fillpdf_route
);
...
...
@@ -133,7 +126,7 @@ class PdfPopulationTest extends FillPdfTestBase {
$populate_result
=
$this
->
container
->
get
(
'state'
)
->
get
(
'fillpdf_test.last_populated_metadata'
);
$node_file
=
File
::
load
(
$
this
->
testNodes
[
2
]
->
field_fillpdf_test_image
->
target_id
);
$node_file
=
File
::
load
(
$
node
->
field_fillpdf_test_image
->
target_id
);
self
::
assertEquals
(
$populate_result
[
'field_mapping'
][
'images'
][
'ImageField'
][
'data'
],
base64_encode
(
file_get_contents
(
$node_file
->
getFileUri
())),
...
...
@@ -255,7 +248,7 @@ class PdfPopulationTest extends FillPdfTestBase {
* Thrown when test had to be skipped as FillPDF LocalServer is not
* available.
*/
public
function
testLocalService
PdfPopulation
()
{
public
function
test
Merge
LocalService
()
{
// 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
...
...
@@ -277,8 +270,12 @@ class PdfPopulationTest extends FillPdfTestBase {
*
* @todo Implementation missing.
*/
public
function
testPdftkPdfPopulation
()
{
throw
new
\PHPUnit_Framework_SkippedTestError
(
'Not implemented yet, so skipping test.'
);
public
function
testMergePdftk
()
{
$this
->
configureFillPdf
([
'backend'
=>
'pdftk'
]);
if
(
!
FillPdf
::
checkPdftkPath
())
{
throw
new
\PHPUnit_Framework_SkippedTestError
(
'pdftk not available, so skipping test.'
);
}
$this
->
backendTest
();
}
/**
...
...
@@ -295,14 +292,23 @@ class PdfPopulationTest extends FillPdfTestBase {
$fields
=
$fillpdf_form
->
getFormFields
();
$this
->
mapFillPdfFieldsToNodeFields
(
$fields
);
// Set up a test node.
$node
=
$this
->
createNode
([
'title'
=>
'Test'
,
'type'
=>
'article'
,
]);
// Hit the generation route, check the results from the test backend plugin.
$fillpdf_route
=
Url
::
fromRoute
(
'fillpdf.populate_pdf'
,
[],
[
'query'
=>
[
'fid'
=>
$fillpdf_form
->
id
(),
'entity_id'
=>
"node:
{
$
this
->
testNodes
[
2
]
->
id
()
}
"
,
'entity_id'
=>
"node:
{
$
node
->
id
()
}
"
,
],
]);
$this
->
drupalGet
(
$fillpdf_route
);
$this
->
assertSession
()
->
pageTextNotContains
(
'Merging the FillPDF Form failed'
);
// Check if what we're seeing really is a PDF file.
$maybe_pdf
=
$this
->
getSession
()
->
getPage
()
->
getContent
();
$finfo
=
new
\finfo
(
FILEINFO_MIME_TYPE
);
static
::
assertEquals
(
'application/pdf'
,
$finfo
->
buffer
(
$maybe_pdf
));
...
...
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