You are here

public function FieldFormatterThirdPartySettingsFormEventTest::testAddingElements in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x modules/field_event_dispatcher/tests/src/Unit/Field/FieldFormatterThirdPartySettingsFormEventTest.php \Drupal\Tests\field_event_dispatcher\Unit\Field\FieldFormatterThirdPartySettingsFormEventTest::testAddingElements()

FieldFormatterThirdPartySettingsFormEvent adding elements test.

This tests adding third-party form elements.

File

modules/field_event_dispatcher/tests/src/Unit/Field/FieldFormatterThirdPartySettingsFormEventTest.php, line 86

Class

FieldFormatterThirdPartySettingsFormEventTest
Class FieldFormatterThirdPartySettingsFormEventTest.

Namespace

Drupal\Tests\field_event_dispatcher\Unit\Field

Code

public function testAddingElements() : void {
  $elements = $expectedElements = [];
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::FIELD_FORMATTER_THIRD_PARTY_SETTINGS_FORM => static function (FieldFormatterThirdPartySettingsFormEvent $event) {
      $event
        ->addElements('test_module', [
        'test' => [],
      ]);
    },
  ]);
  $testFieldDefinition = new BaseFieldDefinition();
  $testPlugin = new BasicStringFormatter('test_formatter', [], $testFieldDefinition, [], 'label', 'view_mode', []);
  $testFormState = new FormState();

  // Run the procedural hook which should trigger the above handler.
  $elements = field_event_dispatcher_field_formatter_third_party_settings_form($testPlugin, $testFieldDefinition, 'view_mode', [], $testFormState);

  /** @var \Drupal\field_event_dispatcher\Event\Field\FieldFormatterThirdPartySettingsFormEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::FIELD_FORMATTER_THIRD_PARTY_SETTINGS_FORM);
  self::assertSame($elements, $event
    ->getElements());
  $expectedElements['test_module']['test'] = [];
  self::assertSame($expectedElements, $elements);
}