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

Issue #3058477 by Pancho: Expand pdftk parse test to LocalServer backend

parent cebb77c8
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\fillpdf\Functional;
use Drupal\Core\Url;
use Drupal\Core\Config\Config;
use Drupal\file\Entity\File;
use Drupal\fillpdf\Component\Utility\FillPdf;
use Drupal\fillpdf\Entity\FillPdfForm;
......@@ -27,11 +28,13 @@ class PdfParseTest extends FillPdfTestBase {
// 200, we assume that we're not in an environment where we can run this
// test.
$this->configureLocalServiceBackend();
$config = $this->container->get('config.factory')->get('fillpdf.settings');
if (!FillPdf::checkLocalServiceEndpoint($this->container->get('http_client'), $config)) {
throw new \PHPUnit_Framework_SkippedTestError('FillPDF LocalServer unavailable, so skipping test.');
}
$this->backendTest();
$this->backendTest($config);
}
/**
......@@ -40,16 +43,41 @@ class PdfParseTest extends FillPdfTestBase {
* @throws \PHPUnit_Framework_SkippedTestError
* Thrown when test had to be skipped as local pdftk install is not
* available.
*
* @todo Consolidate duplicate code with PdfPopulationTest.
*/
public function testParsePdftk() {
$this->configureFillPdf(['backend' => 'pdftk']);
if (!FillPdf::checkPdftkPath()) {
throw new \PHPUnit_Framework_SkippedTestError('pdftk not available, so skipping test.');
}
$fillpdf_form = $this->backendTest();
$config = $this->container->get('config.factory')->get('fillpdf.settings');
$this->backendTest($config);
}
/**
* Tests a backend.
*
* @param \Drupal\Core\Config\Config $fillpdf_config
* FillPDF configuration object.
*
* @return \Drupal\fillpdf\FillPdfFormInterface
* The created FillPdfForm.
*
* @internal
* @todo Consolidate duplicate code with PdfPopulationTest.
* @todo This may be significantly simplified once we're initializing a
* FillPdfForm with the parsed values.
* @see https://www.drupal.org/project/fillpdf/issues/3056400
*/
protected function backendTest(Config $fillpdf_config) {
$this->uploadTestPdf('fillpdf_Ŧäßð_v3â.pdf');
$this->assertSession()->pageTextNotContains('No fields detected in PDF.');
$fillpdf_form = FillPdfForm::load($this->getLatestFillPdfForm());
$fields = $fillpdf_form->getFormFields();
$this->assertCount(12, $fields);
// Get the uploaded template's file ID.
$previous_file_id = $fillpdf_form->file->target_id;
......@@ -69,10 +97,11 @@ class PdfParseTest extends FillPdfTestBase {
$this->assertSession()->pageTextNotContains('Merging the FillPDF Form failed');
// Retrieve the last file ID which should be the sample file.
// @todo: The saved xfdf file leads to the file counter being increased by
// two instead of 1.
// @todo: When using pdftk, the saved xfdf file leads to the file counter
// being increased by two instead of 1. We're therefore only comparing by
// "greater than".
$file_id = $this->getLastFileId();
static::assertEquals($previous_file_id + 2, $file_id);
static::assertTrue($file_id > $previous_file_id, 'Populated PDF was saved as a new managed file.');
// Load the sample file and check it is a PDF.
$file = File::load($file_id);
......@@ -86,9 +115,8 @@ class PdfParseTest extends FillPdfTestBase {
$fillpdf_form->save();
// Create an instance of the pdftk plugin.
$config = $this->container->get('config.factory')->get('fillpdf.settings');
$backend_manager = $this->container->get('plugin.manager.fillpdf_backend');
$backend = $backend_manager->createInstance('pdftk', $config->get());
$backend = $backend_manager->createInstance($config->get('backend'), $config->get());
// Reparse the sample PDF file and check for each text field that the
// field value equals the field name.
......@@ -98,21 +126,6 @@ class PdfParseTest extends FillPdfTestBase {
static::assertEquals($field['name'], $value);
}
}
}
/**
* Tests a backend.
*
* @return \Drupal\fillpdf\FillPdfFormInterface
* The created FillPdfForm.
*/
protected function backendTest() {
$this->uploadTestPdf('fillpdf_Ŧäßð_v3â.pdf');
$this->assertSession()->pageTextNotContains('No fields detected in PDF.');
$fillpdf_form = FillPdfForm::load($this->getLatestFillPdfForm());
$fields = $fillpdf_form->getFormFields();
$this->assertCount(12, $fields);
return $fillpdf_form;
}
......
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