public function ToolbarAlterEventTest::testToolbarAlterEvent in Hook Event Dispatcher 8.2
Same name and namespace in other branches
- 3.x modules/toolbar_event_dispatcher/tests/src/Unit/Toolbar/ToolbarAlterEventTest.php \Drupal\Tests\toolbar_event_dispatcher\Unit\Toolbar\ToolbarAlterEventTest::testToolbarAlterEvent()
Test the ToolbarAlterEvent.
File
- modules/
toolbar_event_dispatcher/ tests/ src/ Unit/ Toolbar/ ToolbarAlterEventTest.php, line 41
Class
- ToolbarAlterEventTest
- Class ToolbarAlterEventTest.
Namespace
Drupal\Tests\toolbar_event_dispatcher\Unit\ToolbarCode
public function testToolbarAlterEvent() : void {
$newItem = [
'test' => 'item',
];
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::TOOLBAR_ALTER => static function (ToolbarAlterEvent $event) use ($newItem) {
$items =& $event
->getItems();
$items += $newItem;
},
]);
$items = [
'user' => [],
'manage' => [],
];
$expectedItems = $items + $newItem;
toolbar_event_dispatcher_toolbar_alter($items);
/** @var \Drupal\toolbar_event_dispatcher\Event\Toolbar\ToolbarAlterEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::TOOLBAR_ALTER);
self::assertSame($expectedItems, $items);
self::assertSame($expectedItems, $event
->getItems());
}