You are here

public function ThemeEventTest::testThemeEventWithAddNewThemes in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 3.x modules/core_event_dispatcher/tests/src/Unit/Theme/ThemeEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Theme\ThemeEventTest::testThemeEventWithAddNewThemes()

ThemeEvent with addNewThemes test.

File

modules/core_event_dispatcher/tests/src/Unit/Theme/ThemeEventTest.php, line 42

Class

ThemeEventTest
Class ThemeEventTest.

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Theme

Code

public function testThemeEventWithAddNewThemes() : void {
  $newThemes = [
    'some_custom__hook_theme' => [
      'variables' => [
        'custom_variable' => NULL,
      ],
      'path' => 'some/path',
    ],
  ];
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::THEME => static function (ThemeEvent $event) use ($newThemes) {
      $event
        ->addNewThemes($newThemes);
    },
  ]);
  $existing = [
    'existing_theme_hook__with_information' => [
      'render element' => [
        '#type' => 'date',
        '#title' => 'Some date',
        '#default_value' => [
          'year' => 2020,
          'month' => 2,
          'day' => 15,
        ],
      ],
    ],
  ];
  $hookNewInformation = core_event_dispatcher_theme($existing);

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