public function JsAlterEventTest::testJsAlterEventByReference in Hook Event Dispatcher 8
JsAlterEvent by reference test.
File
- tests/
src/ Unit/ Theme/ JsAlterEventTest.php, line 42
Class
- JsAlterEventTest
- Class JsAlterEventTest.
Namespace
Drupal\Tests\hook_event_dispatcher\Unit\ThemeCode
public function testJsAlterEventByReference() {
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::JS_ALTER => function (JsAlterEvent $event) {
$javascript =& $event
->getJavascript();
unset($javascript['unset']);
},
]);
$javascript = $expectedJavascript = [
'unset' => [
'data',
],
'other' => [
'other_data',
],
];
unset($expectedJavascript['unset']);
$attachedAssets = new AttachedAssets();
hook_event_dispatcher_js_alter($javascript, $attachedAssets);
/** @var \Drupal\hook_event_dispatcher\Event\Theme\JsAlterEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::JS_ALTER);
self::assertSame($expectedJavascript, $event
->getJavascript());
self::assertSame($attachedAssets, $event
->getAttachedAssets());
}