From 06e97452cdd34a4a048947bac92d28f111a1fdd8 Mon Sep 17 00:00:00 2001
From: Christina Lee <christina.lee@nbcuni.com>
Date: Wed, 16 Sep 2015 16:11:21 -0400
Subject: [PATCH] Dependent module cannot be installed when a parent module
 fails hook_requirements().

---
 modules/simpletest/tests/requirements3_test.info    |  7 +++++++
 modules/simpletest/tests/requirements3_test.install | 21 +++++++++++++++++++++
 modules/simpletest/tests/requirements3_test.module  |  7 +++++++
 modules/simpletest/tests/system_test.module         |  2 +-
 modules/system/system.admin.inc                     |  3 +++
 modules/system/system.test                          | 18 ++++++++++++++++++
 6 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 modules/simpletest/tests/requirements3_test.info
 create mode 100644 modules/simpletest/tests/requirements3_test.install
 create mode 100644 modules/simpletest/tests/requirements3_test.module

diff --git a/modules/simpletest/tests/requirements3_test.info b/modules/simpletest/tests/requirements3_test.info
new file mode 100644
index 0000000..dfe715b
--- /dev/null
+++ b/modules/simpletest/tests/requirements3_test.info
@@ -0,0 +1,7 @@
+name = Requirements 3 Test
+description = "Tests that a dependent module is not installed when its parent module fails hook_requirements('install')."
+dependencies[] = requirements2_test
+package = Testing
+version = VERSION
+core = 7.x
+hidden = TRUE
\ No newline at end of file
diff --git a/modules/simpletest/tests/requirements3_test.install b/modules/simpletest/tests/requirements3_test.install
new file mode 100644
index 0000000..2487b62
--- /dev/null
+++ b/modules/simpletest/tests/requirements3_test.install
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Implements hook_requirements().
+ */
+function requirements3_test_requirements($phase) {
+  $requirements = array();
+  // Ensure translations don't break during installation.
+  $t = get_t();
+
+  // Always fails requirements.
+  if ('install' == $phase) {
+    $requirements['requirements3_test'] = array(
+      'title' => $t('Requirements 3 Test'),
+      'severity' => REQUIREMENT_ERROR,
+      'description' => $t('Requirements 3 Test failed requirements.'),
+    );
+  }
+
+  return $requirements;
+}
\ No newline at end of file
diff --git a/modules/simpletest/tests/requirements3_test.module b/modules/simpletest/tests/requirements3_test.module
new file mode 100644
index 0000000..7270a8e
--- /dev/null
+++ b/modules/simpletest/tests/requirements3_test.module
@@ -0,0 +1,7 @@
+<?php
+
+/**
+ * @file
+ * Tests that a dependent module is not installed when its parent module fails
+ * hook_requirements('install').
+ */
\ No newline at end of file
diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module
index 8c44329..265da8b 100644
--- a/modules/simpletest/tests/system_test.module
+++ b/modules/simpletest/tests/system_test.module
@@ -308,7 +308,7 @@ function system_test_system_info_alter(&$info, $file, $type) {
   ))) {
     $info['hidden'] = FALSE;
   }
-  if ($file->name == 'requirements1_test' || $file->name == 'requirements2_test') {
+  if ($file->name == 'requirements1_test' || $file->name == 'requirements2_test' || $file->name == 'requirements3_test') {
     $info['hidden'] = FALSE;
   }
 }
diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc
index 0f525c6..e059b73 100644
--- a/modules/system/system.admin.inc
+++ b/modules/system/system.admin.inc
@@ -1188,6 +1188,9 @@ function system_modules_submit($form, &$form_state) {
         foreach (array_keys($files[$name]->required_by) as $required_by) {
           $modules[$required_by]['enabled'] = FALSE;
         }
+        foreach (array_keys($files[$name]->requires) as $requires) {
+          $modules[$requires]['enabled'] = FALSE;
+        }
       }
     }
   }
diff --git a/modules/system/system.test b/modules/system/system.test
index d4c98f0..5b9b028 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -375,6 +375,24 @@ class HookRequirementsTestCase extends ModuleTestCase {
     $this->assertText(t('Requirements 1 Test failed requirements'), 'Modules status has been updated.');
     $this->assertModules(array('requirements1_test'), FALSE);
   }
+
+  /**
+   * Assert that a dependent module cannot be installed when a parent module fails hook_requirements().
+   */
+  function testHookRequirements2Failure() {
+    // Attempt to install the requirements3_test module.
+    $edit = array();
+    $edit['modules[Testing][requirements3_test][enable]'] = 'requirements3_test';
+    $this->drupalPost('admin/modules', $edit, t('Save configuration'));
+
+    // Attempt to install dependent module, requirements2_test.
+    $this->assertText(t('Some required modules must be enabled'), 'Dependency required.');
+    $this->drupalPost(NULL, NULL, t('Continue'));
+    $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
+
+    // Make sure both modules are not installed.
+    $this->assertModules(array('requirements2_test', 'requirements3_test'), FALSE);
+  }
 }
 
 /**
-- 
2.3.2 (Apple Git-55)

