Skip to content
Snippets Groups Projects
Commit 7874f2da authored by wizonesolutions's avatar wizonesolutions Committed by Kevin Kaland
Browse files

Issue #3118306 by wizonesolutions: Fix local-only tests

parent 444036ef
No related branches found
No related tags found
No related merge requests found
......@@ -18,15 +18,11 @@ class PdfParseTest extends FillPdfTestBase {
/**
* Tests PDF population using local service.
*
* @throws \PHPUnit_Framework_SkippedTestError
* Thrown when test had to be skipped as FillPDF LocalServer is not
* available.
* @throws \Behat\Mink\Exception\ResponseTextException
* @throws \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_SkippedTestError
* Thrown when test had to be skipped as local pdftk install is not
* available.
* @throws \Behat\Mink\Exception\ResponseTextException
* @throws \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");
}
}
......@@ -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();
......
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