Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.209
diff -u -p -r1.209 module.inc
--- includes/module.inc	27 Nov 2010 20:41:38 -0000	1.209
+++ includes/module.inc	3 Feb 2011 04:58:56 -0000
@@ -372,7 +372,7 @@ function module_enable($module_list, $en
 
       // Add dependencies to the list, with a placeholder weight.
       // The new modules will be processed as the while loop continues.
-      foreach ($module_data[$module]->info['dependencies'] as $dependency) {
+      foreach (array_keys($module_data[$module]->requires) as $dependency) {
         if (!isset($module_list[$dependency])) {
           $module_list[$dependency] = 0;
         }
Index: modules/simpletest/tests/module.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/module.test,v
retrieving revision 1.26
diff -u -p -r1.26 module.test
--- modules/simpletest/tests/module.test	27 Nov 2010 20:41:38 -0000	1.26
+++ modules/simpletest/tests/module.test	3 Feb 2011 04:58:56 -0000
@@ -212,6 +212,27 @@ class ModuleUnitTest extends DrupalWebTe
     $uninstalled_modules = variable_get('test_module_uninstall_order', array());
     $this->assertTrue(in_array('comment', $uninstalled_modules), t('Comment module is in the list of uninstalled modules.'));
     $this->assertFalse(in_array($profile, $uninstalled_modules), t('The installation profile is not in the list of uninstalled modules.'));
+
+    // Enable forum module again, which should enable both the poll module and
+    // php module. But, this time do it with poll module declaring a dependency
+    // on a specific version of php module in its info file. Make sure that
+    // module_enable() still works.
+    variable_set('dependency_test', 'version dependency');
+    drupal_static_reset('system_rebuild_module_data');
+    $result = module_enable(array('forum'));
+    $this->assertTrue($result, t('module_enable() returns the correct value.'));
+    // Verify that the fake dependency chain was installed.
+    $this->assertTrue(module_exists('poll') && module_exists('php'), t('Dependency chain was installed by module_enable().'));
+    // Verify that the original module was installed.
+    $this->assertTrue(module_exists('forum'), t('Module installation with version dependencies succeeded.'));
+    // Finally, verify that the modules were enabled in the correct order.
+    $enable_order = variable_get('test_module_enable_order', array());
+    $php_position = array_search('php', $enable_order);
+    $poll_position = array_search('poll', $enable_order);
+    $forum_position = array_search('forum', $enable_order);
+    $php_before_poll = $php_position !== FALSE && $poll_position !== FALSE && $php_position < $poll_position;
+    $poll_before_forum = $poll_position !== FALSE && $forum_position !== FALSE && $poll_position < $forum_position;
+    $this->assertTrue($php_before_poll && $poll_before_forum, t('Modules were enabled in the correct order by module_enable().'));
   }
 }
 
Index: modules/simpletest/tests/module_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/module_test.module,v
retrieving revision 1.10
diff -u -p -r1.10 module_test.module
--- modules/simpletest/tests/module_test.module	27 Nov 2010 20:41:38 -0000	1.10
+++ modules/simpletest/tests/module_test.module	3 Feb 2011 04:58:56 -0000
@@ -36,6 +36,20 @@ function module_test_system_info_alter(&
       $info['dependencies'][] = 'php';
     }
   }
+  elseif (variable_get('dependency_test', FALSE) == 'version dependency') {
+    if ($file->name == 'forum') {
+      // Make the forum module depend on poll.
+      $info['dependencies'][] = 'poll';
+    }
+    elseif ($file->name == 'poll') {
+      // Make poll depend on a specific version of php module.
+      $info['dependencies'][] = 'php (1.x)';
+    }
+    elseif ($file->name == 'php') {
+      // Set php module to a version compatible with the above.
+      $info['version'] = '7.x-1.0';
+    }
+  }
   if ($file->name == 'seven' && $type == 'theme') {
     $info['regions']['test_region'] = t('Test region');
   }
