You are here

public function AbstractFieldSettingsSummaryAlterEventTestCase::testAddSummary in Hook Event Dispatcher 8.2

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

AbstractFieldSettingsSummaryAlterEventTestCase adding summary test.

This tests adding an additional summary.

File

modules/field_event_dispatcher/tests/src/Unit/Field/AbstractFieldSettingsSummaryAlterEventTestCase.php, line 69

Class

AbstractFieldSettingsSummaryAlterEventTestCase
Class AbstractFieldSettingsSummaryAlterEventTestCase.

Namespace

Drupal\Tests\field_event_dispatcher\Unit\Field

Code

public function testAddSummary() : void {
  $summary = $expectedSummary = [];
  $eventName = $this
    ->getEventName();
  $this->manager
    ->setEventCallbacks([
    $eventName => static function (AbstractFieldSettingsSummaryFormEvent $event) {
      $event
        ->getSummary()[] = 'Test';
    },
  ]);

  // Run the procedural hook which should trigger the above handler.
  $hook = $this
    ->getProceduralHookName();
  $hook($summary, []);

  /** @var \Drupal\field_event_dispatcher\Event\Field\AbstractFieldSettingsSummaryFormEvent $event */
  $event = $this->manager
    ->getRegisteredEvent($eventName);
  self::assertSame($summary, $event
    ->getSummary());
  $expectedSummary[] = 'Test';
  self::assertSame($expectedSummary, $summary);
}