diff --git a/core/includes/schema.inc b/core/includes/schema.inc
index f46739c..aab8f8a 100644
--- a/core/includes/schema.inc
+++ b/core/includes/schema.inc
@@ -66,9 +66,9 @@ function drupal_get_schema($table = NULL, $rebuild = FALSE) {
  *   If TRUE, the schema will be rebuilt instead of retrieved from the cache.
  */
 function drupal_get_complete_schema($rebuild = FALSE) {
-  static $schema = array();
+  static $schema;
 
-  if (empty($schema) || $rebuild) {
+  if (!isset($schema) || $rebuild) {
     // Try to load the schema from cache.
     if (!$rebuild && $cached = cache()->get('schema')) {
       $schema = $cached->data;
@@ -100,15 +100,15 @@ function drupal_get_complete_schema($rebuild = FALSE) {
         _drupal_schema_initialize($current, $module);
         $schema = array_merge($schema, $current);
       }
-
       drupal_alter('schema', $schema);
+
+      if ($rebuild) {
+        cache()->invalidateTags(array('schema' => TRUE));
+      }
       // If the schema is empty, avoid saving it: some database engines require
       // the schema to perform queries, and this could lead to infinite loops.
       if (!empty($schema) && (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL)) {
-        cache()->set('schema', $schema);
-      }
-      if ($rebuild) {
-        cache()->invalidateTags(array('schema' => TRUE));
+        cache()->set('schema', $schema, CacheBackendInterface::CACHE_PERMANENT, array('schema' => TRUE));
       }
     }
   }
@@ -284,8 +284,11 @@ function drupal_get_schema_unprocessed($module, $table = NULL) {
   module_load_install($module);
   $schema = module_invoke($module, 'schema');
 
-  if (isset($table) && isset($schema[$table])) {
-    return $schema[$table];
+  if (isset($table)) {
+    if (isset($schema[$table])) {
+      return $schema[$table];
+    }
+    return array();
   }
   elseif (!empty($schema)) {
     return $schema;
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
index a21d496..f1ba201 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
@@ -117,10 +117,28 @@ protected function setUp() {
    *   The name of the table to install.
    */
   protected function installSchema($module, $table) {
-    require_once DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$module.install";
-    $function = $module . '_schema';
-    $schema = $function();
-    Database::getConnection()->schema()->createTable($table, $schema[$table]);
+    // drupal_get_schema_unprocessed() is technically able to install a schema
+    // of a non-enabled module, but its ability to load the module's .install
+    // file depends on many other factors. To prevent differences in test
+    // behavior and non-reproducible test failures, we only allow the schema of
+    // explicitly loaded/enabled modules to be installed.
+    if (!module_exists($module)) {
+      throw new \RuntimeException(format_string("'@module' module is not enabled.", array(
+        '@module' => $module,
+      )));
+    }
+    $schema = drupal_get_schema_unprocessed($module, $table);
+    if (empty($schema)) {
+      throw new \RuntimeException(format_string("Unable to retrieve '@module' module schema for '@table' table.", array(
+        '@module' => $module,
+        '@table' => $table,
+      )));
+    }
+    Database::getConnection()->schema()->createTable($table, $schema);
+    // We need to refresh the schema cache, as any call to drupal_get_schema()
+    // would not know of/return the schema otherwise.
+    // @todo Very expensive. Refactor the Schema API to make this obsolete.
+    drupal_get_schema(NULL, TRUE);
   }
 
   /**
@@ -132,7 +150,8 @@ protected function installSchema($module, $table) {
    * has no effect, since we are operating with a fixed module list.
    *
    * @param array $modules
-   *   A list of modules to enable.
+   *   A list of modules to enable. Dependencies are not resolved; i.e.,
+   *   multiple modules have to be specified with dependent modules first.
    * @param bool $install
    *   (optional) Whether to install the list of modules via module_enable().
    *   Defaults to TRUE. If FALSE, the new modules are only added to the fixed
@@ -150,11 +169,13 @@ protected function enableModules(array $modules, $install = TRUE) {
 
     // Call module_enable() to enable (install) the new modules.
     if ($install) {
-      module_enable($modules);
+      module_enable($modules, FALSE);
     }
     // Otherwise, only ensure that the new modules are loaded.
     else {
       module_load_all(FALSE, TRUE);
+      module_implements_reset();
     }
   }
+
 }
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
new file mode 100644
index 0000000..ff8f72e
--- /dev/null
+++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
@@ -0,0 +1,145 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\simpletest\Tests\DrupalUnitTestBaseTest.
+ */
+
+namespace Drupal\simpletest\Tests;
+
+use Drupal\simpletest\DrupalUnitTestBase;
+
+/**
+ * Tests DrupalUnitTestBase functionality.
+ */
+class DrupalUnitTestBaseTest extends DrupalUnitTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('entity_test');
+
+  public static function getInfo() {
+    return array(
+      'name' => 'DrupalUnitTestBase',
+      'description' => 'Tests DrupalUnitTestBase functionality.',
+      'group' => 'SimpleTest',
+    );
+  }
+
+  /**
+   * Tests expected behavior of setUp().
+   */
+  function testSetUp() {
+    $module = 'entity_test';
+    // Verify that specified $modules have been loaded.
+    $this->assertTrue(function_exists('entity_test_permission'), "$module.module was loaded.");
+    // Verify that there is a fixed module list.
+    $this->assertIdentical(module_list(), array($module => $module));
+    $this->assertIdentical(module_implements('permission'), array($module));
+    // Verify that no modules have been installed.
+    $this->assertFalse(db_table_exists($module), "'$module' database table not found.");
+  }
+
+  /**
+   * Tests expected load behavior of enableModules().
+   */
+  function testEnableModulesLoad() {
+    $module = 'field_test';
+
+    // Verify that the module does not exist yet.
+    $this->assertFalse(module_exists($module), "$module module not found.");
+    $list = module_list();
+    $this->assertFalse(in_array($module, $list), "$module module in module_list() not found.");
+    $list = module_list('permission');
+    $this->assertFalse(in_array($module, $list), "{$module}_permission() in module_implements() not found.");
+
+    // Enable the module.
+    $this->enableModules(array($module), FALSE);
+
+    // Verify that the module does not exist yet.
+    $this->assertTrue(module_exists($module), "$module module found.");
+    $list = module_list();
+    $this->assertTrue(in_array($module, $list), "$module module in module_list() found.");
+    $list = module_list('permission');
+    $this->assertTrue(in_array($module, $list), "{$module}_permission() in module_implements() found.");
+  }
+
+  /**
+   * Tests expected installation behavior of enableModules().
+   */
+  function testEnableModulesInstall() {
+    $module = 'filter';
+    $table = 'filter';
+
+    // @todo Heh. Remove after configuration system conversion.
+    $this->enableModules(array('system'), FALSE);
+    $this->installSchema('system', 'variable');
+
+    // Verify that the module does not exist yet.
+    $this->assertFalse(module_exists($module), "$module module not found.");
+    $list = module_list();
+    $this->assertFalse(in_array($module, $list), "$module module in module_list() not found.");
+    $list = module_list('permission');
+    $this->assertFalse(in_array($module, $list), "{$module}_permission() in module_implements() not found.");
+
+    $this->assertFalse(db_table_exists($table), "'$table' database table not found.");
+    $schema = drupal_get_schema($table);
+    $this->assertFalse($schema, "'$table' table schema not found.");
+
+    // Enable the module.
+    $this->enableModules(array($module));
+
+    // Verify that the module does not exist yet.
+    $this->assertTrue(module_exists($module), "$module module found.");
+    $list = module_list();
+    $this->assertTrue(in_array($module, $list), "$module module in module_list() found.");
+    $list = module_list('permission');
+    $this->assertTrue(in_array($module, $list), "{$module}_permission() in module_implements() found.");
+
+    $this->assertTrue(db_table_exists($table), "'$table' database table found.");
+    $schema = drupal_get_schema($table);
+    $this->assertTrue($schema, "'$table' table schema found.");
+  }
+
+  /**
+   * Tests expected behavior of installSchema().
+   */
+  function testInstallSchema() {
+    $module = 'entity_test';
+    $table = 'entity_test';
+    // Verify that we can install a table from the module schema.
+    $this->installSchema($module, $table);
+    $this->assertTrue(db_table_exists($table), "'$table' database table found.");
+
+    // Verify that the schema is known to Schema API.
+    $schema = drupal_get_schema();
+    $this->assertTrue($schema[$table], "'$table' table found in schema.");
+    $schema = drupal_get_schema($table);
+    $this->assertTrue($schema, "'$table' table schema found.");
+
+    // Verify that a table from a unknown module cannot be installed.
+    $module = 'database_test';
+    $table = 'test';
+    try {
+      $this->installSchema($module, $table);
+      $this->fail('Exception for non-retrievable schema found.');
+    }
+    catch (\Exception $e) {
+      $this->pass('Exception for non-retrievable schema found.');
+    }
+    $this->assertFalse(db_table_exists($table), "'$table' database table not found.");
+    $schema = drupal_get_schema($table);
+    $this->assertFalse($schema, "'$table' table schema not found.");
+
+    // Verify that the same table can be installed after enabling the module.
+    $this->enableModules(array($module), FALSE);
+    $this->installSchema($module, $table);
+    $this->assertTrue(db_table_exists($table), "'$table' database table found.");
+    $schema = drupal_get_schema($table);
+    $this->assertTrue($schema, "'$table' table schema found.");
+  }
+
+}
