Skip to content
Snippets Groups Projects
Commit e0b13b34 authored by Bernd Oliver Suenderhauf's avatar Bernd Oliver Suenderhauf
Browse files

Issue #3055244 by Pancho: Fix PdfPopulationTest, implementing it for pdftk

parent 9fd30984
No related branches found
No related tags found
No related merge requests found
......@@ -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 testLocalServicePdfPopulation() {
public function testMergeLocalService() {
// 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));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment