Commit 4ecc4ead authored by catch's avatar catch

Issue #2382557 by Wim Leers: Change JS settings into a separate asset type

parent 86ced511
......@@ -52,7 +52,18 @@ drupal:
drupalSettings:
version: VERSION
settings: {}
drupalSettings:
# These placeholder values will be set by system_js_settings_alter().
path:
baseUrl: null
scriptPath: null
pathPrefix: null
currentPath: null
currentPathIsAdmin: null
isFront: null
currentLanguage: null
locale:
pluralDelimiter: null
drupal.active-link:
version: VERSION
......
......@@ -179,18 +179,13 @@ function _batch_progress_page() {
),
),
// Adds JavaScript code and settings for clients where JavaScript is enabled.
'js' => array(
array(
'type' => 'setting',
'data' => array(
'batch' => array(
'errorMessage' => $current_set['error_message'] . '<br />' . $batch['error_message'],
'initMessage' => $current_set['init_message'],
'uri' => $url,
),
),
),
),
'drupalSettings' => [
'batch' => [
'errorMessage' => $current_set['error_message'] . '<br />' . $batch['error_message'],
'initMessage' => $current_set['init_message'],
'uri' => $url,
],
],
'library' => array(
'core/drupal.batch',
),
......
This diff is collapsed.
......@@ -129,8 +129,8 @@ protected function ajaxRender(Request $request) {
// HTML in the page. We pass TRUE as the $skip_alter argument to prevent the
// data from being altered again, as we already altered it above. Settings
// are handled separately, afterwards.
if (isset($items['js']['settings'])) {
unset($items['js']['settings']);
if (isset($items['js']['drupalSettings'])) {
unset($items['js']['drupalSettings']);
}
$styles = drupal_get_css($items['css'], TRUE);
$scripts_footer = drupal_get_js('footer', $items['js'], TRUE, TRUE);
......@@ -153,17 +153,15 @@ protected function ajaxRender(Request $request) {
// Prepend a command to merge changes and additions to drupalSettings.
$scripts = _drupal_add_js();
if (!empty($scripts['settings'])) {
$settings = drupal_merge_js_settings($scripts['settings']['data']);
if (!empty($scripts['drupalSettings'])) {
$settings = $scripts['drupalSettings']['data'];
// During Ajax requests basic path-specific settings are excluded from
// new drupalSettings values. The original page where this request comes
// from already has the right values for the keys below. An Ajax request
// would update them with values for the Ajax request and incorrectly
// override the page's values.
// from already has the right values. An Ajax request would update them
// with values for the Ajax request and incorrectly override the page's
// values.
// @see _drupal_add_js()
foreach (array('basePath', 'currentPath', 'scriptPath', 'pathPrefix') as $item) {
unset($settings[$item]);
}
unset($settings['path']);
$this->addCommand(new SettingsCommand($settings, TRUE), TRUE);
}
......
......@@ -68,7 +68,7 @@ public function render(array $js_assets) {
switch ($js_asset['type']) {
case 'setting':
$element['#value_prefix'] = $embed_prefix;
$element['#value'] = 'var drupalSettings = ' . Json::encode(drupal_merge_js_settings($js_asset['data'])) . ";";
$element['#value'] = 'var drupalSettings = ' . Json::encode($js_asset['data']) . ";";
$element['#value_suffix'] = $embed_suffix;
break;
......
......@@ -84,7 +84,7 @@ public function buildByExtension($extension) {
}
foreach ($libraries as $id => &$library) {
if (!isset($library['js']) && !isset($library['css']) && !isset($library['settings'])) {
if (!isset($library['js']) && !isset($library['css']) && !isset($library['drupalSettings'])) {
throw new IncompleteLibraryDefinitionException(sprintf("Incomplete library definition for '%s' in %s", $id, $library_file));
}
$library += array('dependencies' => array(), 'js' => array(), 'css' => array());
......@@ -198,14 +198,6 @@ public function buildByExtension($extension) {
}
}
// @todo Introduce drupal_add_settings().
if (isset($library['settings'])) {
$library['js'][] = array(
'type' => 'setting',
'data' => $library['settings'],
);
unset($library['settings']);
}
// @todo Convert all uses of #attached[library][]=array('provider','name')
// into #attached[library][]='provider/name' and remove this.
foreach ($library['dependencies'] as $i => $dependency) {
......
......@@ -123,8 +123,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['#attached']['library'][] = 'core/drupal.timezone';
// We add these strings as settings because JavaScript translation does not
// work during installation.
$js = array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail')));
$form['#attached']['js'][] = array('data' => $js, 'type' => 'setting');
$form['#attached']['drupalSettings']['copyFieldValue']['edit-site-mail'] = ['edit-account-mail'];
// Cache a fully-built schema. This is necessary for any invocation of
// index.php because: (1) setting cache table entries requires schema
......
......@@ -163,17 +163,9 @@ public static function processMachineName(&$element, FormStateInterface $form_st
NestedArray::setValue($form_state->getCompleteForm(), $parents, $source['#field_suffix']);
}
$js_settings = array(
'type' => 'setting',
'data' => array(
'machineName' => array(
'#' . $source['#id'] => $element['#machine_name'],
),
'langcode' => $language->getId(),
),
);
$element['#attached']['library'][] = 'core/drupal.machine-name';
$element['#attached']['js'][] = $js_settings;
$element['#attached']['drupalSettings']['machineName']['#' . $source['#id']] = $element['#machine_name'];
$element['#attached']['drupalSettings']['langcode'] = $language->getId();
return $element;
}
......
......@@ -296,10 +296,7 @@ public static function preRenderAjaxForm($element) {
unset($settings['progress']['path']);
}
$element['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('ajax' => array($element['#id'] => $settings)),
);
$element['#attached']['drupalSettings']['ajax'][$element['#id']] = $settings;
// Indicate that Ajax processing was successful.
$element['#ajax_processed'] = TRUE;
......
......@@ -139,10 +139,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$placement = FALSE;
if ($this->request->query->has('block-placement')) {
$placement = $this->request->query->get('block-placement');
$form['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('blockPlacement' => $placement),
);
$form['#attached']['drupalSettings']['blockPlacement'] = $placement;
}
$entities = $this->load();
$form['#theme'] = array('block_list');
......
......@@ -59,17 +59,14 @@ public function demo($theme) {
'#title' => $this->themeHandler->getName($theme),
'#type' => 'page',
'#attached' => array(
'js' => array(
array(
// The block demonstration page is not marked as an administrative
// page by \Drupal::service('router.admin_context')->isAdminRoute()
// function in order to use the frontend theme. Since JavaScript
// relies on a proper separation of admin pages, it needs to know
// this is an actual administrative page.
'data' => array('path' => array('currentPathIsAdmin' => TRUE)),
'type' => 'setting',
)
),
'drupalSettings' => [
// The block demonstration page is not marked as an administrative
// page by \Drupal::service('router.admin_context')->isAdminRoute()
// function in order to use the frontend theme. Since JavaScript
// relies on a proper separation of admin pages, it needs to know this
// is an actual administrative page.
'path' => ['currentPathIsAdmin' => TRUE],
],
'library' => array(
'block/drupal.block.admin',
),
......
......@@ -140,14 +140,11 @@ public function settingsForm(array $form, FormStateInterface $form_state, Editor
'#type' => 'container',
'#attached' => array(
'library' => array('ckeditor/drupal.ckeditor.admin'),
'js' => array(
array(
'type' => 'setting',
'data' => array('ckeditor' => array(
'toolbarAdmin' => drupal_render($ckeditor_settings_toolbar),
)),
)
),
'drupalSettings' => [
'ckeditor' => [
'toolbarAdmin' => drupal_render($ckeditor_settings_toolbar),
],
],
),
'#attributes' => array('class' => array('ckeditor-toolbar-configuration')),
);
......@@ -218,14 +215,7 @@ public function settingsForm(array $form, FormStateInterface $form_state, Editor
$form['hidden_ckeditor'] = array(
'#markup' => '<div id="ckeditor-hidden" class="hidden"></div>',
'#attached' => array(
'js' => array(
array(
'type' => 'setting',
'data' => array('ckeditor' => array(
'hiddenCKEditorConfig' => $config,
)),
),
),
'drupalSettings' => ['ckeditor' => ['hiddenCKEditorConfig' => $config]],
),
);
......
......@@ -213,18 +213,13 @@ function color_scheme_form($complete_form, FormStateInterface $form_state, $them
'color/admin',
),
// Add custom JavaScript.
'js' => array(
array(
'data' => array(
'color' => array(
'reference' => color_get_palette($theme, TRUE),
'schemes' => $schemes,
),
'gradients' => $info['gradients'],
),
'type' => 'setting',
),
),
'drupalSettings' => [
'color' => [
'reference' => color_get_palette($theme, TRUE),
'schemes' => $schemes,
],
'gradients' => $info['gradients'],
],
),
);
......
......@@ -364,23 +364,16 @@ public static function attachNewCommentsLinkMetadata(array $element, array $cont
$query = $page_number ? array('page' => $page_number) : NULL;
// Attach metadata.
$element['#attached']['js'][] = array(
'type' => 'setting',
'data' => array(
'comment' => array(
'newCommentsLinks' => array(
$context['entity_type'] => array(
$context['field_name'] => array(
$context['entity_id'] => array(
'new_comment_count' => (int)$new,
'first_new_comment_link' => \Drupal::urlGenerator()->generateFromPath('node/' . $entity->id(), array('query' => $query, 'fragment' => 'new')),
)
)
),
)
),
),
);
$element['#attached']['drupalSettings']['comment']['newCommentsLinks'] = [
$context['entity_type'] => [
$context['field_name'] => [
$context['entity_id'] => [
'new_comment_count' => (int)$new,
'first_new_comment_link' => \Drupal::urlGenerator()->generateFromPath('node/' . $entity->id(), ['query' => $query, 'fragment' => 'new']),
],
],
],
];
return $element;
}
......
......@@ -52,9 +52,9 @@ function content_translation_field_sync_widget(FieldDefinitionInterface $field)
'library' => array(
'content_translation/drupal.content_translation.admin',
),
'js' => array(
array('data' => array('contentTranslationDependentOptions' => $settings), 'type' => 'setting'),
),
'drupalSettings' => [
'contentTranslationDependentOptions' => $settings,
],
),
);
}
......@@ -126,7 +126,7 @@ function _content_translation_form_language_content_settings_form_alter(array &$
}
$settings = array('dependent_selectors' => $dependent_options_settings);
$form['#attached']['js'][] = array('data' => array('contentTranslationDependentOptions' => $settings), 'type' => 'setting');
$form['#attached']['drupalSettings']['contentTranslationDependentOptions'] = $settings;
$form['#validate'][] = 'content_translation_form_language_content_settings_validate';
$form['#submit'][] = 'content_translation_form_language_content_settings_submit';
}
......
......@@ -96,10 +96,7 @@ public function getAttachments(array $format_ids) {
return array();
}
$attachments['js'][] = array(
'type' => 'setting',
'data' => $settings,
);
$attachments['drupalSettings'] = $settings;
return $attachments;
}
......
......@@ -90,27 +90,26 @@ public function testManager() {
'library' => array(
0 => 'editor_test/unicorn',
),
'js' => array(
0 => array(
'type' => 'setting',
'data' => array('editor' => array('formats' => array(
'full_html' => array(
'drupalSettings' => [
'editor' => [
'formats' => [
'full_html' => [
'format' => 'full_html',
'editor' => 'unicorn',
'editorSettings' => $unicorn_plugin->getJSSettings($editor),
'editorSupportsContentFiltering' => TRUE,
'isXssSafe' => FALSE,
)
)))
)
),
],
],
],
],
);
$this->assertIdentical($expected, $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'Correct attachments when one text editor is enabled and retrieving attachments for multiple text formats.');
// Case 4: a text editor available associated, but now with its JS settings
// being altered via hook_editor_js_settings_alter().
\Drupal::state()->set('editor_test_js_settings_alter_enabled', TRUE);
$expected['js'][0]['data']['editor']['formats']['full_html']['editorSettings']['ponyModeEnabled'] = FALSE;
$expected['drupalSettings']['editor']['formats']['full_html']['editorSettings']['ponyModeEnabled'] = FALSE;
$this->assertIdentical($expected, $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'hook_editor_js_settings_alter() works correctly.');
}
......
......@@ -210,10 +210,7 @@ public function tablePreRender($elements) {
$elements['#regions'][$region_name]['rows_order'] = array_reduce($trees[$region_name], array($this, 'reduceOrder'));
}
$elements['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('fieldUIRowsData' => $js_settings),
);
$elements['#attached']['drupalSettings']['fieldUIRowsData'] = $js_settings;
// If the custom #tabledrag is set and there is a HTML ID, add the table's
// HTML ID to the options and attach the behavior.
......
......@@ -81,7 +81,7 @@ public function upload(Request $request) {
$output = drupal_render($form);
drupal_process_attached($form);
$js = _drupal_add_js();
$settings = drupal_merge_js_settings($js['settings']['data']);
$settings = $js['drupalSettings']['data'];
$response = new AjaxResponse();
foreach ($commands as $command) {
......
......@@ -256,10 +256,7 @@ public static function processManagedFile(&$element, FormStateInterface $form_st
// Add the extension list to the page as JavaScript settings.
if (isset($element['#upload_validators']['file_validate_extensions'][0])) {
$extension_list = implode(',', array_filter(explode(' ', $element['#upload_validators']['file_validate_extensions'][0])));
$element['upload']['#attached']['js'] = [[
'type' => 'setting',
'data' => ['file' => ['elements' => ['#' . $element['#id'] => $extension_list]]],
]];
$element['upload']['#attached']['drupalSettings']['file']['elements']['#' . $element['#id']] = $extension_list;
}
// Prefix and suffix used for Ajax replacement.
......
......@@ -193,16 +193,7 @@ function history_user_delete($account) {
* The updated $element.
*/
function history_attach_timestamp(array $element, array $context) {
$element['#attached']['js'][] = array(
'type' => 'setting',
'data' => array(
'history' => array(
'lastReadTimestamps' => array(
$context['node_id'] => (int) history_read($context['node_id']),
)
),
),
);
$node_id = $context['node_id'];
$element['#attached']['drupalSettings']['history']['lastReadTimestamps'][$node_id] = (int) history_read($node_id);
return $element;
}
......@@ -535,14 +535,10 @@ function locale_library_alter(array &$library, $name) {
$library['dependencies'][] = 'locale/drupal.locale.datepicker';
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
$settings['jquery']['ui']['datepicker'] = array(
$library['drupalSettings']['jquery']['ui']['datepicker'] = array(
'isRTL' => $language_interface->getDirection() == LanguageInterface::DIRECTION_RTL,
'firstDay' => \Drupal::config('system.date')->get('first_day'),
);
$library['js'][] = array(
'type' => 'setting',
'data' => $settings,
);
}
}
......
......@@ -98,17 +98,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#title' => $this->t('Collapse'),
'#suffix' => '<a href="#" class="simpletest-collapse">(' . $this->t('Collapse') . ')</a>',
);
$form['tests']['#attached']['js'][] = array(
'type' => 'setting',
'data' => array(
'simpleTest' => array(
'images' => array(
drupal_render($image_collapsed),
drupal_render($image_extended),
),
),
),
);
$form['tests']['#attached']['drupalSettings']['simpleTest']['images'] = [
drupal_render($image_collapsed),
drupal_render($image_extended),
];
// Generate the list of tests arranged by group.
$groups = simpletest_test_get_all();
......
......@@ -1844,7 +1844,7 @@ protected function drupalProcessAjaxResponse($content, array $ajax_response, arr
}
switch ($command['command']) {
case 'settings':
$drupal_settings = drupal_merge_js_settings(array($drupal_settings, $command['settings']));
$drupal_settings = NestedArray::mergeDeepArray([$drupal_settings, $command['settings']], TRUE);
break;
case 'insert':
......
......@@ -40,10 +40,7 @@ function statistics_node_view(array &$build, EntityInterface $node, EntityViewDi
if (!$node->isNew() && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
$build['statistics_content_counter']['#attached']['library'][] = 'statistics/drupal.statistics';
$settings = array('data' => array('nid' => $node->id()), 'url' => _url(drupal_get_path('module', 'statistics') . '/statistics.php'));
$build['statistics_content_counter']['#attached']['js'][] = array(
'data' => array('statistics' => $settings),
'type' => 'setting',
);
$build['statistics_content_counter']['#attached']['drupalSettings']['statistics'] = $settings;
}
}
......
......@@ -118,10 +118,6 @@ function testAjaxCommands() {
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'settings' command")));
$expected = new SettingsCommand(array('ajax_forms_test' => array('foo' => 42)));
$this->assertCommand($commands, $expected->render(), "'settings' AJAX command issued with correct data.");
// Test that the settings command merges settings properly.
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'settings' command with setting merging")));
$expected = new SettingsCommand(array('ajax_forms_test' => array('foo' => 9001)), TRUE);
$this->assertCommand($commands, $expected->render(), "'settings' AJAX command with setting merging.");
}
}
......@@ -77,16 +77,14 @@ function testAddFile() {
*/
function testAddSetting() {
// Add a file in order to test default settings.
$attached['#attached']['library'][] = 'core/drupalSettings';
$this->render($attached);
$build['#attached']['library'][] = 'core/drupalSettings';
drupal_process_attached($build);
$javascript = _drupal_add_js();
$last_settings = reset($javascript['settings']['data']);
$this->assertTrue(array_key_exists('currentPath', $last_settings['path']), 'The current path JavaScript setting is set correctly.');
$this->assertTrue(array_key_exists('currentPath', $javascript['drupalSettings']['data']['path']), 'The current path JavaScript setting is set correctly.');
$javascript = _drupal_add_js(array('drupal' => 'rocks', 'dries' => 280342800), 'setting');
$last_settings = end($javascript['settings']['data']);
$this->assertEqual(280342800, $last_settings['dries'], 'JavaScript setting is set correctly.');
$this->assertEqual('rocks', $last_settings['drupal'], 'The other JavaScript setting is set correctly.');
$this->assertEqual(280342800, $javascript['drupalSettings']['data']['dries'], 'JavaScript setting is set correctly.');
$this->assertEqual('rocks', $javascript['drupalSettings']['data']['drupal'], 'The other JavaScript setting is set correctly.');
}
/**
......@@ -156,81 +154,11 @@ function testAggregatedAttributes() {
function testHeaderSetting() {
$attached = array();
$attached['#attached']['library'][] = 'core/drupalSettings';
// Nonsensical value to verify if it's possible to override path settings.
$attached['#attached']['drupalSettings']['path']['pathPrefix'] = 'yarhar';
$this->render($attached);
$javascript = drupal_get_js('header');
$this->assertTrue(strpos($javascript, 'baseUrl') > 0, 'Rendered JavaScript header returns baseUrl setting.');
$this->assertTrue(strpos($javascript, 'scriptPath') > 0, 'Rendered JavaScript header returns scriptPath setting.');
$this->assertTrue(strpos($javascript, 'pathPrefix') > 0, 'Rendered JavaScript header returns pathPrefix setting.');
$this->assertTrue(strpos($javascript, 'currentPath') > 0, 'Rendered JavaScript header returns currentPath setting.');
// Only the second of these two entries should appear in drupalSettings.
$attached = array();
$attached['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('commonTest' => 'commonTestShouldNotAppear'),
);
$attached['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('commonTest' => 'commonTestShouldAppear'),
);
// Only the second of these entries should appear in drupalSettings.
$attached['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('commonTestJsArrayLiteral' => array('commonTestJsArrayLiteralOldValue')),
);
$attached['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('commonTestJsArrayLiteral' => array('commonTestJsArrayLiteralNewValue')),
);
// Only the second of these two entries should appear in drupalSettings.
$attached['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('commonTestJsObjectLiteral' => array('key' => 'commonTestJsObjectLiteralOldValue')),
);
$attached['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('commonTestJsObjectLiteral' => array('key' => 'commonTestJsObjectLiteralNewValue')),
);
// Real world test case: multiple elements in a render array are adding the
// same (or nearly the same) JavaScript settings. When merged, they should
// contain all settings and not duplicate some settings.
$settings_one = array('moduleName' => array('ui' => array('button A', 'button B'), 'magical flag' => 3.14159265359));
$attached['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('commonTestRealWorldIdentical' => $settings_one),
);
$attached['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('commonTestRealWorldIdentical' => $settings_one),
);
$settings_two = array('moduleName' => array('ui' => array('button A', 'button B'), 'magical flag' => 3.14159265359, 'thingiesOnPage' => array('id1' => array())));
$attached['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('commonTestRealWorldAlmostIdentical' => $settings_two),
);
$settings_two = array('moduleName' => array('ui' => array('button C', 'button D'), 'magical flag' => 3.14, 'thingiesOnPage' => array('id2' => array())));
$attached['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('commonTestRealWorldAlmostIdentical' => $settings_two),
);
$this->render($attached);
$javascript = drupal_get_js('header');
// Test whether _drupal_add_js can be used to override a previous setting.
$this->assertTrue(strpos($javascript, 'commonTestShouldAppear') > 0, 'Rendered JavaScript header returns custom setting.');
$this->assertTrue(strpos($javascript, 'commonTestShouldNotAppear') === FALSE, '_drupal_add_js() correctly overrides a custom setting.');
// Test whether _drupal_add_js can be used to add and override a JavaScript
// array literal (an indexed PHP array) values.
$array_override = strpos($javascript, 'commonTestJsArrayLiteralNewValue') > 0 && strpos($javascript, 'commonTestJsArrayLiteralOldValue') === FALSE;
$this->assertTrue($array_override, '_drupal_add_js() correctly overrides settings within an array literal (indexed array).');
// Test whether _drupal_add_js can be used to add and override a JavaScript
// object literal (an associate PHP array) values.
$associative_array_override = strpos($javascript, 'commonTestJsObjectLiteralNewValue') > 0 && strpos($javascript, 'commonTestJsObjectLiteralOldValue') === FALSE;
$this->assertTrue($associative_array_override, '_drupal_add_js() correctly overrides settings within an object literal (associative array).');
// Parse the generated drupalSettings <script> back to a PHP representation.
$startToken = 'drupalSettings = ';
......@@ -240,10 +168,20 @@ function testHeaderSetting() {
$json = Unicode::substr($javascript, $start, $end - $start + 1);
$parsed_settings = Json::decode($json);
// Test whether the two real world cases are handled correctly.
$settings_two['moduleName']['thingiesOnPage']['id1'] = array();
$this->assertIdentical($settings_one, $parsed_settings['commonTestRealWorldIdentical'], '_drupal_add_js handled real world test case 1 correctly.');
$this->assertEqual($settings_two, $parsed_settings['commonTestRealWorldAlmostIdentical'], '_drupal_add_js handled real world test case 2 correctly.');
// Test whether the settings for core/drupalSettings are available.
$this->assertTrue(isset($parsed_settings['path']['baseUrl']), 'drupalSettings.path.baseUrl is present.');
$this->assertTrue(isset($parsed_settings['path']['scriptPath']), 'drupalSettings.path.scriptPath is present.');
$this->assertIdentical($parsed_settings['path']['pathPrefix'], 'yarhar', 'drupalSettings.path.pathPrefix is present and has the correct (overridden) value.');
$this->assertIdentical($parsed_settings['path']['currentPath'], '', 'drupalSettings.path.currentPath is present and has the correct value.');
$this->assertIdentical($parsed_settings['path']['currentPathIsAdmin'], FALSE, 'drupalSettings.path.currentPathIsAdmin is present and has the correct value.');
$this->assertIdentical($parsed_settings['path']['isFront'], FALSE, 'drupalSettings.path.isFront is present and has the correct value.');
$this->assertIdentical($parsed_settings['path']['currentLanguage'], 'en', 'drupalSettings.path.currentLanguage is present and has the correct value.');
// Tests whether altering JavaScript settings via hook_js_settings_alter()
// is working as expected.
// @see common_test_js_settings_alter()
$this->assertIdentical($parsed_settings['locale']['pluralDelimiter'], '☃');
$this->assertIdentical($parsed_settings['foo'], 'bar');
}
/**
......
......@@ -12,6 +12,8 @@
/**
* Tests the merging of attachments.
*
* @see drupal_merge_attached()
*
* @group Common
*/
class MergeAttachmentsTest extends DrupalUnitTestBase {
......@@ -165,36 +167,30 @@ function testJsSettingMerging() {
$a['#attached'] = array(
'js' => array(
'foo.js' => array(),
array(
'type' => 'setting',
'data' => array('foo' => array('d')),
),
'bar.js' => array(),
),
'drupalSettings' => [
'foo' => ['d'],
],
);
$b['#attached'] = array(
'js' => array(
83 => array(
'type' => 'setting',
'data' => array('bar' => array('a', 'b', 'c')),
),
'baz.js' => array(),
),
'drupalSettings' => [
'bar' => ['a', 'b', 'c'],
],
);
$expected['#attached'] = array(
'js' => array(
'foo.js' => array(),
0 => array(
'type' => 'setting',
'data' => array('foo' => array('d')),
),
'bar.js' => array(),
1 =>