public function PdfPopulationTest::testProxyMerge in FillPDF 8.4
Same name and namespace in other branches
- 5.0.x tests/src/Functional/PdfPopulationTest.php \Drupal\Tests\fillpdf\Functional\PdfPopulationTest::testProxyMerge()
Tests that merging with the backend proxy works.
File
- tests/
src/ Functional/ PdfPopulationTest.php, line 283
Class
- PdfPopulationTest
- Tests Core entity population and image stamping.
Namespace
Drupal\Tests\fillpdf\FunctionalCode
public function testProxyMerge() {
$this
->uploadTestPdf('fillpdf_test_v3.pdf');
$fillpdf_form = FillPdfForm::load($this
->getLatestFillPdfForm());
// Instantiate the backend proxy (which uses the configured backend).
/** @var \Drupal\fillpdf\Service\BackendProxyInterface $merge_proxy */
$merge_proxy = $this->container
->get('fillpdf.backend_proxy');
$original_pdf = file_get_contents($this
->getTestPdfPath('fillpdf_test_v3.pdf'));
FillPdfTestBase::mapFillPdfFieldsToEntityFields('node', $fillpdf_form
->getFormFields());
// Create a node to populate the FillPdf Form.
// The content of this node is not important; we just need an entity to
// pass.
$node = $this
->createNode([
'title' => 'Hello & how are you?',
'type' => 'article',
'body' => [
[
'value' => "<p>PDF form fields don't accept <em>any</em> HTML.</p>",
'format' => 'restricted_html',
],
],
]);
$entities['node'] = [
$node
->id() => $node,
];
// Test merging via the proxy.
$merged_pdf = $merge_proxy
->merge($fillpdf_form, $entities);
self::assertEquals($original_pdf, $merged_pdf);
$merge_state = $this->container
->get('state')
->get('fillpdf_test.last_populated_metadata');
self::assertInternalType('array', $merge_state, 'Test backend was used.');
self::assertArrayHasKey('field_mapping', $merge_state, 'field_mapping key from test backend is present.');
self::assertArrayHasKey('context', $merge_state, 'context key from test backend is present.');
// These are not that important. They just work because of other tests.
// We're just testing that token replacement works in general, not the
// details of it. We have other tests for that.
self::assertEquals('Hello & how are you doing?', $merge_state['field_mapping']['fields']['TextField1']);
self::assertEquals("PDF form fields don't accept any HTML.\n", $merge_state['field_mapping']['fields']['TextField2']);
}