$build['#attached'
]['library'
][] = 'core/drupal.timezone';
$build['#attached'
]['library'
][] = 'core/drupal.vertical-tabs';
$assets = AttachedAssets::
createFromRenderArray($build);
$this->
assertCount(1,
$this->assetResolver->
getCssAssets($assets, TRUE, \Drupal::
languageManager()->
getCurrentLanguage()), 'There is a sole aggregated CSS asset.'
);
[$header_js,
$footer_js] =
$this->assetResolver->
getJsAssets($assets, TRUE, \Drupal::
languageManager()->
getCurrentLanguage());
$this->
assertEquals([], \Drupal::
service('asset.js.collection_renderer'
)->
render($header_js), 'There are 0 JavaScript assets in the header.'
);
$rendered_footer_js = \Drupal::
service('asset.js.collection_renderer'
)->
render($footer_js);
$this->
assertCount(2,
$rendered_footer_js, 'There are 2 JavaScript assets in the footer.'
);
$this->
assertEquals('drupal-settings-json',
$rendered_footer_js[0
]['#attributes'
]['data-drupal-selector'
], 'The first of the two JavaScript assets in the footer has drupal settings.'
);
$this->
assertStringStartsWith(base_path(),
$rendered_footer_js[1
]['#attributes'
]['src'
], 'The second of the two JavaScript assets in the footer has the sole aggregated JavaScript asset.'
);
} /**
* Tests JavaScript settings.
*/
public function testSettings() { $build =
[];
$build['#attached'
]['library'
][] = 'core/drupalSettings';
// Nonsensical value to verify if it's possible to override path settings.
$build['#attached'
]['drupalSettings'
]['path'
]['pathPrefix'
] = 'yarhar';
$assets = AttachedAssets::
createFromRenderArray($build);