/**
* Adds a JavaScript library to the page and alters it.
*
* @see common_test_library_info_alter()
*/
public function testLibraryAlter() { // Verify that common_test altered the title of loadjs.
/** @var \Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery */
$library_discovery = \Drupal::
service('library.discovery'
);
$library =
$library_discovery->
getLibraryByName('core', 'loadjs'
);
$this->
assertEquals('0.0',
$library['version'
], 'Registered libraries were altered.'
);
// common_test_library_info_alter() also added a dependency on jQuery Form.
$build['#attached'
]['library'
][] = 'core/loadjs';
$assets = AttachedAssets::
createFromRenderArray($build);
$js =
$this->assetResolver->
getJsAssets($assets, FALSE, \Drupal::
languageManager()->
getCurrentLanguage())[1
];
$js_render_array = \Drupal::
service('asset.js.collection_renderer'
)->
render($js);
$rendered_js =
$this->renderer->
renderPlain($js_render_array);
$this->
assertStringContainsString('core/assets/vendor/jquery-form/jquery.form.min.js',
(string) $rendered_js, 'Altered library dependencies are added to the page.'
);
}