From d6d12c76b21003f66acd892ffc475c8d1ebf6960 Mon Sep 17 00:00:00 2001
From: Mariano D'Agostino <dagmar@154086.no-reply.drupal.org>
Date: Wed, 25 Jul 2012 17:38:03 -0300
Subject: [PATCH] Issue #1698428: Notices in Migrate interface

---
 configuration.admin.inc  |   26 ++++++++++++++++++------
 configuration.export.inc |    8 ++++++--
 tests/configuration.test |   49 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/configuration.admin.inc b/configuration.admin.inc
index e7c7a10..b36df71 100644
--- a/configuration.admin.inc
+++ b/configuration.admin.inc
@@ -780,7 +780,7 @@ function configuration_diff($component, $identifier) {
           // arrays through the Diff constructor above may not find difference.
           // This is creating FALSE positives and marking configs as not in
           // sync. If the diff system doesn't see a difference, set the status
-          // to CONFIFURATION_IN_SYNC.
+          // to CONFIGURATION_IN_SYNC.
           drupal_set_message(t('Configuration is in sync.'));
           configuration_set_status($component, $identifier, CONFIGURATION_IN_SYNC);
           cache_clear_all('config_export', 'cache');
@@ -813,12 +813,23 @@ function configuration_download_config($configs = NULL) {
   module_load_include('inc', 'configuration', 'configuration.export');
 
   if ($configs) {
+    configuration_include();
+
     // Only set the configurations that were checked to be passed to the
     // configuration_populate function.
     foreach ($configs as $component => $config) {
       foreach ($config as $name => $on) {
         if ($on) {
-          $c[$component][$name] = 1;
+          if (!empty($all_config[$component][$name])) {
+            $c[$component][$name] = $all_config[$component][$name];
+          }
+          else {
+            $function = "configuration_hash_{$component}";
+            $hash =  $function($name);
+            $c[$component][$name]['hash'] = $hash;
+            $c[$component][$name]['status'] = CONFIGURATION_IN_SYNC;
+            $c[$component][$name]['parent'] = '';
+          }
         }
       }
     }
@@ -835,10 +846,13 @@ function configuration_download_config($configs = NULL) {
 
   // Configs passed in by migrate function
   if ($configs) {
-    foreach ($export['configuration_dependency']['configuration'] as $component => $config) {
-      foreach ($config as $name => $parent) {
-        $c[$component][$name]['status'] = CONFIGURATION_DATASTORE_ONLY;
-        $c[$component][$name]['parent'] = $parent;
+    // Check if there is dependencies to export.
+    if (!empty($export['configuration_dependency'])) {
+      foreach ($export['configuration_dependency']['configuration'] as $component => $config) {
+        foreach ($config as $name => $parent) {
+          $c[$component][$name]['status'] = CONFIGURATION_DATASTORE_ONLY;
+          $c[$component][$name]['parent'] = $parent;
+        }
       }
     }
     configuration_write_export_file($c, "temporary://config.export");
diff --git a/configuration.export.inc b/configuration.export.inc
index 5b6cc2a..d50a84f 100644
--- a/configuration.export.inc
+++ b/configuration.export.inc
@@ -818,9 +818,13 @@ function configuration_write_export_file($config = NULL, $dest = NULL) {
     if (is_array($component)) {
       foreach ($component as $name => $settings) {
         fwrite($h, 'config[' . $owner . '][' . $name . '][status] = ' . $settings['status'] . "\n");
-        fwrite($h, 'config[' . $owner . '][' . $name . '][hash] = \'' . $settings['hash'] . "'\n");
+        if (!empty($settings['hash'])) {
+          fwrite($h, 'config[' . $owner . '][' . $name . '][hash] = \'' . $settings['hash'] . "'\n");
+        }
         fwrite($h, 'config[' . $owner . '][' . $name . '][parent] = \'' . $settings['parent'] . "'\n");
-        fwrite($h, 'config[' . $owner . '][' . $name . '][dependencies] = \'' . $settings['dependencies'] . "'\n\n");
+        if (!empty($settings['dependencies'])) {
+          fwrite($h, 'config[' . $owner . '][' . $name . '][dependencies] = \'' . $settings['dependencies'] . "'\n\n");
+        }
       }
     }
   }
diff --git a/tests/configuration.test b/tests/configuration.test
index ca94eda..432bf0f 100644
--- a/tests/configuration.test
+++ b/tests/configuration.test
@@ -383,6 +383,55 @@ class ConfigurationUITest extends ConfigurationWebTestCase {
   }
 
   /**
+   * Tests the "Migrate Export" page.
+   */
+  public function testMigrateExportUI() {
+    module_load_include('inc', 'configuration', 'configuration.admin');
+
+    // The purpose of this test is check that no notices are displayed
+    // while exporting configuration.
+
+    $edit = array();
+    // Select all the available components that are available in the UI
+    $components = configuration_get_components();
+    foreach ($components as $component => $component_info) {
+      if ($component != 'menu_links') {
+        $options = configuration_invoke($component, 'configuration_export_options');
+        if (!empty($options)) {
+          foreach (configuration_dom_encode_options($options) as $identifier => $value)
+          $edit[$component . '[items][' . $identifier . ']'] = TRUE;
+        }
+      }
+    }
+    $this->drupalPost('admin/config/system/configuration/migrate', $edit, t('Download Configurations'));
+
+    // Migrate a components that don't have dependencies
+    $edit = array();
+    $edit['filter[items][filtered_html]'] = TRUE;
+    $this->drupalPost('admin/config/system/configuration/migrate', $edit, t('Download Configurations'));
+
+    // Migrate an overriden component
+    $this->trackConfigurations();
+    $edit = array();
+    $edit["filters[filter_url][settings][filter_url_length]"] = 20;
+    $this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
+    $edit = array();
+    $edit['filter[items][filtered_html]'] = TRUE;
+    $this->drupalPost('admin/config/system/configuration/migrate', $edit, t('Download Configurations'));
+
+    // Migrate two components. One overriden and other in sync.
+    $edit = array();
+    $edit['filter[items][filtered_html]'] = TRUE;
+    $edit['filter[items][plain_text]'] = TRUE;
+    $this->drupalPost('admin/config/system/configuration/migrate', $edit, t('Download Configurations'));
+
+    // Try to submit the UI without selecting any component
+    $edit = array();
+    $this->drupalPost('admin/config/system/configuration/migrate', $edit, t('Download Configurations'));
+    $this->assertRaw(t('Please choose at least one configuration.'));
+  }
+
+  /**
    * Tests the "stop tracking" page.
    */
   public function testStopTrackingUI() {
-- 
1.7.10

