class ThemeRegistryAlterEventTest in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/core_event_dispatcher/tests/src/Unit/Theme/ThemeRegistryAlterEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Theme\ThemeRegistryAlterEventTest
Class ThemeRegistryAlterEventTest.
@group hook_event_dispatcher
Hierarchy
- class \Drupal\Tests\core_event_dispatcher\Unit\Theme\ThemeRegistryAlterEventTest extends \PHPUnit\Framework\TestCase
Expanded class hierarchy of ThemeRegistryAlterEventTest
File
- modules/
core_event_dispatcher/ tests/ src/ Unit/ Theme/ ThemeRegistryAlterEventTest.php, line 18
Namespace
Drupal\Tests\core_event_dispatcher\Unit\ThemeView source
class ThemeRegistryAlterEventTest extends TestCase {
/**
* The manager.
*
* @var \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy
*/
private $manager;
/**
* Sets up the test.
*/
public function setUp() : void {
$builder = new ContainerBuilder();
$this->manager = new HookEventDispatcherManagerSpy();
$builder
->set('hook_event_dispatcher.manager', $this->manager);
$builder
->compile();
Drupal::setContainer($builder);
}
/**
* ThemeRegistryAlterEvent with theme implementation alter test.
*/
public function testThemeRegistryAlterEventWithThemeAlter() : void {
$themeRegistry = $expected = [
'existing_theme_hook__with_information' => [
'variables' => [
'variable1' => NULL,
'variable2' => FALSE,
'variable3' => [],
],
'type' => 'base_theme_engine',
'template' => 'existing-theme-hook--with-information',
],
];
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::THEME_REGISTRY_ALTER => static function (ThemeRegistryAlterEvent $event) {
$themeRegistry =& $event
->getThemeRegistry();
$themeRegistry['existing_theme_hook__with_information']['variables']['variable2'] = TRUE;
},
]);
core_event_dispatcher_theme_registry_alter($themeRegistry);
$expected['existing_theme_hook__with_information']['variables']['variable2'] = TRUE;
self::assertSame($expected, $themeRegistry);
/** @var \Drupal\core_event_dispatcher\Event\Theme\ThemeRegistryAlterEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::THEME_REGISTRY_ALTER);
self::assertSame($expected, $event
->getThemeRegistry());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ThemeRegistryAlterEventTest:: |
private | property | The manager. | |
ThemeRegistryAlterEventTest:: |
public | function | Sets up the test. | |
ThemeRegistryAlterEventTest:: |
public | function | ThemeRegistryAlterEvent with theme implementation alter test. |