You are here

public function FillPdfFormImportFormTest::testExportDuplicateImport in FillPDF 5.0.x

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/FillPdfFormImportFormTest.php \Drupal\Tests\fillpdf\Functional\FillPdfFormImportFormTest::testExportDuplicateImport()

Tests export and import functions.

File

tests/src/Functional/FillPdfFormImportFormTest.php, line 40

Class

FillPdfFormImportFormTest
@coversDefaultClass \Drupal\fillpdf\Form\FillPdfFormImportForm @group fillpdf

Namespace

Drupal\Tests\fillpdf\Functional

Code

public function testExportDuplicateImport() {
  $this
    ->uploadTestPdf('fillpdf_test_v3.pdf');
  $form1_id = $this
    ->getLatestFillPdfForm();

  // We're now on the edit form. Add some configuration.
  $this
    ->assertSession()
    ->pageTextContains('New FillPDF form has been created.');
  $edit = [
    'admin_title[0][value]' => 'Test',
    'replacements[0][value]' => 'y|Yes',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains("FillPDF Form Test has been updated.");

  // Export.
  $this
    ->drupalGet(Url::fromRoute('entity.fillpdf_form.export_form', [
    'fillpdf_form' => $form1_id,
  ]));
  $code = $this
    ->assertSession()
    ->fieldExists('export')
    ->getValue();

  // Duplicate the form.
  $duplicate_url = Url::fromRoute('entity.fillpdf_form.duplicate_form', [
    'fillpdf_form' => $form1_id,
  ]);
  $this
    ->drupalPostForm($duplicate_url, [], 'Save');
  $form2_id = $this
    ->getLatestFillPdfForm();

  // Change some configuration.
  // @todo: Even without a destination set, we should always return somewhere
  // instead of remaining on the duplicate confirm page.
  $edit = [
    'replacements[0][value]' => 'n|No',
  ];
  $this
    ->drupalPostForm(Url::fromRoute('entity.fillpdf_form.edit_form', [
    'fillpdf_form' => $form2_id,
  ]), $edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains("FillPDF Form Duplicate of Test has been updated.");

  // Import again.
  $import_url = Url::fromRoute('entity.fillpdf_form.import_form', [
    'fillpdf_form' => $form2_id,
  ]);
  $this
    ->drupalPostForm($import_url, [
    'code' => $code,
  ], 'Import');

  // Check none of the mappings failed.
  $this
    ->assertSession()
    ->pageTextContains('Successfully imported FillPDF form configuration and matching PDF field keys.');
  $this
    ->assertSession()
    ->pageTextNotContains('but it does not exist on this form. Therefore, it was ignored.');

  // Check the admin_title has been imported as well.
  $this
    ->assertSession()
    ->fieldValueEquals('admin_title[0][value]', 'Test');
  $this
    ->assertSession()
    ->fieldValueEquals('replacements[0][value]', 'y|Yes');
}