You are here

class Test in FillPDF 8.4

Backend used in tests.

Plugin annotation


@BackendService(
  id = "test",
  label = @Translation("FillPDF Test Backend Service"),
)

Hierarchy

Expanded class hierarchy of Test

4 string references to 'Test'
FillPdfFormDeleteFormTest::testDeleteFormCancel in tests/src/Functional/FillPdfFormDeleteFormTest.php
Tests the cancel link works.
FillPdfFormDuplicateFormTest::testDuplicateForm in tests/src/Functional/FillPdfFormDuplicateFormTest.php
Tests the duplicate function.
FillPdfFormImportFormTest::testExportDuplicateImport in tests/src/Functional/FillPdfFormImportFormTest.php
Tests export and import functions.
PdfPopulationTest::backendTest in tests/src/Functional/PdfPopulationTest.php
Tests a backend.

File

tests/modules/fillpdf_test/src/Plugin/BackendService/Test.php, line 18

Namespace

Drupal\fillpdf_test\Plugin\BackendService
View source
class Test extends BackendServiceBase implements ContainerFactoryPluginInterface {

  /**
   * The state.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * Constructs a \Drupal\Component\Plugin\PluginBase object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, StateInterface $state) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->configuration = $configuration;
    $this->state = $state;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('state'));
  }

  /**
   * {@inheritdoc}
   */
  public function parse($pdf_content) {
    return static::getParseResult();
  }

  /**
   * {@inheritdoc}
   */
  public function merge($pdf_content, array $field_mappings, array $options) {
    $this->state
      ->set('fillpdf_test.last_populated_metadata', [
      'field_mapping' => $field_mappings,
      'options' => $options,
    ]);
    return file_get_contents(drupal_get_path('module', 'fillpdf_test') . '/files/fillpdf_test_v3.pdf');
  }

  /**
   * Returns a list of fields, as if a PDF file was parsed.
   *
   * Note that there is a duplicate field that get consolidated in
   * InputHelper::attachPdfToForm() at the latest.
   * The expected number of fields is therefore three, not four.
   *
   * @return array
   *   List of associative arrays representing fields.
   *
   * @see \Drupal\fillpdf\InputHelper::attachPdfToForm()
   */
  public static function getParseResult() {
    return [
      0 => [
        'name' => 'ImageField',
        'value' => '',
        'type' => 'Pushbutton',
      ],
      1 => [
        'name' => 'TestButton',
        'value' => '',
        'type' => 'Pushbutton',
      ],
      2 => [
        'name' => 'TextField1',
        'value' => '',
        'type' => 'Text',
      ],
      3 => [
        'name' => 'TextField2',
        'value' => '',
        'type' => 'Text',
      ],
      4 => [
        'name' => 'ImageField',
        'value' => '',
        'type' => 'Pushbutton',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
Test::$state protected property The state.
Test::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
Test::getParseResult public static function Returns a list of fields, as if a PDF file was parsed.
Test::merge public function Populate a PDF file with field data. Overrides BackendServiceInterface::merge
Test::parse public function Parse a PDF and return a list of its fields. Overrides BackendServiceInterface::parse
Test::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct