diff --git a/core/modules/system/lib/Drupal/system/Tests/Ajax/CommandsTest.php b/core/modules/system/lib/Drupal/system/Tests/Ajax/CommandsTest.php
index faa35bb..e6977f6 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Ajax/CommandsTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/CommandsTest.php
@@ -158,6 +158,14 @@ class CommandsTest extends AjaxTestBase {
     );
     $this->assertCommand($commands, $expected, "'settings' AJAX command issued with correct data");
 
+     // Test that the settings command merges settings properly.
+     $commands = $this->drupalPostAJAX($form_path, $edit, array('op' => t("AJAX 'settings' command with setting merging")));
+     $expected = array(
+       'command' => 'settings',
+       'settings' => array('ajax_forms_test' => array('foo' => 9001)),
+     );
+     $this->assertCommand($commands, $expected, "'settings' AJAX command with setting merging");
+
     // Tests the 'add_css' command.
     $commands = $this->drupalPostAJAX($form_path, $edit, array('op' => t("AJAX 'add_css' command")));
     $expected = array(
diff --git a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
index d4074d1..9f99b00 100644
--- a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
+++ b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
@@ -267,6 +267,18 @@ function ajax_forms_test_ajax_commands_form($form, &$form_state) {
     ),
   );
 
+  // Tests the 'settings' command with a callback which sets the same
+  // setting multiple times. This is used to check that settings are
+  // merged properly (e.g., array_merge_recursive() merges settings
+  // incorrectly, #1356170).
+  $form['settings_command_with_merging_example'] = array(
+    '#type' => 'submit',
+    '#value' => t("AJAX 'settings' command with setting merging"),
+    '#ajax' => array(
+      'callback' => 'ajax_forms_test_advanced_commands_settings_with_merging_callback',
+    ),
+  );
+
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit'),
@@ -428,6 +440,17 @@ function ajax_forms_test_advanced_commands_add_css_callback($form, $form_state)
   return array('#type' => 'ajax', '#commands' => $commands);
 }
 
+
+/**
+ * Ajax callback for 'settings' but with setting overrides.
+ */
+function ajax_forms_test_advanced_commands_settings_with_merging_callback($form, $form_state) {
+  drupal_add_js(array('ajax_forms_test' => array('foo' => 42)), 'setting');
+  drupal_add_js(array('ajax_forms_test' => array('foo' => 9001)), 'setting');
+
+  return array('#type' => 'ajax', '#commands' => array());
+}
+
 /**
  * This form and its related submit and callback functions demonstrate
  * not validating another form element when a single Ajax element is triggered.
