FillPdfTestBase.php in FillPDF 8.4
File
tests/src/Functional/FillPdfTestBase.php
View source
<?php
namespace Drupal\Tests\fillpdf\Functional;
use Drupal\Tests\file\Functional\FileFieldTestBase;
use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
use Drupal\Tests\fillpdf\Traits\TestImageFieldTrait;
use Drupal\user\Entity\Role;
abstract class FillPdfTestBase extends FileFieldTestBase {
use TestFillPdfTrait;
use TestImageFieldTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'image',
'fillpdf_test',
];
protected $backendServiceManager;
protected $linkManipulator;
protected $testImage;
public static function mapFillPdfFieldsToEntityFields($entity_type, array $fields) {
$token_entity_mapper = \Drupal::service('token.entity_mapper');
$token_type = $token_entity_mapper
->getTokenTypeForEntityType($entity_type);
foreach ($fields as $pdf_key => $field) {
switch ($pdf_key) {
case 'ImageField':
case 'Button2':
case 'TestButton':
$field->value = "[{$token_type}:field_fillpdf_test_image]";
break;
case 'TextField1':
case 'Text1':
$label_key = \Drupal::entityTypeManager()
->getDefinition($entity_type)
->getKey('label');
$field->value = "[{$token_type}:{$label_key}]";
$field->replacements = 'Hello & how are you?|Hello & how are you doing?';
break;
case 'TextField2':
case 'Text2':
if ($token_type == 'node') {
$field->value = '[node:body]';
}
elseif ($token_type == 'term') {
$field->value = '[term:description]';
}
break;
}
$field
->save();
}
}
protected function setUp() {
parent::setUp();
$existing_user_roles = $this->adminUser
->getRoles(TRUE);
$role_to_modify = Role::load(end($existing_user_roles));
$this
->grantPermissions($role_to_modify, [
'administer pdfs',
'create article content',
'edit any article content',
'delete any article content',
]);
$this->testImage = $this
->getTestFile('image');
$this
->configureFillPdf();
$this->backendServiceManager = $this->container
->get('plugin.manager.fillpdf_backend_service');
$this->linkManipulator = $this->container
->get('fillpdf.link_manipulator');
}
}