public function ThemeEventTest::testThemeEventWithAddNewTheme in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/core_event_dispatcher/tests/src/Unit/Theme/ThemeEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Theme\ThemeEventTest::testThemeEventWithAddNewTheme()
ThemeEvent with addNewTheme test.
File
- modules/
core_event_dispatcher/ tests/ src/ Unit/ Theme/ ThemeEventTest.php, line 106
Class
- ThemeEventTest
- Class ThemeEventTest.
Namespace
Drupal\Tests\core_event_dispatcher\Unit\ThemeCode
public function testThemeEventWithAddNewTheme() : void {
$themeHook = 'extra_theme__hook';
$information = [
'test' => 'extra_theme_information',
'path' => 'some/path',
];
$expectedNewTheme = [
$themeHook => $information,
];
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::THEME => static 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 = 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($expectedNewTheme, $hookNewInformation);
self::assertSame($expectedNewTheme, $event
->getNewThemes());
}