FillPdfTestBase.php in FillPDF 5.0.x
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 $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() : void {
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->linkManipulator = $this->container
->get('fillpdf.link_manipulator');
}
}