? diff.patch
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1279
diff -u -p -r1.1279 common.inc
--- includes/common.inc	21 Dec 2010 19:16:31 -0000	1.1279
+++ includes/common.inc	24 Dec 2010 09:43:41 -0000
@@ -6948,6 +6948,34 @@ function drupal_parse_info_format($data)
   return $info;
 }
 
+
+/**
+ * Gernerates an info file that can be parsed by drupal_parse_info_file.
+ * @param array $array
+ *   What is returned from drupal_parse_info_file().
+ * @param string $prefix
+ *   A string to prefix each entry with, should be used only by the function itself
+ *   during recursion.
+ *
+ * @return string
+ *   A string corresponding to $array in the info format. If written into a file, it can be parsed back by drupal_parse_info_file
+ *
+ */
+function drupal_build_info_file($array, $prefix = false) {
+  $info = '';
+  foreach ($array as $key => $value) {
+    if (is_array($value)) {
+      $info .= drupal_build_info_file($value, (!$prefix ? $key : "{$prefix}[{$key}]" ));
+    }
+    else {
+      $info .= $prefix ? ("{$prefix}[" . (is_int($key) ? '' : $key) .']') : $key;
+      $info .= " = '" . str_replace("'", "\'", $value) . "'\n";
+    }
+  }
+  return $info;
+}
+
+
 /**
  * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
  *
Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.138
diff -u -p -r1.138 common.test
--- modules/simpletest/tests/common.test	15 Dec 2010 04:21:39 -0000	1.138
+++ modules/simpletest/tests/common.test	24 Dec 2010 09:43:43 -0000
@@ -2020,6 +2020,28 @@ class ParseInfoFilesTestCase extends Dru
 }
 
 /**
+ * Test the drupal_build_info_file() API function.
+ */
+class BuildInfoFilesTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Generating .info files',
+      'description' => 'Tests generating .info files.',
+      'group' => 'System',
+    );
+  }
+
+  /**
+   * Parse an example .info file, generate the content of the .info back and check if the result of its parsing is equal to the originally parsed file.
+   */
+  function testGenerateInfoFile() {
+    $info_values = drupal_parse_info_file(drupal_get_path('module', 'simpletest') . '/tests/common_test_info.txt');
+    $generated_info_values = drupal_parse_info_format(drupal_build_info_file($info_values)); // Generate the .info string and parse it back
+    $this->assertEqual($info_values, $generated_info_values, t('The automatically generated .info string is parsed as the original one.'), t('System'));
+  }
+}
+
+/**
  * Tests for the drupal_system_listing() function.
  */
 class DrupalSystemListingTestCase extends DrupalWebTestCase {
Index: modules/simpletest/tests/common_test_info.txt
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common_test_info.txt,v
retrieving revision 1.2
diff -u -p -r1.2 common_test_info.txt
--- modules/simpletest/tests/common_test_info.txt	30 Jan 2010 07:59:25 -0000	1.2
+++ modules/simpletest/tests/common_test_info.txt	24 Dec 2010 09:43:43 -0000
@@ -8,3 +8,9 @@ simple_constant = WATCHDOG_INFO
 ; After parsing the .info file, 'double_colon' should hold the literal value.
 ; Parsing should not throw a fatal error or try to access a class constant.
 double_colon = dummyClassName::
+
+; Test for arrays
+key[] = "numeric array"
+key[index] = "associative array"
+key[index][] = "nested numeric array"
+key[index][index] = "nested associative array"
