public function JsAlterEventTest::testJsAlterEvent in Hook Event Dispatcher 8.2
Same name and namespace in other branches
- 3.x modules/core_event_dispatcher/tests/src/Unit/Theme/JsAlterEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Theme\JsAlterEventTest::testJsAlterEvent()
JsAlterEvent test.
File
- modules/
core_event_dispatcher/ tests/ src/ Unit/ Theme/ JsAlterEventTest.php, line 42
Class
- JsAlterEventTest
- Class JsAlterEventTest.
Namespace
Drupal\Tests\core_event_dispatcher\Unit\ThemeCode
public function testJsAlterEvent() : void {
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::JS_ALTER => static function (JsAlterEvent $event) {
$javascript =& $event
->getJavascript();
unset($javascript['unset']);
},
]);
$javascript = $expectedJavascript = [
'unset' => [
'data',
],
'other' => [
'other_data',
],
];
unset($expectedJavascript['unset']);
$attachedAssets = new AttachedAssets();
core_event_dispatcher_js_alter($javascript, $attachedAssets);
/** @var \Drupal\core_event_dispatcher\Event\Theme\JsAlterEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::JS_ALTER);
self::assertSame($expectedJavascript, $event
->getJavascript());
self::assertSame($attachedAssets, $event
->getAttachedAssets());
}