function AttachedAssetsTest::testAttachedSettingsWithoutLibraries
Test settings can be loaded even when libraries are not.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Asset/ AttachedAssetsTest.php, line 473
Class
- AttachedAssetsTest
- Tests #attached assets: attached asset libraries and JavaScript settings.
Namespace
Drupal\KernelTests\Core\AssetCode
public function testAttachedSettingsWithoutLibraries() : void {
$assets = new AttachedAssets();
// First test with no libraries will return no settings.
$assets->setSettings([
'test' => 'foo',
]);
$js = $this->assetResolver
->getJsAssets($assets, TRUE, \Drupal::languageManager()->getCurrentLanguage())[1];
$this->assertArrayNotHasKey('drupalSettings', $js);
// Second test with a warm cache.
$js = $this->assetResolver
->getJsAssets($assets, TRUE, \Drupal::languageManager()->getCurrentLanguage())[1];
$this->assertArrayNotHasKey('drupalSettings', $js);
// Now test with different settings when drupalSettings is already loaded.
$assets->setSettings([
'test' => 'bar',
]);
$assets->setAlreadyLoadedLibraries([
'core/drupalSettings',
]);
$js = $this->assetResolver
->getJsAssets($assets, TRUE, \Drupal::languageManager()->getCurrentLanguage())[1];
$this->assertSame('bar', $js['drupalSettings']['data']['test']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.