You are here

public function ThemeEventTest::testThemeEventWithAddNewTheme in Hook Event Dispatcher 8

ThemeEvent with addNewTheme test.

File

tests/src/Unit/Theme/ThemeEventTest.php, line 105

Class

ThemeEventTest
Class ThemeEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Theme

Code

public function testThemeEventWithAddNewTheme() {
  $themeHook = 'extra_theme__hook';
  $information = [
    'test' => 'extra_theme_information',
    'path' => 'some/path',
  ];
  $expectedNewTheme = [
    $themeHook => $information,
  ];
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::THEME => function (ThemeEvent $event) use ($themeHook, $information) {
      $event
        ->addNewTheme($themeHook, $information);
    },
  ]);
  $existing = [
    'existing_theme_hook__with_information' => [
      'render element' => [
        '#type' => 'date',
        '#title' => 'Some date',
        '#default_value' => [
          'year' => 2020,
          'month' => 2,
          'day' => 15,
        ],
      ],
    ],
  ];
  $hookNewInformation = hook_event_dispatcher_theme($existing);

  /** @var \Drupal\hook_event_dispatcher\Event\Theme\ThemeEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::THEME);
  self::assertSame($existing, $event
    ->getExisting());
  self::assertSame($expectedNewTheme, $hookNewInformation);
}