From 5d04888db6a71cb6e37256a8fcf8aae6da2437d5 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Wed, 6 Aug 2014 19:27:53 +0200
Subject: [PATCH 01/29] Issue #2304461 by sun: Rebase KernelTestBase onto
 PHPUnit.

Includes various performance optimizations, since ContainerBuilder::compile()
is very slow: A precompiled Container is shared across test methods.
Each test boots new DrupalKernel that gets the precompiled Container
injected.

Each test registers itself as a Logger, so as to catch unexpected error
log messages, in case functional code fails to use trigger_error().

Various utility methods of the former Simpletest TestBase + KernelTestBase
are made available as traits (so as to keep the original code functional).
---
 .travis.yml                                        |   18 +
 core/includes/bootstrap.inc                        |    8 +-
 .../Drupal/Component/Discovery/YamlDiscovery.php   |   15 +-
 core/lib/Drupal/Core/DrupalKernel.php              |   37 +-
 core/lib/Drupal/Core/DrupalKernelInterface.php     |   13 +
 core/lib/Drupal/Core/Extension/InfoParser.php      |    2 +
 core/lib/Drupal/Core/Extension/ModuleHandler.php   |    8 +
 core/lib/Drupal/Core/Queue/QueueMemoryFactory.php  |   28 +
 core/lib/Drupal/Core/StreamWrapper/LocalStream.php |   13 +-
 .../simpletest/src/RandomGeneratorTrait.php        |  120 ++
 core/modules/simpletest/src/TestBase.php           |  111 +-
 .../simpletest/src/Tests/KernelTestBaseTest.php    |   13 +-
 core/phpunit.xml.dist                              |    6 +-
 core/tests/Drupal/Tests/AssertLegacyTrait.php      |  102 ++
 core/tests/Drupal/Tests/KernelTestBase.php         | 1265 ++++++++++++++++++++
 core/tests/Drupal/Tests/KernelTestBaseTest.php     |  223 ++++
 core/tests/Drupal/Tests/LogException.php           |   49 +
 core/tests/Drupal/Tests/UnitTestCase.php           |   23 +
 core/tests/bootstrap.php                           |   68 +-
 19 files changed, 1970 insertions(+), 152 deletions(-)
 create mode 100644 .travis.yml
 create mode 100644 core/lib/Drupal/Core/Queue/QueueMemoryFactory.php
 create mode 100644 core/modules/simpletest/src/RandomGeneratorTrait.php
 create mode 100644 core/tests/Drupal/Tests/AssertLegacyTrait.php
 create mode 100644 core/tests/Drupal/Tests/KernelTestBase.php
 create mode 100644 core/tests/Drupal/Tests/KernelTestBaseTest.php
 create mode 100644 core/tests/Drupal/Tests/LogException.php

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..8254b03
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,18 @@
+language: php
+
+php:
+  - 5.4
+
+before_script:
+  #- composer self-update
+  # Enable APC extension on PHP 5.4.
+  - echo -e "extension = apc.so\napc.enable_cli = 1\napc.shm_size = 128M\napc.num_files_hint = 7000" > apc.ini
+  - '[ `expr "$TRAVIS_PHP_VERSION" "<" "5.5"` -eq 1 ] && phpenv config-add apc.ini'
+
+script:
+  - phpunit -v -c core --testsuite Unit
+  # Disable XDebug after running unit tests.
+  - phpenv config-rm xdebug.ini
+  - php --version
+  # @todo Update to PHPUnit 4.3 (once released).
+  - ./core/vendor/phpunit/phpunit/phpunit -v -c core --testsuite Kernel
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 27494e7..df03f77 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -176,7 +176,9 @@
  * @see http://php.net/manual/reserved.variables.server.php
  * @see http://php.net/manual/function.time.php
  */
-define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
+if (!defined('REQUEST_TIME')) {
+  define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
+}
 
 /**
  * Regular expression to match PHP function names.
@@ -204,7 +206,9 @@
  *
  * This strips two levels of directories off the current directory.
  */
-define('DRUPAL_ROOT', dirname(dirname(__DIR__)));
+if (!defined('DRUPAL_ROOT')) {
+  define('DRUPAL_ROOT', dirname(dirname(__DIR__)));
+}
 
 /**
  * Returns the appropriate configuration directory.
diff --git a/core/lib/Drupal/Component/Discovery/YamlDiscovery.php b/core/lib/Drupal/Component/Discovery/YamlDiscovery.php
index bf4ee15..5784e3a 100644
--- a/core/lib/Drupal/Component/Discovery/YamlDiscovery.php
+++ b/core/lib/Drupal/Component/Discovery/YamlDiscovery.php
@@ -29,6 +29,15 @@ class YamlDiscovery implements DiscoverableInterface {
   protected $directories = array();
 
   /**
+   * Array of all parsed files, keyed by filename.
+   *
+   * Especially during kernel tests, YAML files are re-parsed often.
+   *
+   * @var array
+   */
+  protected static $parsedFiles = array();
+
+  /**
    * Constructs a YamlDiscovery object.
    *
    * @param string $name
@@ -48,9 +57,11 @@ public function __construct($name, array $directories) {
   public function findAll() {
     $all = array();
     foreach ($this->findFiles() as $provider => $file) {
-      $all[$provider] = Yaml::decode(file_get_contents($file));
+      if (!isset(static::$parsedFiles[$file])) {
+        static::$parsedFiles[$file] = Yaml::decode(file_get_contents($file));
+      }
+      $all[$provider] = static::$parsedFiles[$file];
     }
-
     return $all;
   }
 
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index e54cf89..62ddb47 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -410,6 +410,14 @@ public function getContainer() {
   }
 
   /**
+   * {@inheritdoc}
+   */
+  public function setContainer(ContainerInterface $container = NULL) {
+    $this->container = $container;
+    return $this;
+  }
+
+  /**
    * Helper method that does request related initialization.
    *
    * @param \Symfony\Component\HttpFoundation\Request $request
@@ -520,9 +528,13 @@ public function discoverServiceProviders() {
 
     // Add site-specific service providers.
     if (!empty($GLOBALS['conf']['container_service_providers'])) {
-      foreach ($GLOBALS['conf']['container_service_providers'] as $class) {
-        if (class_exists($class)) {
-          $this->serviceProviderClasses['site'][] = $class;
+      foreach ($GLOBALS['conf']['container_service_providers'] as $key => $class) {
+        if (is_object($class)) {
+          $this->serviceProviderClasses['site'][$key] = get_class($class);
+          $this->serviceProviders['site'][$key] = $class;
+        }
+        elseif (class_exists($class)) {
+          $this->serviceProviderClasses['site'][$key] = $class;
         }
       }
     }
@@ -683,9 +695,16 @@ protected function initializeContainer($rebuild = FALSE) {
       }
     }
 
+    // If we haven't booted yet but there is a container, then we're asked to
+    // boot the container injected via setContainer().
+    // @see \Drupal\Tests\KernelTestBase::setUp()
+    if (isset($this->container) && !$this->booted) {
+      $container = $this->container;
+    }
+
     // If the module list hasn't already been set in updateModules and we are
     // not forcing a rebuild, then try and load the container from the disk.
-    if (empty($this->moduleList) && !$rebuild) {
+    if (!isset($container) && !isset($this->moduleList) && !$rebuild) {
       $class = $this->getClassName();
       $cache_file = $class . '.php';
 
@@ -700,6 +719,7 @@ protected function initializeContainer($rebuild = FALSE) {
       }
     }
 
+    // If there is still no container, build a new one from scratch.
     if (!isset($container)) {
       $container = $this->compileContainer();
     }
@@ -1085,13 +1105,18 @@ protected function compileContainer() {
    */
   protected function initializeServiceProviders() {
     $this->discoverServiceProviders();
-    $this->serviceProviders = array(
+    if (!isset($this->serviceProviders)) {
+      $this->serviceProviders = array();
+    }
+    $this->serviceProviders += array(
       'app' => array(),
       'site' => array(),
     );
     foreach ($this->serviceProviderClasses as $origin => $classes) {
       foreach ($classes as $name => $class) {
-        $this->serviceProviders[$origin][$name] = new $class;
+        if (!isset($this->serviceProviders[$origin][$name])) {
+          $this->serviceProviders[$origin][$name] = new $class;
+        }
       }
     }
   }
diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php
index 08d007c..987460e 100644
--- a/core/lib/Drupal/Core/DrupalKernelInterface.php
+++ b/core/lib/Drupal/Core/DrupalKernelInterface.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\Core;
 
+use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpKernel\HttpKernelInterface;
 use Symfony\Component\HttpFoundation\Request;
 
@@ -57,6 +58,18 @@ public function getServiceProviders($origin);
   public function getContainer();
 
   /**
+   * Sets the current container.
+   *
+   * Must be called before boot() in order to bootstrap the given container.
+   *
+   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
+   *   The container to set.
+   *
+   * @return $this
+   */
+  public function setContainer(ContainerInterface $container = NULL);
+
+  /**
    * Set the current site path.
    *
    * @param $path
diff --git a/core/lib/Drupal/Core/Extension/InfoParser.php b/core/lib/Drupal/Core/Extension/InfoParser.php
index de1b24a..c48c4c2 100644
--- a/core/lib/Drupal/Core/Extension/InfoParser.php
+++ b/core/lib/Drupal/Core/Extension/InfoParser.php
@@ -19,6 +19,8 @@ class InfoParser implements InfoParserInterface {
   /**
    * Array of all info keyed by filename.
    *
+   * Especially during kernel tests, YAML files are re-parsed often.
+   *
    * @var array
    */
   protected static $parsedInfos = array();
diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php
index 6270c8e..add275e 100644
--- a/core/lib/Drupal/Core/Extension/ModuleHandler.php
+++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php
@@ -710,6 +710,10 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
     $extension_config = \Drupal::config('core.extension');
     if ($enable_dependencies) {
       // Get all module data so we can find dependencies and sort.
+      // @todo Remove dependency on system.module.
+      if (!function_exists('system_rebuild_module_data')) {
+        require_once DRUPAL_ROOT . '/core/modules/system/system.module';
+      }
       $module_data = system_rebuild_module_data();
       $module_list = $module_list ? array_combine($module_list, $module_list) : array();
       if (array_diff_key($module_list, $module_data)) {
@@ -918,6 +922,10 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
    */
   public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
     // Get all module data so we can find dependencies and sort.
+    // @todo Remove dependency on system.module.
+    if (!function_exists('system_rebuild_module_data')) {
+      require_once DRUPAL_ROOT . '/core/modules/system/system.module';
+    }
     $module_data = system_rebuild_module_data();
     $module_list = $module_list ? array_combine($module_list, $module_list) : array();
     if (array_diff_key($module_list, $module_data)) {
diff --git a/core/lib/Drupal/Core/Queue/QueueMemoryFactory.php b/core/lib/Drupal/Core/Queue/QueueMemoryFactory.php
new file mode 100644
index 0000000..97f9db5
--- /dev/null
+++ b/core/lib/Drupal/Core/Queue/QueueMemoryFactory.php
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Queue\QueueMemoryFactory.
+ */
+
+namespace Drupal\Core\Queue;
+
+/**
+ * Defines the queue factory for the memory backend.
+ */
+class QueueMemoryFactory {
+
+  /**
+   * Constructs a new queue object for a given name.
+   *
+   * @param string $name
+   *   The name of the collection holding key and value pairs.
+   *
+   * @return \Drupal\Core\Queue\Memory
+   *   A queue implementation for the given $collection.
+   */
+  public function get($name) {
+    return new Memory($name);
+  }
+
+}
diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
index 937953f..0ac7074 100644
--- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
@@ -120,6 +120,14 @@ protected function getLocalPath($uri = NULL) {
       $uri = $this->uri;
     }
     $path = $this->getDirectoryPath() . '/' . $this->getTarget($uri);
+
+    // In PHPUnit tests, the base path for local streams may be a virtual
+    // filesystem stream wrapper URI, in which case this local stream acts like
+    // a proxy. realpath() is (obviously) not supported by vfsStream.
+    if (strpos($path, 'vfs://') === 0) {
+      return $path;
+    }
+
     $realpath = realpath($path);
     if (!$realpath) {
       // This file does not yet exist.
@@ -127,7 +135,10 @@ protected function getLocalPath($uri = NULL) {
     }
     $directory = realpath($this->getDirectoryPath());
     if (!$realpath || !$directory || strpos($realpath, $directory) !== 0) {
-      return FALSE;
+      throw new \RuntimeException(vsprintf("Unable to resolve URI %s to local path %s", array(
+        var_export($uri, TRUE),
+        var_export($path, TRUE),
+      )));
     }
     return $realpath;
   }
diff --git a/core/modules/simpletest/src/RandomGeneratorTrait.php b/core/modules/simpletest/src/RandomGeneratorTrait.php
new file mode 100644
index 0000000..4219ec3
--- /dev/null
+++ b/core/modules/simpletest/src/RandomGeneratorTrait.php
@@ -0,0 +1,120 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\simpletest\RandomGeneratorTrait.
+ */
+
+namespace Drupal\simpletest;
+
+use Drupal\Component\Utility\Random;
+
+/**
+ * Provides random generator utility methods.
+ */
+trait RandomGeneratorTrait {
+
+  /**
+   * The random generator.
+   *
+   * @var \Drupal\Component\Utility\Random
+   */
+  protected $randomGenerator;
+
+  /**
+   * Generates a unique random string of ASCII characters of codes 32 to 126.
+   *
+   * Do not use this method when special characters are not possible (e.g., in
+   * machine or file names that have already been validated); instead, use
+   * randomMachineName().
+   *
+   * @param int $length
+   *   Length of random string to generate.
+   *
+   * @return string
+   *   Randomly generated unique string.
+   *
+   * @see \Drupal\Component\Utility\Random::string()
+   */
+  protected function randomString($length = 8) {
+    return $this->getRandomGenerator()->string($length, TRUE, array($this, 'randomStringValidate'));
+  }
+
+  /**
+   * Callback for random string validation.
+   *
+   * @see \Drupal\Component\Utility\Random::string()
+   *
+   * @param string $string
+   *   The random string to validate.
+   *
+   * @return bool
+   *   TRUE if the random string is valid, FALSE if not.
+   */
+  protected function randomStringValidate($string) {
+    // Consecutive spaces causes issues for
+    // Drupal\simpletest\WebTestBase::assertLink().
+    if (preg_match('/\s{2,}/', $string)) {
+      return FALSE;
+    }
+    // Starting with a space means that length might not be what is expected.
+    // Starting with an @ sign causes CURL to fail if used in conjunction with a
+    // file upload, see https://drupal.org/node/2174997.
+    if (preg_match('/^(\s|@)/', $string)) {
+      return FALSE;
+    }
+    // Ending with a space means that length might not be what is expected.
+    if (preg_match('/\s$/', $string)) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+
+  /**
+   * Generates a unique random string containing letters and numbers.
+   *
+   * Do not use this method when testing unvalidated user input. Instead, use
+   * \Drupal\simpletest\TestBase::randomString().
+   *
+   * @param int $length
+   *   Length of random string to generate.
+   *
+   * @return string
+   *   Randomly generated unique string.
+   *
+   * @see \Drupal\Component\Utility\Random::name()
+   */
+  protected function randomMachineName($length = 8) {
+    return $this->getRandomGenerator()->name($length, TRUE);
+  }
+
+  /**
+   * Generates a random PHP object.
+   *
+   * @param int $size
+   *   The number of random keys to add to the object.
+   *
+   * @return \stdClass
+   *   The generated object, with the specified number of random keys. Each key
+   *   has a random string value.
+   *
+   * @see \Drupal\Component\Utility\Random::object()
+   */
+  protected function randomObject($size = 4) {
+    return $this->getRandomGenerator()->object($size);
+  }
+
+  /**
+   * Gets the random generator for the utility methods.
+   *
+   * @return \Drupal\Component\Utility\Random
+   *   The random generator.
+   */
+  protected function getRandomGenerator() {
+    if (!is_object($this->randomGenerator)) {
+      $this->randomGenerator = new Random();
+    }
+    return $this->randomGenerator;
+  }
+
+}
diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php
index e57048f..8227cf4 100644
--- a/core/modules/simpletest/src/TestBase.php
+++ b/core/modules/simpletest/src/TestBase.php
@@ -8,7 +8,6 @@
 namespace Drupal\simpletest;
 
 use Drupal\Component\Utility\Crypt;
-use Drupal\Component\Utility\Random;
 use Drupal\Core\Database\Database;
 use Drupal\Component\Utility\String;
 use Drupal\Core\Config\ConfigImporter;
@@ -22,6 +21,7 @@
 use Drupal\Core\Site\Settings;
 use Drupal\Core\StreamWrapper\PublicStream;
 use Drupal\Core\Utility\Error;
+use Drupal\simpletest\RandomGeneratorTrait;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\RequestStack;
 use Symfony\Component\DependencyInjection\Reference;
@@ -33,6 +33,9 @@
  * \Drupal\simpletest\WebTestBase or \Drupal\simpletest\UnitTestBase.
  */
 abstract class TestBase {
+
+  use RandomGeneratorTrait;
+
   /**
    * The test run ID.
    *
@@ -191,13 +194,6 @@
   protected $configImporter;
 
   /**
-   * The random generator.
-   *
-   * @var \Drupal\Component\Utility\Random
-   */
-  protected $randomGenerator;
-
-  /**
    * The name of the session cookie.
    */
   protected $originalSessionName;
@@ -1298,105 +1294,6 @@ protected function settingsSet($name, $value) {
   }
 
   /**
-   * Generates a unique random string of ASCII characters of codes 32 to 126.
-   *
-   * Do not use this method when special characters are not possible (e.g., in
-   * machine or file names that have already been validated); instead, use
-   * \Drupal\simpletest\TestBase::randomMachineName().
-   *
-   * @param int $length
-   *   Length of random string to generate.
-   *
-   * @return string
-   *   Randomly generated unique string.
-   *
-   * @see \Drupal\Component\Utility\Random::string()
-   */
-  public function randomString($length = 8) {
-    return $this->getRandomGenerator()->string($length, TRUE, array($this, 'randomStringValidate'));
-  }
-
-  /**
-   * Callback for random string validation.
-   *
-   * @see \Drupal\Component\Utility\Random::string()
-   *
-   * @param string $string
-   *   The random string to validate.
-   *
-   * @return bool
-   *   TRUE if the random string is valid, FALSE if not.
-   */
-  public function randomStringValidate($string) {
-    // Consecutive spaces causes issues for
-    // Drupal\simpletest\WebTestBase::assertLink().
-    if (preg_match('/\s{2,}/', $string)) {
-      return FALSE;
-    }
-
-    // Starting with a space means that length might not be what is expected.
-    // Starting with an @ sign causes CURL to fail if used in conjunction with a
-    // file upload, see https://drupal.org/node/2174997.
-    if (preg_match('/^(\s|@)/', $string)) {
-      return FALSE;
-    }
-
-    // Ending with a space means that length might not be what is expected.
-    if (preg_match('/\s$/', $string)) {
-      return FALSE;
-    }
-
-    return TRUE;
-  }
-
-  /**
-   * Generates a unique random string containing letters and numbers.
-   *
-   * Do not use this method when testing unvalidated user input. Instead, use
-   * \Drupal\simpletest\TestBase::randomString().
-   *
-   * @param int $length
-   *   Length of random string to generate.
-   *
-   * @return string
-   *   Randomly generated unique string.
-   *
-   * @see \Drupal\Component\Utility\Random::name()
-   */
-  public function randomMachineName($length = 8) {
-    return $this->getRandomGenerator()->name($length, TRUE);
-  }
-
-  /**
-   * Generates a random PHP object.
-   *
-   * @param int $size
-   *   The number of random keys to add to the object.
-   *
-   * @return \stdClass
-   *   The generated object, with the specified number of random keys. Each key
-   *   has a random string value.
-   *
-   * @see \Drupal\Component\Utility\Random::object()
-   */
-  public function randomObject($size = 4) {
-    return $this->getRandomGenerator()->object($size);
-  }
-
-  /**
-   * Gets the random generator for the utility methods.
-   *
-   * @return \Drupal\Component\Utility\Random
-   *   The random generator
-   */
-  protected function getRandomGenerator() {
-    if (!is_object($this->randomGenerator)) {
-      $this->randomGenerator = new Random();
-    }
-    return $this->randomGenerator;
-  }
-
-  /**
    * Converts a list of possible parameters into a stack of permutations.
    *
    * Takes a list of parameters containing possible values, and converts all of
diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
index 288cf4d..370b3ea 100644
--- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
+++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
@@ -7,7 +7,7 @@
 
 namespace Drupal\simpletest\Tests;
 
-use Drupal\simpletest\KernelTestBase;
+use Drupal\Tests\KernelTestBase;
 
 /**
  * Tests KernelTestBase functionality.
@@ -24,15 +24,6 @@ class KernelTestBaseTest extends KernelTestBase {
   public static $modules = array('entity', 'entity_test');
 
   /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    $original_container = \Drupal::getContainer();
-    parent::setUp();
-    $this->assertNotIdentical(\Drupal::getContainer(), $original_container, 'KernelTestBase test creates a new container.');
-  }
-
-  /**
    * Tests expected behavior of setUp().
    */
   function testSetUp() {
@@ -222,7 +213,7 @@ function testEnableModulesFixedList() {
     $this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
 
     // Load some additional modules; entity_test should still exist.
-    $this->enableModules(array('entity', 'field', 'text', 'entity_test'));
+    $this->enableModules(array('field', 'text'));
     $this->assertEqual($this->container->get('module_handler')->moduleExists('entity_test'), TRUE);
     $this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
 
diff --git a/core/phpunit.xml.dist b/core/phpunit.xml.dist
index aa4acfd..fac66de 100644
--- a/core/phpunit.xml.dist
+++ b/core/phpunit.xml.dist
@@ -1,6 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
-<phpunit bootstrap="tests/bootstrap.php" colors="true">
+<phpunit
+  bootstrap="tests/bootstrap.php"
+  colors="true"
+  verbose="true"
+>
   <php>
     <!-- Set error reporting to E_ALL. -->
     <ini name="error_reporting" value="32767"/>
diff --git a/core/tests/Drupal/Tests/AssertLegacyTrait.php b/core/tests/Drupal/Tests/AssertLegacyTrait.php
new file mode 100644
index 0000000..42f7cbf
--- /dev/null
+++ b/core/tests/Drupal/Tests/AssertLegacyTrait.php
@@ -0,0 +1,102 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\AssertLegacyTrait.
+ */
+
+namespace Drupal\Tests;
+
+/**
+ * Translates Simpletest assertion methods to PHPUnit.
+ *
+ * Protected methods are custom. Public static methods override methods of
+ * \PHPUnit_Framework_Assert.
+ */
+trait AssertLegacyTrait {
+
+  /**
+   * @see \Drupal\simpletest\TestBase::assert()
+   */
+  protected function assert($actual, $message = '') {
+    parent::assertTrue((bool) $actual, $message);
+  }
+
+  /**
+   * @see \Drupal\simpletest\TestBase::assertTrue()
+   */
+  public static function assertTrue($actual, $message = '') {
+    if (is_bool($actual)) {
+      parent::assertTrue($actual, $message);
+    }
+    else {
+      parent::assertNotEmpty($actual, $message);
+    }
+  }
+
+  /**
+   * @see \Drupal\simpletest\TestBase::assertFalse()
+   */
+  public static function assertFalse($actual, $message = '') {
+    if (is_bool($actual)) {
+      parent::assertFalse($actual, $message);
+    }
+    else {
+      parent::assertEmpty($actual, $message);
+    }
+  }
+
+  /**
+   * @see \Drupal\simpletest\TestBase::assertEqual()
+   */
+  protected function assertEqual($actual, $expected, $message = '') {
+    $this->assertEquals($expected, $actual, $message);
+  }
+
+  /**
+   * @see \Drupal\simpletest\TestBase::assertNotEqual()
+   */
+  protected function assertNotEqual($actual, $expected, $message = '') {
+    $this->assertNotEquals($expected, $actual, $message);
+  }
+
+  /**
+   * @see \Drupal\simpletest\TestBase::assertIdentical()
+   */
+  protected function assertIdentical($actual, $expected, $message = '') {
+    $this->assertSame($expected, $actual, $message);
+  }
+
+  /**
+   * @see \Drupal\simpletest\TestBase::assertNotIdentical()
+   */
+  protected function assertNotIdentical($actual, $expected, $message = '') {
+    $this->assertNotSame($expected, $actual, $message);
+  }
+
+  /**
+   * @see \Drupal\simpletest\TestBase::assertIdenticalObject()
+   */
+  protected function assertIdenticalObject($actual, $expected, $message = '') {
+    $this->assertSame($expected, $actual, $message);
+  }
+
+  /**
+   * @see \Drupal\simpletest\TestBase::pass()
+   */
+  protected function pass($message) {
+    $this->assertTrue(TRUE, $message);
+  }
+
+  /**
+   * @see \Drupal\simpletest\TestBase::verbose()
+   */
+  protected function verbose($message) {
+    if (in_array('--debug', $_SERVER['argv'], TRUE)) {
+      // Write directly to STDOUT to not produce unexpected test output.
+      // The STDOUT stream does not obey output buffering.
+      fwrite(STDOUT, $message . "\n");
+    }
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/KernelTestBase.php b/core/tests/Drupal/Tests/KernelTestBase.php
new file mode 100644
index 0000000..661be12
--- /dev/null
+++ b/core/tests/Drupal/Tests/KernelTestBase.php
@@ -0,0 +1,1265 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\KernelTestBase.
+ */
+
+namespace Drupal\Tests;
+
+use Drupal\Component\Utility\String;
+use Drupal\Core\Config\ConfigImporter;
+use Drupal\Core\Config\StorageComparer;
+use Drupal\Core\Config\StorageInterface;
+use Drupal\Core\Database\Database;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ServiceProviderInterface;
+use Drupal\Core\DrupalKernel;
+use Drupal\Core\Entity\Schema\EntitySchemaProviderInterface;
+use Drupal\Core\Extension\ExtensionDiscovery;
+use Drupal\Core\Language\Language;
+use Drupal\Core\Site\Settings;
+use Drupal\simpletest\AssertContentTrait;
+use Drupal\simpletest\RandomGeneratorTrait;
+use Psr\Log\LoggerInterface;
+use Psr\Log\LoggerTrait;
+use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
+use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\HttpFoundation\Request;
+use org\bovigo\vfs\vfsStream;
+use org\bovigo\vfs\visitor\vfsStreamPrintVisitor;
+
+/**
+ * Base class for functional integration tests.
+ *
+ * Tests extending this base class can access files and the database, but the
+ * entire environment is initially empty. Drupal runs in a minimal mocked
+ * environment, comparable to the one in the early installer.
+ *
+ * Unlike \Drupal\Tests\UnitTestCase, modules specified in the $modules
+ * property are automatically added to the service container for each test.
+ * The module/hook system is functional and operates on a fixed module list.
+ * Additional modules needed in a test may be loaded and added to the fixed
+ * module list.
+ *
+ * Unlike \Drupal\simpletest\WebTestBase, the modules are only loaded, but not
+ * installed. Modules need to be installed manually, if needed.
+ *
+ * @see \Drupal\Tests\KernelTestBase::$modules
+ * @see \Drupal\Tests\KernelTestBase::enableModules()
+ *
+ * @todo Extend ::setRequirementsFromAnnotation() and ::checkRequirements() to
+ *   account for '@requires module'.
+ */
+abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements ServiceProviderInterface, LoggerInterface {
+
+  use AssertLegacyTrait;
+  use AssertContentTrait;
+  use LoggerTrait;
+  use RandomGeneratorTrait;
+
+  /**
+   * Reset any manipulations to global variables between tests.
+   *
+   * TRUE by default, but MUST be TRUE for kernel tests.
+   *
+   * @var bool
+   */
+  protected $backupGlobals = TRUE;
+
+  /**
+   * Reset all static class properties between tests.
+   *
+   * @var bool
+   */
+  protected $backupStaticAttributes = TRUE;
+
+  /**
+   * Exclude a few static class properties for performance.
+   *
+   * @var array
+   */
+  protected $backupStaticAttributesBlacklist = array(
+    // Ignore static discovery/parser caches to speed up tests.
+    'Drupal\Component\Discovery\YamlDiscovery' => array('parsedFiles'),
+    'Drupal\Core\DependencyInjection\YamlFileLoader' => array('yaml'),
+    'Drupal\Core\Extension\ExtensionDiscovery' => array('files'),
+    'Drupal\Core\Extension\InfoParser' => array('parsedInfos'),
+    // Drupal::$container cannot be serialized.
+    'Drupal' => array('container'),
+  );
+
+  /**
+   * If a test runs in a separate process, do not forward any state.
+   *
+   * @var bool
+   */
+  protected $preserveGlobalState = FALSE;
+
+  /**
+   * @var \Composer\Autoload\Classloader
+   */
+  protected $classLoader;
+
+  /**
+   * @var string
+   */
+  protected $siteDirectory;
+
+  /**
+   * @var string
+   */
+  protected $databasePrefix;
+
+  /**
+   * @var \Drupal\Core\DependencyInjection\ContainerBuilder
+   */
+  protected $container;
+
+  /**
+   * @var \Drupal\Core\DependencyInjection\ContainerBuilder
+   */
+  private static $initialContainerBuilder;
+
+  /**
+   * Modules to enable.
+   *
+   * Test classes extending this class, and any classes in the hierarchy up to
+   * this class, may specify individual lists of modules to enable by setting
+   * this property. The values of all properties in all classes in the hierarchy
+   * are merged.
+   *
+   * @see \Drupal\Tests\KernelTestBase::enableModules()
+   * @see \Drupal\Tests\KernelTestBase::bootKernel()
+   *
+   * @var array
+   */
+  public static $modules = array();
+
+  /**
+   * The virtual filesystem root directory.
+   *
+   * @var \org\bovigo\vfs\vfsStreamDirectory
+   */
+  protected $vfsRoot;
+
+  /**
+   * List of custom stream wrappers registered by a test.
+   *
+   * @see \Drupal\Tests\KernelTestBase::registerStreamWrapper()
+   *
+   * @var array
+   */
+  private $streamWrappers = array();
+
+  /**
+   * @var int
+   */
+  private $expectedLogSeverity;
+
+  /**
+   * @var string
+   */
+  private $expectedLogMessage;
+
+  /**
+   * @todo Move into Config test base class.
+   * @var \Drupal\Core\Config\ConfigImporter
+   */
+  protected $configImporter;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function setUpBeforeClass() {
+    parent::setUpBeforeClass();
+    chdir(__DIR__ . '/../../../../');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->bootEnvironment();
+    $this->bootKernel();
+  }
+
+  /**
+   * Bootstraps a basic test environment.
+   *
+   * Should not be called by tests. Only visible for DrupalKernel integration
+   * tests.
+   *
+   * @see \Drupal\system\Tests\DrupalKernel\DrupalKernelTest
+   * @internal
+   */
+  protected function bootEnvironment() {
+    $this->streamWrappers = array();
+    \Drupal::setContainer(NULL);
+
+    // @see /core/tests/bootstrap.php
+    $this->classLoader = $GLOBALS['loader'];
+
+    require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+
+    // Set up virtual filesystem.
+    // Uses a random ID, since created test files may be processed by file
+    // discovery/parser services that are using a static cache to avoid parsing
+    // the identical files multiple times.
+    $suffix = mt_rand(100000, 999999);
+    $this->vfsRoot = vfsStream::setup('root', NULL, array(
+      'sites' => array(
+        'simpletest' => array(
+          $suffix => array(),
+        ),
+      ),
+    ));
+    $this->siteDirectory = vfsStream::url('root/sites/simpletest/' . $suffix);
+
+    mkdir($this->siteDirectory . '/files', 0775);
+    mkdir($this->siteDirectory . '/files/config/' . CONFIG_ACTIVE_DIRECTORY, 0775, TRUE);
+    mkdir($this->siteDirectory . '/files/config/' . CONFIG_STAGING_DIRECTORY, 0775, TRUE);
+
+    // Ensure that all code that relies on drupal_valid_test_ua() can still be
+    // safely executed. This primarily affects the (test) site directory
+    // resolution (used by e.g. LocalStream and PhpStorage).
+    $this->databasePrefix = 'simpletest' . $suffix;
+    drupal_valid_test_ua($this->databasePrefix);
+
+    $settings = array(
+      'hash_salt' => get_class($this),
+      'file_public_path' => $this->siteDirectory . '/files',
+      // Disable Twig template caching/dumping.
+      'twig_cache' => FALSE,
+      // @todo Remove this; fix Queue factories + consuming code.
+      // @see \Drupal\Tests\KernelTestBase::register()
+      'queue_default' => 'queue.memory',
+    );
+    new Settings($settings);
+
+    $GLOBALS['config_directories'] = array(
+      CONFIG_ACTIVE_DIRECTORY => $this->siteDirectory . '/files/config/active',
+      CONFIG_STAGING_DIRECTORY => $this->siteDirectory . '/files/config/staging',
+    );
+
+    foreach (Database::getAllConnectionInfo() as $key => $targets) {
+      Database::removeConnection($key);
+    }
+    Database::setMultipleConnectionInfo($this->getDatabaseConnectionInfo());
+  }
+
+  /**
+   * Bootstraps a kernel for a test.
+   */
+  private function bootKernel() {
+    // Allow for global test environment overrides.
+    if (file_exists($test_env = DRUPAL_ROOT . '/sites/default/testing.services.yml')) {
+      $GLOBALS['conf']['container_yamls']['testing'] = $test_env;
+    }
+    // Add this test class as a service provider.
+    $GLOBALS['conf']['container_service_providers']['test'] = $this;
+
+    $modules = self::getModulesToEnable(get_class($this));
+
+    // Prepare a precompiled container for all tests of this class.
+    // Substantially improves performance, since ContainerBuilder::compile()
+    // is very expensive. Encourages testing best practices (small tests).
+    // Normally a setUpBeforeClass() operation, but object scope is required to
+    // inject $this test class instance as a service provider (see above).
+    $rc = new \ReflectionClass(get_class($this));
+    $test_method_count = count(array_filter($rc->getMethods(), function ($method) {
+      // PHPUnit's @test annotations are intentionally ignored/not supported.
+      return strpos($method->getName(), 'test') === 0;
+    }));
+    if ($test_method_count > 1 && !$this->isTestInIsolation()) {
+      // Clone a precompiled, empty ContainerBuilder instance for each test.
+      $container = $this->getCompiledContainerBuilder($modules);
+    }
+
+    // Bootstrap the kernel. Do not use createFromRequest to retain Settings.
+    $kernel = new DrupalKernel('testing', $this->classLoader, FALSE);
+    $kernel->setSitePath($this->siteDirectory);
+    // Boot the precompiled container. The kernel will enhance it with synthetic
+    // services.
+    if (isset($container)) {
+      $kernel->setContainer($container);
+      unset($container);
+    }
+    // Boot a new one-time container from scratch. Ensure to set the module list
+    // upfront to avoid a subsequent rebuild.
+    elseif ($modules && $extensions = $this->getExtensionsForModules($modules)) {
+      $kernel->updateModules($extensions, $extensions);
+    }
+    // DrupalKernel::boot() is not sufficient as it does not invoke preHandle(),
+    // which is required to initialize legacy global variables.
+    $request = Request::create('/');
+    $kernel->prepareLegacyRequest($request);
+
+    // register() is only called if a new container was built/compiled.
+    $this->container = $kernel->getContainer();
+
+    if ($modules) {
+      $this->container->get('module_handler')->loadAll();
+    }
+
+    $this->container->set('test.logger', $this);
+
+    // Write the core.extension configuration.
+    // Required for ConfigInstaller::installDefaultConfig() to work.
+    $this->container->get('config.storage')->write('core.extension', array(
+      'module' => array_fill_keys($modules, 0),
+      'theme' => array(),
+      'disabled' => array('theme' => array()),
+    ));
+
+    // Record custom stream wrappers registered by modules during kernel boot.
+    // @todo Move StreamWrapper management into DrupalKernel.
+    // @see https://drupal.org/node/2028109
+    $wrappers = &drupal_static('file_get_stream_wrappers', array());
+    foreach ($wrappers[STREAM_WRAPPERS_ALL] as $scheme => $info) {
+      $this->streamWrappers[$scheme] = $info['type'];
+    }
+
+    // Register basic stream wrappers to avoid dependencies on System module.
+    // The public stream wrapper only depends on 'file_public_path'.
+    if (!isset($this->streamWrappers['public'])) {
+      $this->registerStreamWrapper('public', 'Drupal\Core\StreamWrapper\PublicStream');
+    }
+    // The temporary stream wrapper only depends on the OS temp directory.
+    if (!isset($this->streamWrappers['temporary'])) {
+      $this->registerStreamWrapper('temporary', 'Drupal\Core\StreamWrapper\TemporaryStream');
+    }
+  }
+
+  /**
+   * Returns the Database connection info to be used for this test.
+   *
+   * This method only exists for tests of the Database component itself, because
+   * they require multiple database connections. Each SQLite :memory: connection
+   * creates a new/separate database in memory. A shared-memory SQLite file URI
+   * triggers PHP open_basedir/allow_url_fopen/allow_url_include restrictions.
+   * Due to that, Database tests are running against a SQLite database that is
+   * located in an actual file in the system's temporary directory.
+   *
+   * Other tests should not override this method.
+   *
+   * @return array
+   *   A Database connection info array.
+   *
+   * @internal
+   */
+  protected function getDatabaseConnectionInfo() {
+    $databases['default']['default'] = array(
+      'driver' => 'sqlite',
+      'namespace' => 'Drupal\\Core\\Database\\Driver\\sqlite',
+      'host' => '',
+      'database' => ':memory:',
+      'username' => '',
+      'password' => '',
+      'prefix' => array(
+        'default' => '',
+      ),
+    );
+    return $databases;
+  }
+
+  /**
+   * Prepares a precompiled ContainerBuilder for all tests of this class.
+   *
+   * Avoids repetitive calls to ContainerBuilder::compile(), which is very slow.
+   *
+   * Based on the (always identical) list of $modules to enable, an initial
+   * container is compiled, all instantiated services are reset/removed, and
+   * this precompiled container is stored in a static class property. (Static,
+   * because PHPUnit instantiates a new class instance for each test *method*.)
+   *
+   * This method is not invoked if there is only a single test method. It is
+   * also not invoked for tests running in process isolation (since each test
+   * method runs in a separate process).
+   *
+   * The ContainerBuilder is not dumped into the filesystem (which would yield
+   * an actually compiled Container class), because
+   *
+   * 1. PHP code cannot be unloaded, so e.g. 900 tests would load 900 different,
+   *    full Container classes into memory, quickly exceeding any sensible
+   *    memory consumption (GigaBytes).
+   * 2. Dumping a Container class requires to actually write to the system's
+   *    temporary directory (unless vfsStream supports secret PHP stream wrapper
+   *    flags [cf. Patchwork] to allow for `include 'vfs://container.php';`).
+   * 3. PhpDumper is very slow on its own.
+   *
+   * @param array $modules
+   *   The list of modules to enable.
+   *
+   * @return \Drupal\Core\DependencyInjection\ContainerBuilder
+   *   A clone of the precompiled, empty service container.
+   */
+  private function getCompiledContainerBuilder(array $modules) {
+    if (!isset(self::$initialContainerBuilder)) {
+      $kernel = new DrupalKernel('testing', $this->classLoader, FALSE);
+      $kernel->setSitePath($this->siteDirectory);
+      if ($modules && $extensions = $this->getExtensionsForModules($modules)) {
+        $kernel->updateModules($extensions, $extensions);
+      }
+      $kernel->boot();
+      self::$initialContainerBuilder = $kernel->getContainer();
+
+      // Remove all instantiated services, so the container is safe for cloning.
+      // Technically, ContainerBuilder::set($id, NULL) removes each definition,
+      // but the container is compiled/frozen already.
+      foreach (self::$initialContainerBuilder->getServiceIds() as $id) {
+        self::$initialContainerBuilder->set($id, NULL);
+      }
+
+      // Destruct and trigger garbage collection.
+      \Drupal::setContainer(NULL);
+      $kernel->shutdown();
+      $kernel = NULL;
+      // @see register()
+      $this->container = NULL;
+    }
+
+    $container = clone self::$initialContainerBuilder;
+    // @todo Remove this after updating symfony/dependency-injection.
+    // @see https://github.com/symfony/symfony/pull/11422
+    $container->set('service_container', $container);
+
+    return $container;
+  }
+
+  /**
+   * Returns Extension objects for $modules to enable.
+   *
+   * @param array $modules
+   *   The list of modules to enable.
+   *
+   * @return \Drupal\Core\Extension\Extension[]
+   *   Extension objects for $modules, keyed by module name.
+   *
+   * @throws \PHPUnit_Framework_Exception
+   *   If a module is not available.
+   *
+   * @see \Drupal\Tests\KernelTestBase::enableModules()
+   * @see \Drupal\Core\Extension\ModuleHandler::add()
+   */
+  private function getExtensionsForModules(array $modules) {
+    $extensions = array();
+    $discovery = new ExtensionDiscovery();
+    $discovery->setProfileDirectories(array());
+    $list = $discovery->scan('module');
+    foreach ($modules as $name) {
+      if (!isset($list[$name])) {
+        throw new \PHPUnit_Framework_Exception("Unavailable module: '$name'. If this module needs to be downloaded separately, annotate the test class with '@requires module $name'.");
+      }
+      $extensions[$name] = $list[$name];
+    }
+    return $extensions;
+  }
+
+  /**
+   * Registers test-specific services.
+   *
+   * Extend this method in your test to register additional services. This
+   * method is called whenever the kernel is rebuilt.
+   *
+   * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
+   *   The service container to enhance.
+   *
+   * @see \Drupal\Tests\KernelTestBase::bootKernel()
+   */
+  public function register(ContainerBuilder $container) {
+    $this->container = $container;
+
+    $container
+      ->register('flood', 'Drupal\Core\Flood\MemoryBackend')
+      ->addArgument(new Reference('request_stack'));
+    $container
+      ->register('lock', 'Drupal\Core\Lock\NullLockBackend');
+    $container
+      ->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory');
+    $container
+      ->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory')
+      // Must persist container rebuilds, or all data would vanish otherwise.
+      ->addTag('persist');
+    $container
+      ->setAlias('keyvalue', 'keyvalue.memory');
+
+    // @todo Missing QueueMemoryFactory + QueueFactory type hints + no interface.
+    //   Temporarily tampering with Settings instead.
+    // @see \Drupal\Tests\KernelTestBase::bootEnvironment()
+    $container
+      ->register('queue.memory', 'Drupal\Core\Queue\QueueMemoryFactory');
+    //$container
+    //  ->setAlias('queue', 'queue.memory');
+
+    if ($container->hasDefinition('path_processor_alias')) {
+      // Prevent the alias-based path processor, which requires a url_alias db
+      // table, from being registered to the path processor manager. We do this
+      // by removing the tags that the compiler pass looks for. This means the
+      // url generator can safely be used within tests.
+      $container->getDefinition('path_processor_alias')
+        ->clearTag('path_processor_inbound')
+        ->clearTag('path_processor_outbound');
+    }
+
+    if ($container->hasDefinition('password')) {
+      $container->getDefinition('password')
+        ->setArguments(array(1));
+    }
+
+    // @todo Remove this BC layer.
+    $this->containerBuild($container);
+
+    $container
+      ->register('test.logger', __CLASS__)
+      ->setSynthetic(TRUE)
+      ->addTag('logger');
+  }
+
+  /**
+   * BC alias for register().
+   *
+   * @deprecated 8.0.x:8.0.0
+   * @see \Drupal\Tests\KernelTestBase::register()
+   */
+  public function containerBuild(ContainerBuilder $container) {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function assertPostConditions() {
+    // Execute registered Drupal shutdown functions prior to tearing down.
+    // @see _drupal_shutdown_function()
+    $callbacks = &drupal_register_shutdown_function();
+    while ($callback = array_shift($callbacks)) {
+      call_user_func_array($callback['callback'], $callback['arguments']);
+    }
+
+    // Shut down the kernel (if bootKernel() was called).
+    // @see \Drupal\system\Tests\DrupalKernel\DrupalKernelTest
+    if ($this->container) {
+      $this->container->get('kernel')->shutdown();
+    }
+
+    // Fail in case any (new) shutdown functions exist.
+    $this->assertCount(0, drupal_register_shutdown_function(), 'Unexpected Drupal shutdown callbacks exist after running shutdown functions.');
+
+    // Verify that any expected log message was logged.
+    if (isset($this->expectedLogSeverity)) {
+      $this->fail(vsprintf("Failed to assert expected log message:\n%s: %s", array(
+        $this->logSeverityToString($this->expectedLogSeverity),
+        $this->expectedLogMessage ?: '(no message)',
+      )));
+    }
+
+    parent::assertPostConditions();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function tearDown() {
+    // Stream wrappers are a native global state construct of PHP core, which
+    // has to be maintained manually. Ensure that stream wrappers of this test
+    // do not leak into subsequently executed tests.
+    // @todo Move StreamWrapper management into DrupalKernel.
+    // @see https://drupal.org/node/2028109
+    $this->unregisterAllStreamWrappers();
+
+    // Free up memory: Own properties.
+    $this->classLoader = NULL;
+    $this->vfsRoot = NULL;
+    $this->configImporter = NULL;
+
+    // Free up memory: Custom test class properties.
+    // Note: Private properties cannot be cleaned up.
+    $rc = new \ReflectionClass(__CLASS__);
+    $blacklist = array();
+    foreach ($rc->getProperties() as $property) {
+      $blacklist[$property->name] = $property->getDeclaringClass()->name;
+    }
+    $rc = new \ReflectionClass($this);
+    foreach ($rc->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $property) {
+      if (!$property->isStatic() && !isset($blacklist[$property->name])) {
+        $this->{$property->name} = NULL;
+      }
+    }
+
+    // Clean up statics, container, and settings.
+    drupal_static_reset();
+    \Drupal::setContainer(NULL);
+    $this->container = NULL;
+    new Settings(array());
+
+    // Destroy the in-memory database.
+    foreach (Database::getAllConnectionInfo() as $key => $targets) {
+      Database::removeConnection($key);
+    }
+
+    parent::tearDown();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function tearDownAfterClass() {
+    // Free up memory: Precompiled container.
+    self::$initialContainerBuilder = NULL;
+    parent::tearDownAfterClass();
+  }
+
+  /**
+   * Installs default configuration for a given list of modules.
+   *
+   * @param string|array $modules
+   *   A list of modules for which to install default configuration.
+   *
+   * @throws \LogicException
+   *   If any module in $modules is not enabled.
+   */
+  protected function installConfig($modules) {
+    foreach ((array) $modules as $module) {
+      if (!$this->container->get('module_handler')->moduleExists($module)) {
+        throw new \LogicException("$module module is not enabled.");
+      }
+      $this->container->get('config.installer')->installDefaultConfig('module', $module);
+    }
+  }
+
+  /**
+   * Installs database tables from a module schema definition.
+   *
+   * @param string $module
+   *   The name of the module that defines the table's schema.
+   * @param string|array $tables
+   *   The name or an array of the names of the tables to install.
+   *
+   * @throws \LogicException
+   *   If $module is not enabled or the table schema cannot be found.
+   */
+  protected function installSchema($module, $tables) {
+    // 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 (!$this->container->get('module_handler')->moduleExists($module)) {
+      throw new \LogicException("$module module is not enabled.");
+    }
+    $tables = (array) $tables;
+    foreach ($tables as $table) {
+      $schema = drupal_get_schema_unprocessed($module, $table);
+      if (empty($schema)) {
+        throw new \LogicException("$module module does not define a schema for table '$table'.");
+      }
+      $this->container->get('database')->schema()->createTable($table, $schema);
+    }
+
+    // Refresh the schema cache to make drupal_get_schema() aware of the newly
+    // installed schema.
+    // @todo Refactor Schema API to make this obsolete.
+    drupal_get_schema(NULL, TRUE);
+  }
+
+  /**
+   * Installs the tables for a specific entity type.
+   *
+   * @param string $entity_type_id
+   *   The ID of the entity type.
+   *
+   * @throws \LogicException
+   *   If the entity type does not support automatic schema installation.
+   */
+  protected function installEntitySchema($entity_type_id) {
+    /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
+    $entity_manager = $this->container->get('entity.manager');
+    /** @var \Drupal\Core\Database\Schema $schema_handler */
+    $schema_handler = $this->container->get('database')->schema();
+
+    $storage = $entity_manager->getStorage($entity_type_id);
+    if ($storage instanceof EntitySchemaProviderInterface) {
+      $schema = $storage->getSchema();
+      foreach ($schema as $table_name => $table_schema) {
+        $schema_handler->createTable($table_name, $table_schema);
+      }
+    }
+    else {
+      throw new \LogicException("Entity type '$entity_type_id' does not support automatic schema installation.");
+    }
+  }
+
+  /**
+   * Enables modules for this test.
+   *
+   * @param array $modules
+   *   A list of modules to enable. Dependencies are not resolved; i.e.,
+   *   multiple modules have to be specified individually. The modules are only
+   *   added to the active module list and loaded; i.e., their database schema
+   *   is not installed. hook_install() is not invoked. A custom module weight
+   *   is not applied.
+   *
+   * @throws \LogicException
+   *   If any module in $modules is already enabled.
+   * @throws \RuntimeException
+   *   If a module is not enabled after enabling it.
+   */
+  protected function enableModules(array $modules) {
+    $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+    if ($trace[1]['function'] === 'setUp') {
+      $this->triggerDeprecated('KernelTestBase::enableModules() should not be called from setUp(). Use the $modules property instead.');
+    }
+    unset($trace);
+
+    // Set the list of modules in the extension handler.
+    $module_handler = $this->container->get('module_handler');
+
+    // Write directly to active storage to avoid early instantiation of
+    // the event dispatcher which can prevent modules from registering events.
+    $active_storage = $this->container->get('config.storage');
+    $extension_config = $active_storage->read('core.extension');
+
+    foreach ($modules as $module) {
+      if ($module_handler->moduleExists($module)) {
+        throw new \LogicException("$module module is already enabled.");
+      }
+      $module_handler->addModule($module, drupal_get_path('module', $module));
+      // Maintain the list of enabled modules in configuration.
+      $extension_config['module'][$module] = 0;
+    }
+    $active_storage->write('core.extension', $extension_config);
+
+    // Update the kernel to make their services available.
+    $extensions = $module_handler->getModuleList();
+    $this->container->get('kernel')->updateModules($extensions, $extensions);
+
+    // Ensure isLoaded() is TRUE in order to make _theme() work.
+    // Note that the kernel has rebuilt the container; this $module_handler is
+    // no longer the $module_handler instance from above.
+    $module_handler = $this->container->get('module_handler');
+    $module_handler->reload();
+    foreach ($modules as $module) {
+      if (!$module_handler->moduleExists($module)) {
+        throw new \RuntimeException("$module module is not enabled after enabling it.");
+      }
+    }
+  }
+
+  /**
+   * Disables modules for this test.
+   *
+   * @param array $modules
+   *   A list of modules to disable. Dependencies are not resolved; i.e.,
+   *   multiple modules have to be specified with dependent modules first.
+   *   Code of previously enabled modules is still loaded. The modules are only
+   *   removed from the active module list.
+   *
+   * @throws \LogicException
+   *   If any module in $modules is already disabled.
+   * @throws \RuntimeException
+   *   If a module is not disabled after disabling it.
+   */
+  protected function disableModules(array $modules) {
+    // Unset the list of modules in the extension handler.
+    $module_handler = $this->container->get('module_handler');
+    $extensions = $module_handler->getModuleList();
+    $extension_config = $this->container->get('config.factory')->get('core.extension');
+    foreach ($modules as $module) {
+      if (!$module_handler->moduleExists($module)) {
+        throw new \LogicException("$module module cannot be disabled because it is not enabled.");
+      }
+      unset($extensions[$module]);
+      $extension_config->clear('module.' . $module);
+    }
+    $extension_config->save();
+    $module_handler->setModuleList($extensions);
+    $module_handler->resetImplementations();
+    // Update the kernel to remove their services.
+    $this->container->get('kernel')->updateModules($extensions, $extensions);
+
+    // Ensure isLoaded() is TRUE in order to make _theme() work.
+    // Note that the kernel has rebuilt the container; this $module_handler is
+    // no longer the $module_handler instance from above.
+    $module_handler = $this->container->get('module_handler');
+    $module_handler->reload();
+    foreach ($modules as $module) {
+      if ($module_handler->moduleExists($module)) {
+        throw new \RuntimeException("$module module is not disabled after disabling it.");
+      }
+    }
+  }
+
+  /**
+   * Registers a custom stream wrapper for this test.
+   *
+   * @param string $scheme
+   *   The scheme to register.
+   * @param string $class
+   *   The fully qualified class name to register.
+   * @param int $type
+   *   The Drupal Stream Wrapper API type. Defaults to
+   *   STREAM_WRAPPERS_LOCAL_NORMAL.
+   */
+  protected function registerStreamWrapper($scheme, $class, $type = STREAM_WRAPPERS_LOCAL_NORMAL) {
+    if (isset($this->streamWrappers[$scheme])) {
+      $this->triggerDeprecated(sprintf("Stream wrapper scheme '%s' is already registered; possibly by hook_stream_wrappers() of an enabled (test) module. Either do not call %s() or do not enable the module.", $scheme, __FUNCTION__));
+      $this->unregisterStreamWrapper($scheme, $this->streamWrappers[$scheme]);
+    }
+
+    $this->streamWrappers[$scheme] = $type;
+    if (($type & STREAM_WRAPPERS_LOCAL) == STREAM_WRAPPERS_LOCAL) {
+      stream_wrapper_register($scheme, $class);
+    }
+    else {
+      stream_wrapper_register($scheme, $class, STREAM_IS_URL);
+    }
+    // @todo Revamp Drupal's stream wrapper API for D8.
+    // @see https://drupal.org/node/2028109
+    $wrappers = &drupal_static('file_get_stream_wrappers', array());
+    $wrappers[STREAM_WRAPPERS_ALL][$scheme] = array(
+      'type' => $type,
+      'class' => $class,
+    );
+    if (($type & STREAM_WRAPPERS_WRITE_VISIBLE) == STREAM_WRAPPERS_WRITE_VISIBLE) {
+      $wrappers[STREAM_WRAPPERS_WRITE_VISIBLE][$scheme] = $wrappers[STREAM_WRAPPERS_ALL][$scheme];
+    }
+  }
+
+  /**
+   * Unregisters a custom stream wrapper previously registered by this test.
+   *
+   * KernelTestBase::tearDown() automatically cleans up all registered
+   * stream wrappers, so this usually does not have to be called manually.
+   *
+   * @param string $scheme
+   *   The scheme to unregister.
+   * @param int $type
+   *   The Drupal Stream Wrapper API type of the scheme to unregister.
+   */
+  protected function unregisterStreamWrapper($scheme, $type) {
+    stream_wrapper_unregister($scheme);
+    unset($this->streamWrappers[$scheme]);
+    // @todo Revamp Drupal's stream wrapper API for D8.
+    // @see https://drupal.org/node/2028109
+    $wrappers = &drupal_static('file_get_stream_wrappers', array());
+    foreach ($wrappers as $filter => $schemes) {
+      if (is_int($filter) && (($filter & $type) == $filter)) {
+        unset($wrappers[$filter][$scheme]);
+      }
+    }
+  }
+
+  /**
+   * Unregisters all custom stream wrappers.
+   *
+   * @todo Revamp Drupal's stream wrapper API for D8.
+   * @see https://drupal.org/node/2028109
+   */
+  protected function unregisterAllStreamWrappers() {
+    // file_get_stream_wrappers()'s static variable may have been reset, so
+    // unregister all known wrappers first.
+    foreach ($this->streamWrappers as $scheme => $type) {
+      $this->unregisterStreamWrapper($scheme, $type);
+    }
+
+    $wrappers = &drupal_static('file_get_stream_wrappers', array());
+    if (empty($wrappers)) {
+      return;
+    }
+    foreach ($wrappers[STREAM_WRAPPERS_ALL] as $scheme => $info) {
+      $this->unregisterStreamWrapper($scheme, $info['type']);
+    }
+  }
+
+  /**
+   * Renders a render array.
+   *
+   * @param array $elements
+   *   The elements to render.
+   *
+   * @return string
+   *   The rendered string output (typically HTML).
+   */
+  protected function render(array $elements) {
+    $content = drupal_render($elements);
+    $this->setRawContent($content);
+    $this->verbose('<pre style="white-space: pre-wrap">' . String::checkPlain($content));
+    return $content;
+  }
+
+  /**
+   * Sets an in-memory Settings variable.
+   *
+   * @param string $name
+   *   The name of the setting to set.
+   * @param bool|string|int|array|null $value
+   *   The value to set. Note that array values are replaced entirely; use
+   *   \Drupal\Core\Site\Settings::get() to perform custom merges.
+   */
+  protected function setSetting($name, $value) {
+    $settings = Settings::getAll();
+    $settings[$name] = $value;
+    new Settings($settings);
+  }
+
+  /**
+   * BC alias for setSetting().
+   *
+   * @deprecated 8.0.x:8.0.0
+   * @see \Drupal\Tests\KernelTestBase::setSetting()
+   */
+  protected function settingsSet($name, $value) {
+    $this->triggerDeprecated(sprintf("KernelTestBase::%s() is deprecated. Use setSetting() instead.", __FUNCTION__));
+    $this->setSetting($name, $value);
+  }
+
+  /**
+   * Converts a list of possible parameters into a stack of permutations.
+   *
+   * Takes a list of parameters containing possible values, and converts all of
+   * them into a list of items containing every possible permutation.
+   *
+   * Example:
+   * @code
+   * $parameters = array(
+   *   'one' => array(0, 1),
+   *   'two' => array(2, 3),
+   * );
+   * $permutations = KernelTestBase::generatePermutations($parameters);
+   * // Result:
+   * $permutations == array(
+   *   array('one' => 0, 'two' => 2),
+   *   array('one' => 1, 'two' => 2),
+   *   array('one' => 0, 'two' => 3),
+   *   array('one' => 1, 'two' => 3),
+   * )
+   * @endcode
+   *
+   * @param array $parameters
+   *   An associative array of parameters, keyed by parameter name, and whose
+   *   values are arrays of parameter values.
+   *
+   * @return array
+   *   A list of permutations, which is an array of arrays. Each inner array
+   *   contains the full list of parameters that have been passed, but with a
+   *   single value only.
+   */
+  public static function generatePermutations(array $parameters) {
+    $all_permutations = array(array());
+    foreach ($parameters as $parameter => $values) {
+      $new_permutations = array();
+      // Iterate over all values of the parameter.
+      foreach ($values as $value) {
+        // Iterate over all existing permutations.
+        foreach ($all_permutations as $permutation) {
+          // Add the new parameter value to existing permutations.
+          $new_permutations[] = $permutation + array($parameter => $value);
+        }
+      }
+      // Replace the old permutations with the new permutations.
+      $all_permutations = $new_permutations;
+    }
+    return $all_permutations;
+  }
+
+  /**
+   * Returns a ConfigImporter object to import test configuration.
+   *
+   * @return \Drupal\Core\Config\ConfigImporter
+   *
+   * @todo Move into Config-specific test base class.
+   */
+  protected function configImporter() {
+    if (!$this->configImporter) {
+      // Set up the ConfigImporter object for testing.
+      $storage_comparer = new StorageComparer(
+        $this->container->get('config.storage.staging'),
+        $this->container->get('config.storage'),
+        $this->container->get('config.manager')
+      );
+      $this->configImporter = new ConfigImporter(
+        $storage_comparer,
+        $this->container->get('event_dispatcher'),
+        $this->container->get('config.manager'),
+        $this->container->get('lock'),
+        $this->container->get('config.typed'),
+        $this->container->get('module_handler'),
+        $this->container->get('theme_handler'),
+        $this->container->get('string_translation')
+      );
+    }
+    // Always recalculate the changelist when called.
+    return $this->configImporter->reset();
+  }
+
+  /**
+   * Copies configuration objects from a source storage to a target storage.
+   *
+   * @param \Drupal\Core\Config\StorageInterface $source_storage
+   *   The source config storage.
+   * @param \Drupal\Core\Config\StorageInterface $target_storage
+   *   The target config storage.
+   *
+   * @todo Move into Config-specific test base class.
+   */
+  protected function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage) {
+    $target_storage->deleteAll();
+    foreach ($source_storage->listAll() as $name) {
+      $target_storage->write($name, $source_storage->read($name));
+    }
+  }
+
+  /**
+   * Sets an expected severe log message.
+   *
+   * @param int $severity
+   *   The expected log level severity constant (WATCHDOG_*).
+   * @param string $message
+   *   (optional) The expected log message to assert via
+   *   \PHPUnit_Framework_Assert::assertStringMatchesFormat().
+   *
+   * @see \Drupal\Tests\KernelTestBase::log()
+   *
+   * @todo Add support for `@expectedLogMessage*` test method annotations.
+   */
+  protected function setExpectedLogMessage($severity, $message = '') {
+    $this->expectedLogSeverity = $severity;
+    $this->expectedLogMessage = $message;
+  }
+
+  /**
+   * {@inheritdoc}
+   *
+   * @see \Drupal\Tests\KernelTestBase::setExpectedLogMessage()
+   * @see \Drupal\Tests\LogException
+   */
+  public function log($level, $message, array $context = array()) {
+    if ($level <= WATCHDOG_WARNING) {
+      $placeholders = $this->container->get('logger.log_message_parser')
+        ->parseMessagePlaceholders($message, $context);
+      if (!empty($placeholders)) {
+        $message = strtr($message, $placeholders);
+      }
+
+      // Assert an expected log message.
+      if (isset($this->expectedLogSeverity)) {
+        if (!empty($this->expectedLogMessage)) {
+          $this->expectedLogMessage = $this->logSeverityToString($this->expectedLogSeverity) . ': ' . $this->expectedLogMessage;
+          $message = $this->logSeverityToString($level) . ': ' . $message;
+          $this->assertStringMatchesFormat($this->expectedLogMessage, $message);
+        }
+        else {
+          $this->assertSame($this->expectedLogSeverity, $level, vsprintf("Expected log message severity '%s' does not match actual severity '%s'.", array(
+            $this->logSeverityToString($this->expectedLogSeverity),
+            $this->logSeverityToString($level),
+          )));
+        }
+        // If the test did not fail (and thus stop), reset the properties.
+        $this->expectedLogSeverity = NULL;
+        $this->expectedLogMessage = NULL;
+      }
+      else {
+        throw new LogException($message, $level);
+      }
+    }
+  }
+
+  /**
+   * Returns a string presentation of a log severity constant.
+   *
+   * @param int $severity
+   *   The WATCHDOG_* log severity constant to translate.
+   *
+   * @return string
+   *
+   * @throws \LogicException
+   *   If $severity is unknown.
+   */
+  private function logSeverityToString($severity) {
+    $names = ['EMERGENCY', 'ALERT', 'CRITICAL', 'ERROR', 'WARNING', 'NOTICE', 'INFO', 'DEBUG'];
+    if (isset($names[$severity])) {
+      return 'WATCHDOG_' . $names[$severity];
+    }
+    throw new \LogicException("Unknown log message severity '$value'");
+  }
+
+  /**
+   * Stops test execution.
+   */
+  protected function stop() {
+    $this->getTestResultObject()->stop();
+  }
+
+  /**
+   * Dumps the current state of the virtual filesystem to STDOUT.
+   */
+  protected function vfsDump() {
+    vfsStream::inspect(new vfsStreamPrintVisitor());
+  }
+
+  /**
+   * Returns the modules to enable for this test.
+   *
+   * @param string $class
+   *   The fully-qualified class name of this test.
+   *
+   * @return array
+   */
+  private static function getModulesToEnable($class) {
+    $modules = array();
+    while ($class) {
+      if (property_exists($class, 'modules')) {
+        // Only add the modules, if the $modules property was not inherited.
+        $rp = new \ReflectionProperty($class, 'modules');
+        if ($rp->class == $class) {
+          $modules[$class] = $class::$modules;
+        }
+      }
+      $class = get_parent_class($class);
+    }
+    // Modules have been collected in reverse class hierarchy order; modules
+    // defined by base classes should be sorted first. Then, merge the results
+    // together.
+    $modules = array_reverse($modules);
+    return call_user_func_array('array_merge_recursive', $modules);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function prepareTemplate(\Text_Template $template) {
+    $bootstrap_globals = '';
+
+    // Fix missing bootstrap.php when $preserveGlobalState is FALSE.
+    // @see https://github.com/sebastianbergmann/phpunit/pull/797
+    $bootstrap_globals .= '$__PHPUNIT_BOOTSTRAP = ' . var_export($GLOBALS['__PHPUNIT_BOOTSTRAP'], TRUE) . ";\n";
+
+    // Avoid repetitive test namespace discoveries to improve performance.
+    // @see /core/tests/bootstrap.php
+    $bootstrap_globals .= '$namespaces = ' . var_export($GLOBALS['namespaces'], TRUE) . ";\n";
+
+    $template->setVar(array(
+      'constants' => '',
+      'included_files' => '',
+      'globals' => $bootstrap_globals,
+    ));
+  }
+
+  /**
+   * Returns whether the current test runs in isolation.
+   *
+   * @return bool
+   *
+   * @see https://github.com/sebastianbergmann/phpunit/pull/1350
+   */
+  protected function isTestInIsolation() {
+    return function_exists('__phpunit_run_isolated_test');
+  }
+
+  /**
+   * BC: Automatically resolve former KernelTestBase class properties.
+   *
+   * Test authors should follow the provided instructions and adjust their tests
+   * accordingly.
+   *
+   * @deprecated 8.0.x:8.0.0
+   */
+  public function __get($name) {
+    if (in_array($name, array(
+      'public_files_directory',
+      'private_files_directory',
+      'temp_files_directory',
+      'translation_files_directory',
+    ))) {
+      $this->triggerDeprecated(sprintf("KernelTestBase::\$%s no longer exists. Use the regular API method to retrieve it instead (e.g., Settings).", $name));
+      switch ($name) {
+        case 'public_files_directory':
+          return Settings::get('file_public_path', conf_path() . '/files');
+
+        case 'private_files_directory':
+          return $this->container->get('config.factory')->get('system.file')->get('path.private');
+
+        case 'temp_files_directory':
+          return file_directory_temp();
+
+        case 'translation_files_directory':
+          return Settings::get('file_public_path', conf_path() . '/translations');
+      }
+    }
+
+    if ($name === 'configDirectories') {
+      $this->triggerDeprecated(sprintf("KernelTestBase::\$%s no longer exists. Use config_get_config_directory() directly instead.", $name));
+      return array(
+        CONFIG_ACTIVE_DIRECTORY => config_get_config_directory(CONFIG_ACTIVE_DIRECTORY),
+        CONFIG_STAGING_DIRECTORY => config_get_config_directory(CONFIG_STAGING_DIRECTORY),
+      );
+    }
+
+    $denied = array(
+      // @see \Drupal\simpletest\TestBase
+      'testId',
+      'databasePrefix', // @todo 
+      'timeLimit',
+      'results',
+      'assertions',
+      'skipClasses',
+      'verbose',
+      'verboseId',
+      'verboseClassName',
+      'verboseDirectory',
+      'verboseDirectoryUrl',
+      'dieOnFail',
+      'kernel',
+      // @see \Drupal\simpletest\TestBase::prepareEnvironment()
+      'generatedTestFiles',
+      // @see \Drupal\simpletest\KernelTestBase::containerBuild()
+      'keyValueFactory',
+    );
+    if (in_array($name, $denied) || strpos($name, 'original') === 0) {
+      throw new \RuntimeException(sprintf('TestBase::$%s property no longer exists', $name));
+    }
+  }
+
+  /**
+   * BC: Trigger warnings/exceptions for former KernelTestBase class properties.
+   *
+   * This is just an extra safety net. Legacy tests are only reading the former
+   * KernelTestBase properties. Drupal core is not aware of any tests that are
+   * trying to set or change them.
+   *
+   * Test authors should follow the provided instructions and adjust their tests
+   * accordingly.
+   *
+   * @deprecated 8.0.x:8.0.0
+   */
+  public function __set($name, $value) {
+    $this->__get($name);
+  }
+
+  /**
+   * Triggers a test framework feature deprecation warning.
+   *
+   * Does not halt test execution.
+   *
+   * @param string $message
+   *   The plain-text message to output (on CLI).
+   */
+  private function triggerDeprecated($message) {
+    // PHPUnit_Util_DeprecatedFeature no longer exists and is replaced by simply
+    // triggering E_USER_DEPRECATED errors in upcoming PHPUnit versions.
+    // @todo Remove this entire method after upgrading.
+    if (class_exists('PHPUnit_Util_DeprecatedFeature')) {
+      $message = get_class($this) . '::' . $this->getName() . "\n" . $message;
+      $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+      $this->getTestResultObject()->addDeprecatedFeature(
+        new \PHPUnit_Util_DeprecatedFeature($message, $trace[1])
+      );
+    }
+    else {
+      trigger_error($message, E_USER_DEPRECATED);
+    }
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/KernelTestBaseTest.php b/core/tests/Drupal/Tests/KernelTestBaseTest.php
new file mode 100644
index 0000000..14fa767
--- /dev/null
+++ b/core/tests/Drupal/Tests/KernelTestBaseTest.php
@@ -0,0 +1,223 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\KernelTestBaseTest.
+ */
+
+namespace Drupal\Tests;
+
+use org\bovigo\vfs\vfsStream;
+use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
+
+/**
+ * @coversDefaultClass \Drupal\Tests\KernelTestBase
+ * @group PHPUnit
+ */
+class KernelTestBaseTest extends KernelTestBase {
+
+  public static $modules = array('user');
+
+  /**
+   * @covers ::setUpBeforeClass
+   */
+  public function testSetUpBeforeClass() {
+    // Note: PHPUnit automatically restores the original working directory.
+    $this->assertSame(realpath(__DIR__ . '/../../../../'), getcwd());
+  }
+
+  /**
+   * @covers ::prepareEnvironment
+   */
+  public function testPrepareEnvironment() {
+    $this->assertRegExp('/^simpletest\d{6}$/', $this->databasePrefix);
+    $this->assertStringStartsWith('vfs://root/sites/simpletest/', $this->siteDirectory);
+    $this->assertEquals(array(
+      'root' => array(
+        'sites' => array(
+          'simpletest' => array(
+            substr($this->databasePrefix, 10) => array(
+              'files' => array(
+                'config' => array(
+                  'active' => array(),
+                  'staging' => array(),
+                ),
+              ),
+            ),
+          ),
+        ),
+      ),
+    ), vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure());
+  }
+
+  /**
+   * @covers ::setUp
+   */
+  public function testSetUp() {
+    $this->assertTrue($this->container->has('request_stack'));
+    $this->assertTrue($this->container->initialized('request_stack'));
+    $request = $this->container->get('request_stack')->getCurrentRequest();
+    $this->assertNotEmpty($request);
+    $this->assertEquals('/', $request->getPathInfo());
+
+    $this->assertSame($request, \Drupal::request());
+
+    $this->assertEquals($this, $GLOBALS['conf']['container_service_providers']['test']);
+
+    $GLOBALS['destroy-me'] = TRUE;
+    $this->assertArrayHasKey('destroy-me', $GLOBALS);
+
+    $schema = $this->container->get('database')->schema();
+    $schema->createTable('foo', array(
+      'fields' => array(
+        'name' => array(
+          'type' => 'varchar',
+        ),
+      ),
+    ));
+    $this->assertTrue($schema->tableExists('foo'));
+  }
+
+  /**
+   * @covers ::setUp
+   * @depends testSetUp
+   */
+  public function testSetUpDoesNotLeak() {
+    $this->assertArrayNotHasKey('destroy-me', $GLOBALS);
+
+    $expected = array(
+      'config' => 'config',
+    );
+    $schema = $this->container->get('database')->schema();
+    $this->assertEquals($expected, $schema->findTables('%'));
+  }
+
+  /**
+   * @covers ::register
+   */
+  public function testRegister() {
+    // Verify that this container is identical to the actual container.
+    $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerInterface', $this->container);
+    $this->assertSame($this->container, \Drupal::getContainer());
+
+    // The request service should never exist.
+    $this->assertFalse($this->container->has('request'));
+
+    // Verify that there is a request stack.
+    $request = $this->container->get('request_stack')->getCurrentRequest();
+    $this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $request);
+    $this->assertSame($request, \Drupal::request());
+
+    // Trigger a container rebuild.
+    $this->enableModules(array('system'));
+
+    // Verify that this container is identical to the actual container.
+    $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerInterface', $this->container);
+    $this->assertSame($this->container, \Drupal::getContainer());
+
+    // The request service should never exist.
+    $this->assertFalse($this->container->has('request'));
+
+    // Verify that there is a request stack (and that it persisted).
+    $new_request = $this->container->get('request_stack')->getCurrentRequest();
+    $this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $new_request);
+    $this->assertSame($new_request, \Drupal::request());
+    $this->assertSame($request, $new_request);
+  }
+
+  /**
+   * @covers ::getCompiledContainerBuilder
+   */
+  public function testCompiledContainer() {
+    $this->installConfig('user');
+  }
+
+  /**
+   * @covers ::getCompiledContainerBuilder
+   * @depends testCompiledContainer
+   */
+  public function testCompiledContainerIsDestructed() {
+    $this->installConfig('user');
+  }
+
+  /**
+   * @covers ::render
+   */
+  public function testRender() {
+    $type = 'html_tag';
+    $element_info = $this->container->get('element_info');
+    $this->assertEmpty($this->container->get('element_info')->getInfo($type));
+
+    $this->enableModules(array('system'));
+
+    $this->assertNotSame($element_info, $this->container->get('element_info'));
+    $this->assertNotEmpty($this->container->get('element_info')->getInfo($type));
+
+    $build = array(
+      '#type' => $type,
+      '#tag' => 'h3',
+      '#value' => 'Inner',
+    );
+    $expected = "<h3>Inner</h3>\n";
+
+    $this->assertNull($GLOBALS['theme']);
+    $output = drupal_render($build);
+    $this->assertNull($GLOBALS['theme']);
+
+    $this->assertEquals($expected, $build['#children']);
+    $this->assertEquals($expected, $output);
+  }
+
+  /**
+   * @covers ::render
+   */
+  public function testRenderWithTheme() {
+    $this->enableModules(array('system'));
+
+    $build = array(
+      '#type' => 'textfield',
+      '#name' => 'test',
+    );
+    $expected = '/' . preg_quote('<input type="text" name="test"', '/') . '/';
+
+    $this->assertArrayNotHasKey('theme', $GLOBALS);
+    $output = drupal_render($build);
+    $this->assertEquals('core', $GLOBALS['theme']);
+
+    $this->assertRegExp($expected, $build['#children']);
+    $this->assertRegExp($expected, $output);
+  }
+
+  /**
+   * @covers ::log
+   * @expectedException \ErrorException
+   * @expectedExceptionCode WATCHDOG_WARNING
+   * @expectedExceptionMessage Some problem.
+   */
+  public function testLog() {
+    watchdog('system', 'Not a problem.', array(), WATCHDOG_NOTICE);
+    watchdog('system', 'Some problem.', array(), WATCHDOG_WARNING);
+  }
+
+  /**
+   * @covers ::__get
+   * @covers ::__set
+   * @expectedException \RuntimeException
+   * @dataProvider provider__get
+   */
+  public function test__get($property) {
+    $this->$property;
+  }
+
+  public function provider__get() {
+    return [
+      ['originalWhatever'],
+      ['public_files_directory'],
+      ['private_files_directory'],
+      ['temp_files_directory'],
+      ['translation_files_directory'],
+      ['generatedTestFiles'],
+    ];
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/LogException.php b/core/tests/Drupal/Tests/LogException.php
new file mode 100644
index 0000000..f84139a
--- /dev/null
+++ b/core/tests/Drupal/Tests/LogException.php
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\LogException.
+ */
+
+namespace Drupal\Tests;
+
+/**
+ * Exception thrown in case of unexpected severe log messages.
+ */
+class LogException extends \PHPUnit_Framework_Exception implements \PHPUnit_Framework_SelfDescribing {
+
+  /**
+   * @var int
+   */
+  protected $severity;
+
+  /**
+   * Constructs a new LogException.
+   *
+   * @param string $message
+   *   The log message.
+   * @param int $severity
+   *   The log message severity.
+   * @param \Exception $previous
+   *   (optional) A previously thrown exception.
+   */
+  public function __construct($message = '', $severity = 0, \Exception $previous = NULL) {
+    parent::__construct($message, $severity, $previous);
+    $this->severity = $severity;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function toString() {
+    $names = ['EMERGENCY', 'ALERT', 'CRITICAL', 'ERROR', 'WARNING', 'NOTICE', 'INFO', 'DEBUG'];
+    if (isset($names[$this->severity])) {
+      $name = 'WATCHDOG_' . $names[$this->severity];
+    }
+    else {
+      $name = 'UNKNOWN';
+    }
+    return $name . ': ' . $this->getMessage();
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php
index b024e68..8758b5b 100644
--- a/core/tests/Drupal/Tests/UnitTestCase.php
+++ b/core/tests/Drupal/Tests/UnitTestCase.php
@@ -27,6 +27,29 @@
   protected $randomGenerator;
 
   /**
+   * If a test requests process isolation, do not backup state.
+   *
+   * @var bool
+   */
+  protected $preserveGlobalState = FALSE;
+
+  /**
+   * {@inheritdoc}
+   *
+   * Fixes missing invocation of bootstrap.php when $preserveGlobalState is
+   * FALSE.
+   *
+   * @see https://github.com/sebastianbergmann/phpunit/pull/797
+   */
+  protected function prepareTemplate(\Text_Template $template) {
+    $template->setVar(array(
+      'constants' => '',
+      'included_files' => '',
+      'globals' => '$GLOBALS[\'__PHPUNIT_BOOTSTRAP\'] = ' . var_export($GLOBALS['__PHPUNIT_BOOTSTRAP'], TRUE) . ";\n",
+    ));
+  }
+
+  /**
    * {@inheritdoc}
    */
   protected function setUp() {
diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php
index 99fe34d..b030926 100644
--- a/core/tests/bootstrap.php
+++ b/core/tests/bootstrap.php
@@ -20,7 +20,7 @@ function drupal_phpunit_find_extension_directories($scan_directory) {
   $extensions = array();
   $dirs = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($scan_directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS));
   foreach ($dirs as $dir) {
-    if (strpos($dir->getPathname(), 'info.yml') !== FALSE) {
+    if (strpos($dir->getPathname(), '.info.yml') !== FALSE) {
       // Cut off ".info.yml" from the filename for use as the extension name.
       $extensions[substr($dir->getFilename(), 0, -9)] = $dir->getPathInfo()->getRealPath();
     }
@@ -35,55 +35,76 @@ function drupal_phpunit_find_extension_directories($scan_directory) {
  *   An array of directories under which contributed extensions may exist.
  */
 function drupal_phpunit_contrib_extension_directory_roots() {
-  $sites_path = __DIR__ . '/../../sites';
-  $paths = array();
-  // Note this also checks sites/../modules and sites/../profiles.
+  $root = dirname(dirname(__DIR__));
+  $paths = array(
+    $root . '/core/modules',
+    $root . '/core/profiles',
+    $root . '/modules',
+    $root . '/profiles',
+  );
+  $sites_path = $root . '/sites';
   foreach (scandir($sites_path) as $site) {
+    if ($site[0] === '.' || $site === 'simpletest') {
+      continue;
+    }
     $path = "$sites_path/$site";
-    $paths[] = is_dir("$path/modules") ? realpath("$path/modules") : NULL;
-    $paths[] = is_dir("$path/profiles") ? realpath("$path/profiles") : NULL;
+    if (is_dir("$path/modules")) {
+      $paths[] = "$path/modules";
+    }
+    if (is_dir("$path/profiles")) {
+      $paths[] = "$path/profiles";
+    }
   }
-  return array_filter($paths);
+  return $paths;
 }
 
 /**
  * Registers the namespace for each extension directory with the autoloader.
  *
- * @param Composer\Autoload\ClassLoader $loader
- *   The supplied autoloader.
  * @param array $dirs
  *   An associative array of extension directories, keyed by extension name.
  */
-function drupal_phpunit_register_extension_dirs(Composer\Autoload\ClassLoader $loader, $dirs) {
+function drupal_phpunit_get_extension_namespaces($dirs) {
+  $namespaces = array();
   foreach ($dirs as $extension => $dir) {
     if (is_dir($dir . '/src')) {
       // Register the PSR-4 directory for module-provided classes.
-      $loader->addPsr4('Drupal\\' . $extension . '\\', $dir . '/src');
+      $namespaces['Drupal\\' . $extension . '\\'][] = $dir . '/src';
     }
     if (is_dir($dir . '/tests/src')) {
       // Register the PSR-4 directory for PHPUnit test classes.
-      $loader->addPsr4('Drupal\\' . $extension . '\Tests\\', $dir . '/tests/src');
+      $namespaces['Drupal\\' . $extension . '\Tests\\'][] = $dir . '/tests/src';
     }
   }
+  return $namespaces;
 }
 
 // Start with classes in known locations.
 $loader = require __DIR__ . '/../vendor/autoload.php';
 $loader->add('Drupal\\Tests', __DIR__);
 
-// Scan for arbitrary extension namespaces from core and contrib.
-$extension_roots = array_merge(array(
-  __DIR__ . '/../modules',
-  __DIR__ . '/../profiles',
-), drupal_phpunit_contrib_extension_directory_roots());
+if (!isset($GLOBALS['namespaces'])) {
+  // Scan for arbitrary extension namespaces from core and contrib.
+  $extension_roots = drupal_phpunit_contrib_extension_directory_roots();
 
-$dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
-$dirs = array_reduce($dirs, 'array_merge', array());
-drupal_phpunit_register_extension_dirs($loader, $dirs);
+  $dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
+  $dirs = array_reduce($dirs, 'array_merge', array());
+  $GLOBALS['namespaces'] = drupal_phpunit_get_extension_namespaces($dirs);
+}
+foreach ($GLOBALS['namespaces'] as $prefix => $paths) {
+  $loader->addPsr4($prefix, $paths);
+}
 
 // Look into removing these later.
-define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
-define('DRUPAL_ROOT', realpath(__DIR__ . '/../../'));
+// PHPUnit process isolation template re-defines constants and reloads included
+// files (bootstrap.inc) before including this file (bootstrap.php).
+// @todo Fix this upstream and/or use a custom child process template.
+if (!defined('REQUEST_TIME')) {
+  define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
+}
+if (!defined('DRUPAL_ROOT')) {
+  define('DRUPAL_ROOT', realpath(__DIR__ . '/../../'));
+}
 
 // Set sane locale settings, to ensure consistent string, dates, times and
 // numbers handling.
@@ -93,3 +114,6 @@ function drupal_phpunit_register_extension_dirs(Composer\Autoload\ClassLoader $l
 // Set the default timezone. While this doesn't cause any tests to fail, PHP
 // complains if 'date.timezone' is not set in php.ini.
 date_default_timezone_set('UTC');
+
+// Clean up.
+unset($extension_roots, $dirs);
-- 
1.7.11.msysgit.1


From bfe3c2e0e96ced19e2dc7a428c5e16088881e758 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Fri, 1 Aug 2014 04:59:31 +0200
Subject: [PATCH 02/29] Issue #2260121 by sun: [TBD] Re-route former KTB to
 new KTB.

---
 core/modules/simpletest/src/KernelTestBase.php     |  9 +++++
 core/modules/simpletest/tests/src/TestBaseTest.php | 20 ++++++++---
 core/phpunit.xml.dist                              | 41 ++++++++++++++--------
 3 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php
index 616d064..6a2adeb 100644
--- a/core/modules/simpletest/src/KernelTestBase.php
+++ b/core/modules/simpletest/src/KernelTestBase.php
@@ -7,6 +7,13 @@
 
 namespace Drupal\simpletest;
 
+use Drupal\Tests\KernelTestBase as KernelTestBaseNG;
+
+abstract class KernelTestBase extends KernelTestBaseNG {
+}
+
+namespace Drupal\simpletest\Gone;
+
 use Drupal\Component\Utility\String;
 use Drupal\Core\Database\Database;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
@@ -15,6 +22,8 @@
 use Drupal\Core\Language\Language;
 use Drupal\Core\Site\Settings;
 use Drupal\Core\Entity\Schema\EntitySchemaProviderInterface;
+use Drupal\simpletest\AssertContentTrait;
+use Drupal\simpletest\UnitTestBase;
 use Symfony\Component\DependencyInjection\Reference;
 use Symfony\Component\HttpFoundation\Request;
 
diff --git a/core/modules/simpletest/tests/src/TestBaseTest.php b/core/modules/simpletest/tests/src/TestBaseTest.php
index 50e08b5..41f5e4b 100644
--- a/core/modules/simpletest/tests/src/TestBaseTest.php
+++ b/core/modules/simpletest/tests/src/TestBaseTest.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\simpletest\Tests;
 
+use Drupal\simpletest\TestBase;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -16,14 +17,14 @@
 class TestBaseTest extends UnitTestCase {
 
   /**
-   * A stub built using the TestBase class.
+   * TestBase class stub.
    *
-   * @var \PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\simpletest\TestBase
    */
-  protected $stub;
+  private $stub;
 
   protected function setUp() {
-    $this->stub = $this->getMockForAbstractClass('Drupal\simpletest\TestBase');
+    $this->stub = new StubTestBase(0);
   }
 
   /**
@@ -64,3 +65,14 @@ public function testRandomStringValidate($string, $expected) {
   }
 
 }
+
+class StubTestBase extends TestBase {
+
+  public function randomStringValidate($string) {
+    return parent::randomStringValidate($string);
+  }
+
+  protected function setUp() {
+  }
+
+}
diff --git a/core/phpunit.xml.dist b/core/phpunit.xml.dist
index fac66de..abed04a 100644
--- a/core/phpunit.xml.dist
+++ b/core/phpunit.xml.dist
@@ -12,17 +12,23 @@
     <ini name="memory_limit" value="-1"/>
   </php>
   <testsuites>
-    <testsuite name="Drupal Unit Test Suite">
-      <directory>./tests</directory>
-      <directory>./modules/*/tests</directory>
-      <directory>../modules</directory>
-      <directory>../sites/*/modules</directory>
-      <!-- Exclude Composer's vendor directory so we don't run tests there. -->
-      <exclude>./vendor</exclude>
-      <!-- Exclude Drush tests. -->
-      <exclude>./drush/tests</exclude>
-      <!-- Exclude special-case files from config's test modules. -->
-      <exclude>./modules/config/tests/config_test/src</exclude>
+    <!-- @todo Verify glob patterns -->
+    <!-- @todo Use TestSuite.php -->
+    <testsuite name="Unit">
+      <directory>./tests/Drupal/Tests</directory>
+      <directory>./modules/**/tests/src</directory>
+      <directory>../modules/**/tests/src</directory>
+      <directory>../sites/*/modules/**/tests/src</directory>
+      <exclude>./tests/Drupal/Tests/KernelTestBaseTest.php</exclude>
+      <exclude>**/Kernel</exclude>
+      <exclude>**/vendor</exclude>
+    </testsuite>
+    <testsuite name="Kernel">
+      <!-- @todo Move to /tests/src/Kernel/* -->
+      <directory>./modules/**/src/Tests</directory>
+      <directory>../modules/**/src/Tests</directory>
+      <directory>../sites/*/modules/**/src/Tests</directory>
+      <exclude>**/vendor</exclude>
     </testsuite>
   </testsuites>
   <!-- Filter for coverage reports. -->
@@ -30,9 +36,14 @@
     <whitelist>
       <directory>./includes</directory>
       <directory>./lib</directory>
-      <directory>./modules</directory>
-      <directory>../modules</directory>
-      <directory>../sites</directory>
-     </whitelist>
+      <directory>./modules/**/src</directory>
+      <directory>../modules/**/src</directory>
+      <directory>../sites/*/modules/**/src</directory>
+    </whitelist>
+    <blacklist>
+      <directory>**/tests</directory>
+      <directory>../sites/simpletest</directory>
+      <directory>**/vendor</directory>
+    </blacklist>
   </filter>
 </phpunit>
-- 
1.7.11.msysgit.1


From 5525f2424246afe950dbb90f86f7052e76f0ecb0 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 20 Jul 2014 20:55:13 +0200
Subject: [PATCH 03/29] Issue #2304461 by sun: Fixed
 DependencySerializationTrait breaks sans container.

---
 .../Core/DependencyInjection/DependencySerializationTrait.php      | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php
index cb6a27d..9de7e71 100644
--- a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php
+++ b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php
@@ -49,9 +49,10 @@ public function __sleep() {
    * {@inheritdoc}
    */
   public function __wakeup() {
-    $container = \Drupal::getContainer();
-    foreach ($this->_serviceIds as $key => $service_id) {
-      $this->$key = $container->get($service_id);
+    if ($container = \Drupal::getContainer()) {
+      foreach ($this->_serviceIds as $key => $service_id) {
+        $this->$key = $container->get($service_id);
+      }
     }
     $this->_serviceIds = array();
   }
-- 
1.7.11.msysgit.1


From 480df08ac27be84929b465e7a114ac758521418e Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Thu, 24 Jul 2014 17:31:32 +0200
Subject: [PATCH 04/29] Issue #2304461 by sun: [interim] PHPUnit 4.3 process
 isolation fixes.

- Fix process isolation infinitely blocks on Windows.
  https://github.com/sebastianbergmann/phpunit/pull/1340
- Fix standard IO streams are not defined in process isolation.
  https://github.com/sebastianbergmann/phpunit/pull/1348
- Fix isolated child process leaks into parent process.
  https://github.com/sebastianbergmann/phpunit/issues/1351
---
 core/vendor/composer/autoload_classmap.php         |  1 +
 .../vendor/phpunit/phpunit/src/Framework/Error.php |  2 +-
 .../phpunit/phpunit/src/Framework/Exception.php    | 62 ++++++++++++++++
 .../Windows.php => Framework/ExceptionWrapper.php} | 86 +++++++++++++++-------
 .../phpunit/phpunit/src/Framework/TestFailure.php  | 23 +++---
 .../phpunit/phpunit/src/Framework/TestResult.php   |  3 +
 .../phpunit/phpunit/src/TextUI/ResultPrinter.php   | 33 ++-------
 core/vendor/phpunit/phpunit/src/Util/Filter.php    |  9 ++-
 .../src/Util/PHP/Template/TestCaseMethod.tpl.dist  |  6 ++
 .../phpunit/phpunit/src/Util/PHP/Windows.php       | 54 ++++++++++++++
 10 files changed, 213 insertions(+), 66 deletions(-)
 copy core/vendor/phpunit/phpunit/src/{Util/PHP/Windows.php => Framework/ExceptionWrapper.php} (53%)

diff --git a/core/vendor/composer/autoload_classmap.php b/core/vendor/composer/autoload_classmap.php
index 87d8298..1c61900 100644
--- a/core/vendor/composer/autoload_classmap.php
+++ b/core/vendor/composer/autoload_classmap.php
@@ -64,6 +64,7 @@
     'PHPUnit_Framework_Error_Notice' => $vendorDir . '/phpunit/phpunit/src/Framework/Error/Notice.php',
     'PHPUnit_Framework_Error_Warning' => $vendorDir . '/phpunit/phpunit/src/Framework/Error/Warning.php',
     'PHPUnit_Framework_Exception' => $vendorDir . '/phpunit/phpunit/src/Framework/Exception.php',
+    'PHPUnit_Framework_ExceptionWrapper' => $vendorDir . '/phpunit/phpunit/src/Framework/ExceptionWrapper.php',
     'PHPUnit_Framework_ExpectationFailedException' => $vendorDir . '/phpunit/phpunit/src/Framework/ExpectationFailedException.php',
     'PHPUnit_Framework_IncompleteTest' => $vendorDir . '/phpunit/phpunit/src/Framework/IncompleteTest.php',
     'PHPUnit_Framework_IncompleteTestError' => $vendorDir . '/phpunit/phpunit/src/Framework/IncompleteTestError.php',
diff --git a/core/vendor/phpunit/phpunit/src/Framework/Error.php b/core/vendor/phpunit/phpunit/src/Framework/Error.php
index 65ced26..afac325 100644
--- a/core/vendor/phpunit/phpunit/src/Framework/Error.php
+++ b/core/vendor/phpunit/phpunit/src/Framework/Error.php
@@ -54,7 +54,7 @@
  * @link       http://www.phpunit.de/
  * @since      Class available since Release 2.2.0
  */
-class PHPUnit_Framework_Error extends Exception
+class PHPUnit_Framework_Error extends PHPUnit_Framework_Exception
 {
     /**
      * Constructor.
diff --git a/core/vendor/phpunit/phpunit/src/Framework/Exception.php b/core/vendor/phpunit/phpunit/src/Framework/Exception.php
index 832b3a1..4d25d3f 100644
--- a/core/vendor/phpunit/phpunit/src/Framework/Exception.php
+++ b/core/vendor/phpunit/phpunit/src/Framework/Exception.php
@@ -44,6 +44,25 @@
  */
 
 /**
+ * Base class for all PHPUnit Framework exceptions.
+ *
+ * Ensures that exceptions thrown during a test run do not leave stray
+ * references behind.
+ *
+ * Every Exception contains a stack trace. Each stack frame contains the 'args'
+ * of the called function. The function arguments can contain references to
+ * instantiated objects. The references prevent the objects from being
+ * destructed (until test results are eventually printed), so memory cannot be
+ * freed up.
+ *
+ * With enabled process isolation, test results are serialized in the child
+ * process and unserialized in the parent process. The stack trace of Exceptions
+ * may contain objects that cannot be serialized or unserialized (e.g., PDO
+ * connections). Unserializing user-space objects from the child process into
+ * the parent would break the intended encapsulation of process isolation.
+ *
+ * @see http://fabien.potencier.org/article/9/php-serialization-stack-traces-and-exceptions
+ *
  * @package    PHPUnit
  * @subpackage Framework
  * @author     Sebastian Bergmann <sebastian@phpunit.de>
@@ -54,4 +73,47 @@
  */
 class PHPUnit_Framework_Exception extends RuntimeException implements PHPUnit_Exception
 {
+    /**
+     * @var array
+     */
+    protected $serializableTrace;
+
+    public function __construct($message = '', $code = 0, Exception $previous = null)
+    {
+        parent::__construct($message, $code, $previous);
+
+        $this->serializableTrace = $this->getTrace();
+        foreach ($this->serializableTrace as $i => $call) {
+            unset($this->serializableTrace[$i]['args']);
+        }
+    }
+
+    /**
+     * Returns the serializable trace (without 'args').
+     *
+     * @return array
+     */
+    public function getSerializableTrace()
+    {
+        return $this->serializableTrace;
+    }
+
+    /**
+     * @return string
+     */
+    public function __toString()
+    {
+        $string = PHPUnit_Framework_TestFailure::exceptionToString($this);
+
+        if ($trace = PHPUnit_Util_Filter::getFilteredStacktrace($this)) {
+            $string .= "\n" . $trace;
+        }
+
+        return $string;
+    }
+
+    public function __sleep()
+    {
+        return array_keys(get_object_vars($this));
+    }
 }
diff --git a/core/vendor/phpunit/phpunit/src/Util/PHP/Windows.php b/core/vendor/phpunit/phpunit/src/Framework/ExceptionWrapper.php
similarity index 53%
copy from core/vendor/phpunit/phpunit/src/Util/PHP/Windows.php
copy to core/vendor/phpunit/phpunit/src/Framework/ExceptionWrapper.php
index 17d9768..1105afa 100644
--- a/core/vendor/phpunit/phpunit/src/Util/PHP/Windows.php
+++ b/core/vendor/phpunit/phpunit/src/Framework/ExceptionWrapper.php
@@ -35,58 +35,94 @@
  * POSSIBILITY OF SUCH DAMAGE.
  *
  * @package    PHPUnit
- * @subpackage Util
+ * @subpackage Framework
  * @author     Sebastian Bergmann <sebastian@phpunit.de>
  * @copyright  2001-2014 Sebastian Bergmann <sebastian@phpunit.de>
  * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
  * @link       http://www.phpunit.de/
- * @since      File available since Release 3.5.12
+ * @since      File available since Release 4.1.5
  */
 
 /**
- * Windows utility for PHP sub-processes.
+ * Wraps Exceptions thrown by code under test.
+ *
+ * Re-instantiates Exceptions thrown by user-space code to retain their original
+ * class names, properties, and stack traces (but without arguments).
+ *
+ * Unlike PHPUnit_Framework_Exception, the complete stack of previous Exceptions
+ * is processed.
  *
  * @package    PHPUnit
- * @subpackage Util
- * @author     Sebastian Bergmann <sebastian@phpunit.de>
+ * @subpackage Framework
+ * @author     Daniel F. Kudwien <sun@unleashedmind.com>
  * @copyright  2001-2014 Sebastian Bergmann <sebastian@phpunit.de>
  * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
  * @link       http://www.phpunit.de/
- * @since      Class available since Release 3.5.12
+ * @since      Class available since Release 4.1.5
  */
-class PHPUnit_Util_PHP_Windows extends PHPUnit_Util_PHP_Default
+class PHPUnit_Framework_ExceptionWrapper extends PHPUnit_Framework_Exception
 {
     /**
      * @var string
      */
-    private $tempFile;
+    protected $classname;
 
     /**
-     * @param  resource                    $pipe
-     * @param  string                      $job
-     * @throws PHPUnit_Framework_Exception
-     * @since  Method available since Release 3.5.12
+     * @var PHPUnit_Framework_ExceptionWrapper|null
      */
-    protected function process($pipe, $job)
+    protected $previous;
+
+    public function __construct(Exception $e)
     {
-        if (!($this->tempFile = tempnam(sys_get_temp_dir(), 'PHPUnit')) ||
-            file_put_contents($this->tempFile, $job) === false) {
-            throw new PHPUnit_Framework_Exception(
-              'Unable to write temporary file'
-            );
+        // PDOException::getCode() is a string.
+        // @see http://php.net/manual/en/class.pdoexception.php#95812
+        parent::__construct($e->getMessage(), (int) $e->getCode());
+
+        $this->classname = get_class($e);
+        $this->file = $e->getFile();
+        $this->line = $e->getLine();
+
+        $this->serializableTrace = $e->getTrace();
+        foreach ($this->serializableTrace as $i => $call) {
+            unset($this->serializableTrace[$i]['args']);
         }
 
-        fwrite(
-          $pipe,
-          "<?php require_once " . var_export($this->tempFile, true) .  "; ?>"
-        );
+        if ($e->getPrevious()) {
+            $this->previous = new self($e->getPrevious());
+        }
+    }
+
+    /**
+     * @return string
+     */
+    public function getClassname()
+    {
+        return $this->classname;
+    }
+
+    /**
+     * @return PHPUnit_Framework_ExceptionWrapper
+     */
+    public function getPreviousWrapped()
+    {
+        return $this->previous;
     }
 
     /**
-     * @since Method available since Release 3.5.12
+     * @return string
      */
-    protected function cleanup()
+    public function __toString()
     {
-        unlink($this->tempFile);
+        $string = PHPUnit_Framework_TestFailure::exceptionToString($this);
+
+        if ($trace = PHPUnit_Util_Filter::getFilteredStacktrace($this)) {
+            $string .= "\n" . $trace;
+        }
+
+        if ($this->previous) {
+            $string .= "\nCaused by\n" . $this->previous;
+        }
+
+        return $string;
     }
 }
diff --git a/core/vendor/phpunit/phpunit/src/Framework/TestFailure.php b/core/vendor/phpunit/phpunit/src/Framework/TestFailure.php
index 9da0b73..835ea91 100644
--- a/core/vendor/phpunit/phpunit/src/Framework/TestFailure.php
+++ b/core/vendor/phpunit/phpunit/src/Framework/TestFailure.php
@@ -57,9 +57,9 @@
 class PHPUnit_Framework_TestFailure
 {
     /**
-     * @var    PHPUnit_Framework_Test
+     * @var string
      */
-    protected $failedTest;
+    private $testName;
 
     /**
      * @var    Exception
@@ -74,7 +74,11 @@ class PHPUnit_Framework_TestFailure
      */
     public function __construct(PHPUnit_Framework_Test $failedTest, Exception $thrownException)
     {
-        $this->failedTest      = $failedTest;
+        if ($failedTest instanceof PHPUnit_Framework_SelfDescribing) {
+            $this->testName = $failedTest->toString();
+        } else {
+            $this->testName = get_class($failedTest);
+        }
         $this->thrownException = $thrownException;
     }
 
@@ -87,8 +91,7 @@ public function toString()
     {
         return sprintf(
           '%s: %s',
-
-          $this->failedTest->toString(),
+          $this->testName,
           $this->thrownException->getMessage()
         );
     }
@@ -125,6 +128,8 @@ public static function exceptionToString(Exception $e)
             }
         } elseif ($e instanceof PHPUnit_Framework_Error) {
             $buffer = $e->getMessage() . "\n";
+        } elseif ($e instanceof PHPUnit_Framework_ExceptionWrapper) {
+            $buffer = $e->getClassname() . ': ' . $e->getMessage() . "\n";
         } else {
             $buffer = get_class($e) . ': ' . $e->getMessage() . "\n";
         }
@@ -133,13 +138,13 @@ public static function exceptionToString(Exception $e)
     }
 
     /**
-     * Gets the failed test.
+     * Returns the name of the failing test (including data set, if any).
      *
-     * @return PHPUnit_Framework_Test
+     * @return string
      */
-    public function failedTest()
+    public function getTestName()
     {
-        return $this->failedTest;
+        return $this->testName;
     }
 
     /**
diff --git a/core/vendor/phpunit/phpunit/src/Framework/TestResult.php b/core/vendor/phpunit/phpunit/src/Framework/TestResult.php
index f373b08..7a34bc1 100644
--- a/core/vendor/phpunit/phpunit/src/Framework/TestResult.php
+++ b/core/vendor/phpunit/phpunit/src/Framework/TestResult.php
@@ -695,7 +695,10 @@ public function run(PHPUnit_Framework_Test $test)
             } elseif ($e instanceof PHPUnit_Framework_SkippedTestError) {
                 $skipped = true;
             }
+        } catch (PHPUnit_Framework_Exception $e) {
+            $error = true;
         } catch (Exception $e) {
+            $e = new PHPUnit_Framework_ExceptionWrapper($e);
             $error = true;
         }
 
diff --git a/core/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php b/core/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php
index 3a316c1..adf82c2 100644
--- a/core/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php
+++ b/core/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php
@@ -260,20 +260,12 @@ protected function printDefect(PHPUnit_Framework_TestFailure $defect, $count)
      */
     protected function printDefectHeader(PHPUnit_Framework_TestFailure $defect, $count)
     {
-        $failedTest = $defect->failedTest();
-
-        if ($failedTest instanceof PHPUnit_Framework_SelfDescribing) {
-            $testName = $failedTest->toString();
-        } else {
-            $testName = get_class($failedTest);
-        }
-
         $this->write(
           sprintf(
             "\n%d) %s\n",
 
             $count,
-            $testName
+            $defect->getTestName()
           )
         );
     }
@@ -283,26 +275,11 @@ protected function printDefectHeader(PHPUnit_Framework_TestFailure $defect, $cou
      */
     protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect)
     {
-        $this->write($defect->getExceptionAsString());
-
-        $trace = PHPUnit_Util_Filter::getFilteredStacktrace(
-          $defect->thrownException()
-        );
-
-        if (!empty($trace)) {
-            $this->write("\n" . $trace);
-        }
-
-        $e = $defect->thrownException()->getPrevious();
-
-        while ($e) {
-          $this->write(
-            "\nCaused by\n" .
-            PHPUnit_Framework_TestFailure::exceptionToString($e). "\n" .
-            PHPUnit_Util_Filter::getFilteredStacktrace($e)
-          );
+        $e = $defect->thrownException();
+        $this->write((string) $e);
 
-          $e = $e->getPrevious();
+        while ($e = $e->getPrevious()) {
+          $this->write("\nCaused by\n" . $e);
         }
     }
 
diff --git a/core/vendor/phpunit/phpunit/src/Util/Filter.php b/core/vendor/phpunit/phpunit/src/Util/Filter.php
index b36ce7d..5a0ae4f 100644
--- a/core/vendor/phpunit/phpunit/src/Util/Filter.php
+++ b/core/vendor/phpunit/phpunit/src/Util/Filter.php
@@ -82,12 +82,15 @@ public static function getFilteredStacktrace(Exception $e, $asString = true)
             $eTrace = $e->getSyntheticTrace();
             $eFile  = $e->getSyntheticFile();
             $eLine  = $e->getSyntheticLine();
+        } elseif ($e instanceof PHPUnit_Framework_Exception) {
+            $eTrace = $e->getSerializableTrace();
+            $eFile  = $e->getFile();
+            $eLine  = $e->getLine();
         } else {
             if ($e->getPrevious()) {
-                $eTrace = $e->getPrevious()->getTrace();
-            } else {
-                $eTrace = $e->getTrace();
+                $e = $e->getPrevious();
             }
+            $eTrace = $e->getTrace();
             $eFile  = $e->getFile();
             $eLine  = $e->getLine();
         }
diff --git a/core/vendor/phpunit/phpunit/src/Util/PHP/Template/TestCaseMethod.tpl.dist b/core/vendor/phpunit/phpunit/src/Util/PHP/Template/TestCaseMethod.tpl.dist
index 8d714b5..5daca63 100644
--- a/core/vendor/phpunit/phpunit/src/Util/PHP/Template/TestCaseMethod.tpl.dist
+++ b/core/vendor/phpunit/phpunit/src/Util/PHP/Template/TestCaseMethod.tpl.dist
@@ -1,4 +1,10 @@
 <?php
+// @see https://github.com/sebastianbergmann/phpunit/pull/1348
+if (!defined('STDOUT')) {
+    define('STDOUT', fopen('php://stdout', 'wb'));
+    define('STDERR', fopen('php://stderr', 'wb'));
+}
+
 {iniSettings}
 ini_set('display_errors', 'stderr');
 set_include_path('{include_path}');
diff --git a/core/vendor/phpunit/phpunit/src/Util/PHP/Windows.php b/core/vendor/phpunit/phpunit/src/Util/PHP/Windows.php
index 17d9768..1a53479 100644
--- a/core/vendor/phpunit/phpunit/src/Util/PHP/Windows.php
+++ b/core/vendor/phpunit/phpunit/src/Util/PHP/Windows.php
@@ -43,6 +43,8 @@
  * @since      File available since Release 3.5.12
  */
 
+use SebastianBergmann\Environment\Runtime;
+
 /**
  * Windows utility for PHP sub-processes.
  *
@@ -62,6 +64,58 @@ class PHPUnit_Util_PHP_Windows extends PHPUnit_Util_PHP_Default
     private $tempFile;
 
     /**
+     * {@inheritdoc}
+     *
+     * Reading from STDOUT or STDERR hangs forever on Windows if the output is
+     * too large.
+     *
+     * @see https://bugs.php.net/bug.php?id=51800
+     * @see https://github.com/sebastianbergmann/phpunit/pull/1340
+     */
+    public function runJob($job, array $settings = array())
+    {
+        $runtime = new Runtime;
+
+        if (false === $stdout_handle = tmpfile()) {
+            throw new PHPUnit_Framework_Exception(
+              'A temporary file could not be created; verify that your TEMP environment variable is writable'
+            );
+        }
+
+        $process = proc_open(
+          $runtime->getBinary() . $this->settingsToParameters($settings),
+          array(
+            0 => array('pipe', 'r'),
+            1 => $stdout_handle,
+            2 => array('pipe', 'w')
+          ),
+          $pipes
+        );
+
+        if (!is_resource($process)) {
+            throw new PHPUnit_Framework_Exception(
+              'Unable to spawn worker process'
+            );
+        }
+
+        $this->process($pipes[0], $job);
+        fclose($pipes[0]);
+
+        $stderr = stream_get_contents($pipes[2]);
+        fclose($pipes[2]);
+
+        proc_close($process);
+
+        rewind($stdout_handle);
+        $stdout = stream_get_contents($stdout_handle);
+        fclose($stdout_handle);
+
+        $this->cleanup();
+
+        return array('stdout' => $stdout, 'stderr' => $stderr);
+    }
+
+    /**
      * @param  resource                    $pipe
      * @param  string                      $job
      * @throws PHPUnit_Framework_Exception
-- 
1.7.11.msysgit.1


From 5c82b339afc41cedc6950b661011e94773499679 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Wed, 6 Aug 2014 19:31:41 +0200
Subject: [PATCH 05/29] Issue #2314123 by sun: Fixed lots of bogus tests.

---
 .../block/src/Tests/BlockConfigSchemaTest.php      |  1 +
 .../src/Tests/CKEditorPluginManagerTest.php        |  3 +-
 core/modules/ckeditor/src/Tests/CKEditorTest.php   |  3 +-
 .../Tests/CommentDefaultFormatterCacheTagsTest.php |  2 +-
 .../src/Tests/CommentStringIdEntitiesTest.php      |  1 +
 .../config/src/Tests/ConfigEntityUnitTest.php      |  3 +
 .../config/src/Tests/Storage/CachedStorageTest.php |  3 +-
 .../src/Tests/Storage/ConfigStorageTestBase.php    |  5 ++
 .../config/src/Tests/Storage/FileStorageTest.php   |  2 +-
 .../dblog/src/Tests/Views/ViewsIntegrationTest.php |  3 +-
 .../modules/editor/src/Tests/EditorManagerTest.php |  3 +-
 .../editor/src/Tests/QuickEditIntegrationTest.php  |  8 ++-
 .../modules/entity/src/Tests/EntityDisplayTest.php |  7 +--
 .../entity/src/Tests/EntityFormDisplayTest.php     |  6 +-
 .../field/src/Tests/Email/EmailItemTest.php        |  7 ---
 .../src/Tests/FieldImportDeleteUninstallTest.php   |  2 +-
 core/modules/file/src/Tests/ValidatorTest.php      | 11 ++++
 core/modules/hal/src/Tests/NormalizerTestBase.php  |  2 +-
 .../modules/node/src/Tests/NodeLastChangedTest.php |  2 +-
 .../quickedit/src/Tests/MetadataGeneratorTest.php  |  7 ++-
 core/modules/rdf/src/Tests/CrudTest.php            | 15 +++++
 .../rdf/src/Tests/Field/EmailFieldRdfaTest.php     |  2 +-
 .../Tests/Field/FieldRdfaDatatypeCallbackTest.php  |  6 +-
 .../rdf/src/Tests/Field/FieldRdfaTestBase.php      |  9 ++-
 .../system/src/Tests/Block/SystemMenuBlockTest.php |  2 +-
 .../system/src/Tests/Cache/ApcuBackendUnitTest.php |  9 +--
 .../Cache/GenericCacheBackendUnitTestBase.php      |  2 +-
 .../src/Tests/Database/SelectComplexTest.php       |  4 +-
 .../Tests/DrupalKernel/DrupalKernelSiteTest.php    |  2 +-
 .../src/Tests/Entity/ConfigEntityQueryTest.php     |  9 ++-
 .../system/src/Tests/Entity/EntityAccessTest.php   |  2 +-
 .../src/Tests/Entity/EntityBundleFieldTest.php     |  7 ---
 .../system/src/Tests/Entity/EntityCrudHookTest.php |  1 -
 .../system/src/Tests/Entity/EntityFieldTest.php    | 19 ++++++-
 .../src/Tests/Entity/EntityLanguageTestBase.php    |  7 +++
 .../system/src/Tests/Entity/EntityQueryTest.php    |  4 +-
 .../src/Tests/Entity/EntityValidationTest.php      | 15 +++++
 .../src/Tests/Entity/FieldSqlStorageTest.php       | 10 ++++
 .../src/Tests/Extension/ModuleHandlerTest.php      |  5 ++
 .../src/Tests/Extension/ThemeHandlerTest.php       |  2 +-
 .../system/src/Tests/File/DirectoryTest.php        |  6 +-
 .../system/src/Tests/File/NameMungingTest.php      | 16 ++++++
 .../system/src/Tests/File/ScanDirectoryTest.php    |  5 ++
 .../system/src/Tests/Form/FormCacheTest.php        | 15 +++++
 .../system/src/Tests/Path/PathUnitTestBase.php     |  5 ++
 .../modules/system/src/Tests/System/ScriptTest.php |  5 ++
 .../system/src/Tests/TypedData/TypedDataTest.php   |  4 +-
 .../text/src/Tests/Formatter/TextFormatterTest.php |  1 -
 .../text/src/Tests/Formatter/TextPlainUnitTest.php | 65 ++++++++++++++++++++++
 .../user/src/Tests/UserAccountFormFieldsTest.php   |  1 +
 .../src/Tests/Entity/RowEntityRenderersTest.php    |  2 +-
 .../src/Tests/Plugin/RelationshipJoinTestBase.php  |  5 ++
 .../views/src/Tests/Plugin/RowEntityTest.php       |  2 +-
 .../modules/views/src/Tests/ViewExecutableTest.php |  2 +-
 core/modules/views/src/Tests/ViewStorageTest.php   |  1 -
 .../src/Tests/Wizard/WizardPluginBaseUnitTest.php  |  4 +-
 56 files changed, 267 insertions(+), 85 deletions(-)

diff --git a/core/modules/block/src/Tests/BlockConfigSchemaTest.php b/core/modules/block/src/Tests/BlockConfigSchemaTest.php
index 2be1a6d..69b5e9d 100644
--- a/core/modules/block/src/Tests/BlockConfigSchemaTest.php
+++ b/core/modules/block/src/Tests/BlockConfigSchemaTest.php
@@ -32,6 +32,7 @@ class BlockConfigSchemaTest extends KernelTestBase {
     'forum',
     'node',
     'statistics',
+    'system', // BlockManager->getModuleName() -> system_get_info()
     'taxonomy',
   );
 
diff --git a/core/modules/ckeditor/src/Tests/CKEditorPluginManagerTest.php b/core/modules/ckeditor/src/Tests/CKEditorPluginManagerTest.php
index f84f73e..3a5a070 100644
--- a/core/modules/ckeditor/src/Tests/CKEditorPluginManagerTest.php
+++ b/core/modules/ckeditor/src/Tests/CKEditorPluginManagerTest.php
@@ -22,7 +22,7 @@ class CKEditorPluginManagerTest extends DrupalUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('system', 'editor', 'ckeditor');
+  public static $modules = array('system', 'user', 'filter', 'editor', 'ckeditor');
 
   /**
    * The manager for "CKEditor plugin" plugins.
@@ -36,7 +36,6 @@ function setUp() {
 
     // Install the Filter module.
     $this->installSchema('system', 'url_alias');
-    $this->enableModules(array('user', 'filter'));
 
     // Create text format, associate CKEditor.
     $filtered_html_format = entity_create('filter_format', array(
diff --git a/core/modules/ckeditor/src/Tests/CKEditorTest.php b/core/modules/ckeditor/src/Tests/CKEditorTest.php
index 41b81b8..a80db68 100644
--- a/core/modules/ckeditor/src/Tests/CKEditorTest.php
+++ b/core/modules/ckeditor/src/Tests/CKEditorTest.php
@@ -23,7 +23,7 @@ class CKEditorTest extends DrupalUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('system', 'editor', 'ckeditor', 'filter_test');
+  public static $modules = array('system', 'user', 'filter', 'editor', 'ckeditor', 'filter_test');
 
   /**
    * An instance of the "CKEditor" text editor plugin.
@@ -44,7 +44,6 @@ function setUp() {
 
     // Install the Filter module.
     $this->installSchema('system', 'url_alias');
-    $this->enableModules(array('user', 'filter'));
 
     // Create text format, associate CKEditor.
     $filtered_html_format = entity_create('filter_format', array(
diff --git a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
index 787631b..3c809c4 100644
--- a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
+++ b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
@@ -24,7 +24,7 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('entity_test', 'comment', 'menu_link');
+  public static $modules = array('entity_test', 'comment');
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php b/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php
index a65aed0..638043d 100644
--- a/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php
+++ b/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php
@@ -29,6 +29,7 @@ class CommentStringIdEntitiesTest extends KernelTestBase {
     'field_ui',
     'entity',
     'entity_test',
+    'system', // EMAIL_MAX_LENGTH constant.
     'text',
   );
 
diff --git a/core/modules/config/src/Tests/ConfigEntityUnitTest.php b/core/modules/config/src/Tests/ConfigEntityUnitTest.php
index 984583e..b9daa6c 100644
--- a/core/modules/config/src/Tests/ConfigEntityUnitTest.php
+++ b/core/modules/config/src/Tests/ConfigEntityUnitTest.php
@@ -71,6 +71,9 @@ public function testStorageMethods() {
 
     // Ensure that the configuration entity can be loaded by UUID.
     $entity_loaded_by_uuid = entity_load_by_uuid($entity_type->id(), $entity->uuid());
+    if (!$entity_loaded_by_uuid) {
+      $this->fail(sprintf("Failed to load '%s' entity ID '%s' by UUID '%s'.", $entity_type->id(), $entity->id(), $entity->uuid()));
+    }
     // Compare UUIDs as the objects are not identical since
     // $entity->enforceIsNew is FALSE and $entity_loaded_by_uuid->enforceIsNew
     // is NULL.
diff --git a/core/modules/config/src/Tests/Storage/CachedStorageTest.php b/core/modules/config/src/Tests/Storage/CachedStorageTest.php
index bd02b7d..72beb6a 100644
--- a/core/modules/config/src/Tests/Storage/CachedStorageTest.php
+++ b/core/modules/config/src/Tests/Storage/CachedStorageTest.php
@@ -11,6 +11,7 @@
 use Drupal\Core\Config\CachedStorage;
 use Drupal\Core\Database\Database;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
 
 /**
  * Tests CachedStorage operations.
@@ -89,7 +90,7 @@ public function containerBuild(ContainerBuilder $container) {
     parent::containerBuild($container);
     // Use the regular database cache backend to aid testing.
     $container->register('cache_factory', 'Drupal\Core\Cache\DatabaseBackendFactory')
-      ->addArgument(Database::getConnection());
+      ->addArgument(new Reference('database'));
   }
 
 }
diff --git a/core/modules/config/src/Tests/Storage/ConfigStorageTestBase.php b/core/modules/config/src/Tests/Storage/ConfigStorageTestBase.php
index 2bc48fa..e3c4e76 100644
--- a/core/modules/config/src/Tests/Storage/ConfigStorageTestBase.php
+++ b/core/modules/config/src/Tests/Storage/ConfigStorageTestBase.php
@@ -29,6 +29,11 @@
   protected $storage;
 
   /**
+   * @var \Drupal\Core\Config\StorageInterface;
+   */
+  protected $invalidStorage;
+
+  /**
    * Tests storage CRUD operations.
    *
    * @todo Coverage: Trigger PDOExceptions / Database exceptions.
diff --git a/core/modules/config/src/Tests/Storage/FileStorageTest.php b/core/modules/config/src/Tests/Storage/FileStorageTest.php
index 4aadad5..6165044 100644
--- a/core/modules/config/src/Tests/Storage/FileStorageTest.php
+++ b/core/modules/config/src/Tests/Storage/FileStorageTest.php
@@ -46,7 +46,7 @@ protected function delete($name) {
   /**
    * Tests the FileStorage::listAll method with a relative and absolute path.
    */
-  protected function testlistAll() {
+  public function testlistAll() {
     $expected_files = array(
       'core.extension',
       'system.performance',
diff --git a/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php b/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php
index f771f3d..89f7cf0 100644
--- a/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php
+++ b/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php
@@ -32,7 +32,7 @@ class ViewsIntegrationTest extends ViewUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('dblog_test_views');
+  public static $modules = array('dblog', 'dblog_test_views');
 
   /**
    * {@inheritdoc}
@@ -40,7 +40,6 @@ class ViewsIntegrationTest extends ViewUnitTestBase {
   protected function setUp() {
     parent::setUp();
 
-    $this->enableModules(array('system', 'dblog'));
     $this->installSchema('dblog', array('watchdog'));
 
     ViewTestData::createTestViews(get_class($this), array('dblog_test_views'));
diff --git a/core/modules/editor/src/Tests/EditorManagerTest.php b/core/modules/editor/src/Tests/EditorManagerTest.php
index 55f37da..9e071d9 100644
--- a/core/modules/editor/src/Tests/EditorManagerTest.php
+++ b/core/modules/editor/src/Tests/EditorManagerTest.php
@@ -22,7 +22,7 @@ class EditorManagerTest extends DrupalUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('system', 'editor');
+  public static $modules = array('system', 'user', 'filter', 'editor');
 
   /**
    * The manager for text editor plugins.
@@ -36,7 +36,6 @@ public function setUp() {
 
     // Install the Filter module.
     $this->installSchema('system', 'url_alias');
-    $this->enableModules(array('user', 'filter'));
 
     // Add text formats.
     $filtered_html_format = entity_create('filter_format', array(
diff --git a/core/modules/editor/src/Tests/QuickEditIntegrationTest.php b/core/modules/editor/src/Tests/QuickEditIntegrationTest.php
index a8f81e2..73494f6 100644
--- a/core/modules/editor/src/Tests/QuickEditIntegrationTest.php
+++ b/core/modules/editor/src/Tests/QuickEditIntegrationTest.php
@@ -25,6 +25,11 @@
 class QuickEditIntegrationTest extends QuickEditTestBase {
 
   /**
+   * {@inheritdoc}
+   */
+  public static $modules = array('editor', 'editor_test');
+
+  /**
    * The manager for editor plug-ins.
    *
    * @var \Drupal\Component\Plugin\PluginManagerInterface
@@ -65,9 +70,6 @@ public function setUp() {
     // Install the Filter module.
     $this->installSchema('system', 'url_alias');
 
-    // Enable the Text Editor and Text Editor Test module.
-    $this->enableModules(array('editor', 'editor_test'));
-
     // Create a field.
     $this->field_name = 'field_textarea';
     $this->createFieldWithInstance(
diff --git a/core/modules/entity/src/Tests/EntityDisplayTest.php b/core/modules/entity/src/Tests/EntityDisplayTest.php
index 1e6d05d..1efa671 100644
--- a/core/modules/entity/src/Tests/EntityDisplayTest.php
+++ b/core/modules/entity/src/Tests/EntityDisplayTest.php
@@ -16,7 +16,7 @@
  */
 class EntityDisplayTest extends DrupalUnitTestBase {
 
-  public static $modules = array('entity', 'field', 'entity_test', 'user', 'text', 'entity_test');
+  public static $modules = array('entity', 'field', 'entity_test', 'user', 'text', 'field_test', 'node', 'system');
 
   protected function setUp() {
     parent::setUp();
@@ -137,8 +137,6 @@ public function testExtraFieldComponent() {
    * Tests the behavior of a field component within an entity display object.
    */
   public function testFieldComponent() {
-    $this->enableModules(array('field_test'));
-
     $field_name = 'test_field';
     // Create a field storage and an instance.
     $field_storage = entity_create('field_storage_config', array(
@@ -264,7 +262,6 @@ public function testBaseFieldComponent() {
    * Tests renaming and deleting a bundle.
    */
   public function testRenameDeleteBundle() {
-    $this->enableModules(array('field_test', 'node', 'system', 'text'));
     $this->installEntitySchema('node');
 
     // Create a node bundle, display and form display object.
@@ -314,8 +311,6 @@ public function testRenameDeleteBundle() {
    * Tests deleting field instance.
    */
   public function testDeleteFieldInstance() {
-    $this->enableModules(array('field_test'));
-
     $field_name = 'test_field';
     // Create a field storage and an instance.
     $field_storage = entity_create('field_storage_config', array(
diff --git a/core/modules/entity/src/Tests/EntityFormDisplayTest.php b/core/modules/entity/src/Tests/EntityFormDisplayTest.php
index ee7eb9d..eaaec9a 100644
--- a/core/modules/entity/src/Tests/EntityFormDisplayTest.php
+++ b/core/modules/entity/src/Tests/EntityFormDisplayTest.php
@@ -16,7 +16,7 @@
  */
 class EntityFormDisplayTest extends DrupalUnitTestBase {
 
-  public static $modules = array('entity', 'field', 'entity_test', 'user', 'text');
+  public static $modules = array('entity', 'field', 'entity_test', 'field_test', 'user', 'text');
 
   protected function setUp() {
     parent::setUp();
@@ -47,8 +47,6 @@ public function testEntityGetFromDisplay() {
    * Tests the behavior of a field component within an EntityFormDisplay object.
    */
   public function testFieldComponent() {
-    $this->enableModules(array('field_test'));
-
     // Create a field storage and an instance.
     $field_name = 'test_field';
     $field_storage = entity_create('field_storage_config', array(
@@ -177,8 +175,6 @@ public function testBaseFieldComponent() {
    * Tests deleting field instance.
    */
   public function testDeleteFieldInstance() {
-    $this->enableModules(array('field_sql_storage', 'field_test'));
-
     $field_name = 'test_field';
     // Create a field storage and an instance.
     $field_storage = entity_create('field_storage_config', array(
diff --git a/core/modules/field/src/Tests/Email/EmailItemTest.php b/core/modules/field/src/Tests/Email/EmailItemTest.php
index 20bb137..237749c 100644
--- a/core/modules/field/src/Tests/Email/EmailItemTest.php
+++ b/core/modules/field/src/Tests/Email/EmailItemTest.php
@@ -18,13 +18,6 @@
  */
 class EmailItemTest extends FieldUnitTestBase {
 
-  /**
-   * Modules to enable.
-   *
-   * @var array
-   */
-  public static $modules = array('email');
-
   public function setUp() {
     parent::setUp();
 
diff --git a/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php b/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php
index c26d912..6584ec1 100644
--- a/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php
+++ b/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php
@@ -22,7 +22,7 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('telephone', 'menu_link');
+  public static $modules = array('telephone');
 
   public function setUp() {
     parent::setUp();
diff --git a/core/modules/file/src/Tests/ValidatorTest.php b/core/modules/file/src/Tests/ValidatorTest.php
index 4f81f08..6176225 100644
--- a/core/modules/file/src/Tests/ValidatorTest.php
+++ b/core/modules/file/src/Tests/ValidatorTest.php
@@ -13,6 +13,17 @@
  * @group file
  */
 class ValidatorTest extends FileManagedUnitTestBase {
+
+  /**
+   * @var \Drupal\file\Entity\File
+   */
+  protected $image;
+
+  /**
+   * @var \Drupal\file\Entity\File
+   */
+  protected $non_image;
+
   function setUp() {
     parent::setUp();
 
diff --git a/core/modules/hal/src/Tests/NormalizerTestBase.php b/core/modules/hal/src/Tests/NormalizerTestBase.php
index 2ebff74..b5bb348 100644
--- a/core/modules/hal/src/Tests/NormalizerTestBase.php
+++ b/core/modules/hal/src/Tests/NormalizerTestBase.php
@@ -33,7 +33,7 @@
    *
    * @var array
    */
-  public static $modules = array('entity', 'entity_test', 'entity_reference', 'field', 'hal', 'language', 'rest', 'serialization', 'system', 'text', 'user', 'filter',  'menu_link');
+  public static $modules = array('entity', 'entity_test', 'entity_reference', 'field', 'hal', 'language', 'rest', 'serialization', 'system', 'text', 'user', 'filter');
 
   /**
    * The mock serializer.
diff --git a/core/modules/node/src/Tests/NodeLastChangedTest.php b/core/modules/node/src/Tests/NodeLastChangedTest.php
index 5160ad0..37d3bcc 100644
--- a/core/modules/node/src/Tests/NodeLastChangedTest.php
+++ b/core/modules/node/src/Tests/NodeLastChangedTest.php
@@ -21,7 +21,7 @@ class NodeLastChangedTest extends DrupalUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('entity', 'user', 'node', 'field', 'text', 'filter');
+  public static $modules = array('entity', 'user', 'node', 'field', 'system', 'text', 'filter');
 
   public function setUp() {
     parent::setUp();
diff --git a/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php b/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php
index f665071..bf1df14 100644
--- a/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php
+++ b/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php
@@ -21,6 +21,11 @@
 class MetadataGeneratorTest extends QuickEditTestBase {
 
   /**
+   * {@inheritdoc}
+   */
+  public static $modules = array('quickedit_test');
+
+  /**
    * The manager for editor plugins.
    *
    * @var \Drupal\Component\Plugin\PluginManagerInterface
@@ -124,8 +129,6 @@ public function testSimpleEntityType() {
   public function testEditorWithCustomMetadata() {
     $this->installSchema('system', 'url_alias');
 
-    // Enable edit_test module so that the WYSIWYG editor becomes available.
-    $this->enableModules(array('quickedit_test'));
     $this->editorManager = $this->container->get('plugin.manager.quickedit.editor');
     $this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
     $this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
diff --git a/core/modules/rdf/src/Tests/CrudTest.php b/core/modules/rdf/src/Tests/CrudTest.php
index 772ec4f..e97a73c 100644
--- a/core/modules/rdf/src/Tests/CrudTest.php
+++ b/core/modules/rdf/src/Tests/CrudTest.php
@@ -23,6 +23,21 @@ class CrudTest extends DrupalUnitTestBase {
    */
   public static $modules = array('entity_test', 'rdf', 'system');
 
+  /**
+   * @var string
+   */
+  protected $prefix;
+
+  /**
+   * @var string
+   */
+  protected $entity_type;
+
+  /**
+   * @var string
+   */
+  protected $bundle;
+
   public function setUp() {
     parent::setUp();
     $this->prefix = 'rdf.mapping';
diff --git a/core/modules/rdf/src/Tests/Field/EmailFieldRdfaTest.php b/core/modules/rdf/src/Tests/Field/EmailFieldRdfaTest.php
index 7eb8d33..623a626 100644
--- a/core/modules/rdf/src/Tests/Field/EmailFieldRdfaTest.php
+++ b/core/modules/rdf/src/Tests/Field/EmailFieldRdfaTest.php
@@ -23,7 +23,7 @@ class EmailFieldRdfaTest extends FieldRdfaTestBase {
   /**
    * {@inheritdoc}
    */
-  public static $modules = array('email', 'text');
+  public static $modules = array('text');
 
   public function setUp() {
     parent::setUp();
diff --git a/core/modules/rdf/src/Tests/Field/FieldRdfaDatatypeCallbackTest.php b/core/modules/rdf/src/Tests/Field/FieldRdfaDatatypeCallbackTest.php
index 7dc6c74..6b4dc12 100644
--- a/core/modules/rdf/src/Tests/Field/FieldRdfaDatatypeCallbackTest.php
+++ b/core/modules/rdf/src/Tests/Field/FieldRdfaDatatypeCallbackTest.php
@@ -38,9 +38,9 @@ public function setUp() {
     ))->save();
 
     // Set up test values.
-    $this->test_value = $this->randomMachineName();
+    $this->testValue = $this->randomMachineName();
     $this->entity = entity_create('entity_test');
-    $this->entity->{$this->fieldName}->value = $this->test_value;
+    $this->entity->{$this->fieldName}->value = $this->testValue;
     $this->entity->save();
 
     $this->uri = $this->getAbsoluteUri($this->entity);
@@ -51,7 +51,7 @@ public function setUp() {
    */
   public function testDefaultFormatter() {
     // Expected value is the output of the datatype callback, not the raw value.
-    $this->assertFormatterRdfa(array('type'=>'text_default'), 'http://schema.org/interactionCount', array('value' => 'foo' . $this->test_value));
+    $this->assertFormatterRdfa(array('type'=>'text_default'), 'http://schema.org/interactionCount', array('value' => 'foo' . $this->testValue));
   }
 
 }
diff --git a/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php b/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php
index 9a26aca..a61c9ca 100644
--- a/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php
+++ b/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php
@@ -43,14 +43,19 @@
    *
    * @var bool
    */
-  protected $debug = TRUE;
+  protected $debug = FALSE;
 
   /**
    * Modules to enable.
    *
    * @var array
    */
-  public static $modules = array('rdf', 'menu_link');
+  public static $modules = array('rdf');
+
+  /**
+   * @var string
+   */
+  protected $testValue;
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php b/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php
index 95a4258..80c3d3d 100644
--- a/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php
+++ b/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php
@@ -24,7 +24,7 @@ class SystemMenuBlockTest extends DrupalUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('system', 'menu_link', 'block');
+  public static $modules = array('system', 'block');
 
   /**
    * Tests calculation of a system menu block's configuration dependencies.
diff --git a/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php b/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php
index 134de2c..5174501 100644
--- a/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php
+++ b/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php
@@ -13,6 +13,7 @@
  * Tests the APCu cache backend.
  *
  * @group Cache
+ * @requires extension apc
  */
 class ApcuBackendUnitTest extends GenericCacheBackendUnitTestBase {
 
@@ -33,14 +34,14 @@ protected function checkRequirements() {
   }
 
   protected function createCacheBackend($bin) {
-    $this->backend = new ApcuBackend($bin, $this->databasePrefix);
-    return $this->backend;
+    return new ApcuBackend($bin, $this->databasePrefix);
   }
 
   public function tearDown() {
-    $this->backend->removeBin();
+    foreach ($this->cachebackends as $bin => $cachebackend) {
+      $this->cachebackends[$bin]->removeBin();
+    }
     parent::tearDown();
-    $this->backend = NULL;
   }
 
 }
diff --git a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php
index a949b35..debff49 100644
--- a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php
+++ b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php
@@ -94,7 +94,7 @@ public function tearDownCacheBackend() {
    * @return \Drupal\Core\Cache\CacheBackendInterface
    *   Cache backend to test.
    */
-  final function getCacheBackend($bin = null) {
+  protected function getCacheBackend($bin = null) {
     if (!isset($bin)) {
       $bin = $this->getTestBin();
     }
diff --git a/core/modules/system/src/Tests/Database/SelectComplexTest.php b/core/modules/system/src/Tests/Database/SelectComplexTest.php
index 7932816..f63d84d 100644
--- a/core/modules/system/src/Tests/Database/SelectComplexTest.php
+++ b/core/modules/system/src/Tests/Database/SelectComplexTest.php
@@ -21,7 +21,7 @@ class SelectComplexTest extends DatabaseTestBase {
    *
    * @var array
    */
-  public static $modules = array('node_access_test', 'field');
+  public static $modules = array('system', 'user', 'node_access_test', 'field');
 
   /**
    * Tests simple JOIN statements.
@@ -322,9 +322,7 @@ function testJoinTwice() {
    * Tests that we can join on a query.
    */
   function testJoinSubquery() {
-    $this->enableModules(array('system'), FALSE);
     $this->installSchema('system', 'sequences');
-    $this->enableModules(array('field', 'user'));
 
     $account = entity_create('user', array(
       'name' => $this->randomMachineName(),
diff --git a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php
index 7e78d6b..1a719d2 100644
--- a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php
+++ b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php
@@ -39,7 +39,7 @@ class: Drupal\Core\Cache\MemoryBackendFactory
     file_put_contents($this->siteDirectory . '/services.yml', $doc);
 
     // Rebuild the container.
-    $this->kernel->rebuildContainer();
+    $this->container->get('kernel')->rebuildContainer();
 
     $this->assertTrue($this->container->has('site.service.yml'));
     $this->assertIdentical(get_class($this->container->get('cache.backend.database')), 'Drupal\Core\Cache\MemoryBackendFactory');
diff --git a/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php b/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php
index 528c73b..6f39086 100644
--- a/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php
+++ b/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php
@@ -22,7 +22,7 @@ class ConfigEntityQueryTest extends DrupalUnitTestBase {
    *
    * @var array
    */
-  static $modules = array('config_test');
+  static $modules = array('entity', 'config_test');
 
   /**
    * Stores the search results for alter comparison.
@@ -49,7 +49,6 @@ protected function setUp() {
     parent::setUp();
 
     $this->entities = array();
-    $this->enableModules(array('entity'), TRUE);
     $this->factory = $this->container->get('entity.query');
 
     // These two are here to make sure that matchArray needs to go over several
@@ -346,7 +345,7 @@ public function testConfigEntityQuery() {
   /**
    * Tests count query.
    */
-  protected function testCount() {
+  public function testCount() {
     // Test count on no conditions.
     $count = $this->factory->get('config_query_test')
       ->count()
@@ -372,7 +371,7 @@ protected function testCount() {
   /**
    * Tests sorting and range on config entity queries.
    */
-  protected function testSortRange() {
+  public function testSortRange() {
     // Sort by simple ascending/descending.
     $this->queryResults = $this->factory->get('config_query_test')
       ->sort('number', 'DESC')
@@ -428,7 +427,7 @@ protected function testSortRange() {
   /**
    * Tests dotted path matching.
    */
-  protected function testDotted() {
+  public function testDotted() {
     $this->queryResults = $this->factory->get('config_query_test')
       ->condition('array.level1.*', 1)
       ->execute();
diff --git a/core/modules/system/src/Tests/Entity/EntityAccessTest.php b/core/modules/system/src/Tests/Entity/EntityAccessTest.php
index 70f402b..6528f21 100644
--- a/core/modules/system/src/Tests/Entity/EntityAccessTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityAccessTest.php
@@ -119,7 +119,7 @@ function testEntityTranslationAccess() {
   /**
    * Tests hook invocations.
    */
-  protected function testHooks() {
+  public function testHooks() {
     $state = $this->container->get('state');
     $entity = entity_create('entity_test', array(
       'name' => 'test',
diff --git a/core/modules/system/src/Tests/Entity/EntityBundleFieldTest.php b/core/modules/system/src/Tests/Entity/EntityBundleFieldTest.php
index 9b51d86..334ab58 100644
--- a/core/modules/system/src/Tests/Entity/EntityBundleFieldTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityBundleFieldTest.php
@@ -29,13 +29,6 @@ class EntityBundleFieldTest extends EntityUnitTestBase  {
   protected $database;
 
   /**
-   * Modules to enable.
-   *
-   * @var array
-   */
-  public static $modules = array('menu_link');
-
-  /**
    * {@inheritdoc}
    */
   public function setUp() {
diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php
index 2f41f43..56bbd98 100644
--- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php
@@ -135,7 +135,6 @@ public function testBlockHooks() {
    */
   public function testCommentHooks() {
     $account = $this->createUser();
-    $this->enableModules(array('entity', 'filter'));
     entity_create('node_type', array(
       'type' => 'article',
       'name' => 'Article',
diff --git a/core/modules/system/src/Tests/Entity/EntityFieldTest.php b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
index 2371957..e83e442 100644
--- a/core/modules/system/src/Tests/Entity/EntityFieldTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
@@ -34,6 +34,21 @@ class EntityFieldTest extends EntityUnitTestBase  {
    */
   public static $modules = array('filter', 'text', 'node', 'user');
 
+  /**
+   * @var string
+   */
+  protected $entity_name;
+
+  /**
+   * @var \Drupal\user\Entity\User
+   */
+  protected $entity_user;
+
+  /**
+   * @var string
+   */
+  protected $entity_field_text;
+
   public function setUp() {
     parent::setUp();
 
@@ -230,9 +245,9 @@ protected function assertReadWrite($entity_type) {
 
     // Tests adding a value to a field item list.
     $entity->name[] = 'Another name';
-    $this->assertEqual($entity->name[1]->value == 'Another name', format_string('%entity_type: List item added via [].', array('%entity_type' => $entity_type)));
+    $this->assertEqual($entity->name[1]->value, 'Another name', format_string('%entity_type: List item added via [].', array('%entity_type' => $entity_type)));
     $entity->name[2]->value = 'Third name';
-    $this->assertEqual($entity->name[2]->value == 'Third name', format_string('%entity_type: List item added by a accessing not yet created item.', array('%entity_type' => $entity_type)));
+    $this->assertEqual($entity->name[2]->value, 'Third name', format_string('%entity_type: List item added by a accessing not yet created item.', array('%entity_type' => $entity_type)));
 
     // Test removing and empty-ing list items.
     $this->assertEqual(count($entity->name), 3, format_string('%entity_type: List has 3 items.', array('%entity_type' => $entity_type)));
diff --git a/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php b/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php
index 19cf1ad..ffc7830 100644
--- a/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php
+++ b/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php
@@ -37,6 +37,13 @@
   protected $field_name;
 
   /**
+   * Test field instances, keyed by entity type.
+   *
+   * @var array
+   */
+  protected $instance;
+
+  /**
    * The untranslatable test field name.
    *
    * @var string
diff --git a/core/modules/system/src/Tests/Entity/EntityQueryTest.php b/core/modules/system/src/Tests/Entity/EntityQueryTest.php
index 478068e..4d47e3f 100644
--- a/core/modules/system/src/Tests/Entity/EntityQueryTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityQueryTest.php
@@ -373,7 +373,7 @@ function testSort() {
   /**
    * Test tablesort().
    */
-  protected function testTableSort() {
+  public function testTableSort() {
     // While ordering on bundles do not give us a definite order, we can still
     // assert that all entities from one bundle are after the other as the
     // order dictates.
@@ -422,7 +422,7 @@ protected function testTableSort() {
   /**
    * Test that count queries are separated across entity types.
    */
-  protected function testCount() {
+  public function testCount() {
     // Create a field with the same name in a different entity type.
     $field_name = $this->figures;
     $field_storage = entity_create('field_storage_config', array(
diff --git a/core/modules/system/src/Tests/Entity/EntityValidationTest.php b/core/modules/system/src/Tests/Entity/EntityValidationTest.php
index ec858bd..1f87c74 100644
--- a/core/modules/system/src/Tests/Entity/EntityValidationTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityValidationTest.php
@@ -22,6 +22,21 @@ class EntityValidationTest extends EntityUnitTestBase {
   public static $modules = array('filter', 'text');
 
   /**
+   * @var string
+   */
+  protected $entity_name;
+
+  /**
+   * @var \Drupal\user\Entity\User
+   */
+  protected $entity_user;
+
+  /**
+   * @var string
+   */
+  protected $entity_field_text;
+
+  /**
    * {@inheritdoc}
    */
   public function setUp() {
diff --git a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php
index 2ae87fc..94a2f9a 100644
--- a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php
+++ b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php
@@ -37,6 +37,11 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
   protected $field_name;
 
   /**
+   * @var int
+   */
+  protected $field_cardinality;
+
+  /**
    * A field storage to use in this class.
    *
    * @var \Drupal\field\Entity\FieldStorageConfig
@@ -51,6 +56,11 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
   protected $instance;
 
   /**
+   * @var string
+   */
+  protected $table;
+
+  /**
    * Name of the revision table of the field.
    *
    * @var string
diff --git a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php
index 597bb03..820e4aa 100644
--- a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php
+++ b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php
@@ -21,6 +21,11 @@ class ModuleHandlerTest extends KernelTestBase {
   /**
    * {@inheritdoc}
    */
+  public static $modules = array('system');
+
+  /**
+   * {@inheritdoc}
+   */
   public function containerBuild(ContainerBuilder $container) {
     parent::containerBuild($container);
     // Put a fake route bumper on the container to be called during uninstall.
diff --git a/core/modules/system/src/Tests/Extension/ThemeHandlerTest.php b/core/modules/system/src/Tests/Extension/ThemeHandlerTest.php
index 03a94cf..7f5caad 100644
--- a/core/modules/system/src/Tests/Extension/ThemeHandlerTest.php
+++ b/core/modules/system/src/Tests/Extension/ThemeHandlerTest.php
@@ -23,7 +23,7 @@ class ThemeHandlerTest extends DrupalUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('system', 'menu_link');
+  public static $modules = array('system');
 
   public function containerBuild(ContainerBuilder $container) {
     parent::containerBuild($container);
diff --git a/core/modules/system/src/Tests/File/DirectoryTest.php b/core/modules/system/src/Tests/File/DirectoryTest.php
index 158be71..b402227 100644
--- a/core/modules/system/src/Tests/File/DirectoryTest.php
+++ b/core/modules/system/src/Tests/File/DirectoryTest.php
@@ -30,8 +30,8 @@ function testFileCheckLocalDirectoryHandling() {
     $old_mode = fileperms($directory);
 
     // Create the directories.
-    $parent_path = $directory . DIRECTORY_SEPARATOR . $parent;
-    $child_path = $parent_path . DIRECTORY_SEPARATOR . $child;
+    $parent_path = $directory . '/' . $parent;
+    $child_path = $parent_path . '/' . $child;
     $this->assertTrue(drupal_mkdir($child_path, 0775, TRUE), t('No error reported when creating new local directories.'), 'File');
 
     // Ensure new directories also exist.
@@ -46,7 +46,7 @@ function testFileCheckLocalDirectoryHandling() {
     $this->assertDirectoryPermissions($directory, $old_mode);
 
     // Check creating a directory using an absolute path.
-    $absolute_path = drupal_realpath($directory) . DIRECTORY_SEPARATOR . $this->randomMachineName() . DIRECTORY_SEPARATOR . $this->randomMachineName();
+    $absolute_path = drupal_realpath($directory) . '/' . $this->randomMachineName() . '/' . $this->randomMachineName();
     $this->assertTrue(drupal_mkdir($absolute_path, 0775, TRUE), 'No error reported when creating new absolute directories.', 'File');
     $this->assertDirectoryPermissions($absolute_path, 0775);
   }
diff --git a/core/modules/system/src/Tests/File/NameMungingTest.php b/core/modules/system/src/Tests/File/NameMungingTest.php
index 1584067..a4542cb 100644
--- a/core/modules/system/src/Tests/File/NameMungingTest.php
+++ b/core/modules/system/src/Tests/File/NameMungingTest.php
@@ -13,6 +13,22 @@
  * @group File
  */
 class NameMungingTest extends FileTestBase {
+
+  /**
+   * @var string
+   */
+  protected $bad_extension;
+
+  /**
+   * @var string
+   */
+  protected $name;
+
+  /**
+   * @var string
+   */
+  protected $name_with_uc_ext;
+
   function setUp() {
     parent::setUp();
     $this->bad_extension = 'php';
diff --git a/core/modules/system/src/Tests/File/ScanDirectoryTest.php b/core/modules/system/src/Tests/File/ScanDirectoryTest.php
index cda57de..0777460 100644
--- a/core/modules/system/src/Tests/File/ScanDirectoryTest.php
+++ b/core/modules/system/src/Tests/File/ScanDirectoryTest.php
@@ -21,6 +21,11 @@ class ScanDirectoryTest extends FileTestBase {
    */
   public static $modules = array('file_test');
 
+  /**
+   * @var string
+   */
+  protected $path;
+
   function setUp() {
     parent::setUp();
     $this->path = drupal_get_path('module', 'simpletest') . '/files';
diff --git a/core/modules/system/src/Tests/Form/FormCacheTest.php b/core/modules/system/src/Tests/Form/FormCacheTest.php
index 57dbb28..f551092 100644
--- a/core/modules/system/src/Tests/Form/FormCacheTest.php
+++ b/core/modules/system/src/Tests/Form/FormCacheTest.php
@@ -25,6 +25,21 @@ class FormCacheTest extends DrupalUnitTestBase {
    */
   public static $modules = array('system', 'user');
 
+  /**
+   * @var string
+   */
+  protected $form_build_id;
+
+  /**
+   * @var array
+   */
+  protected $form;
+
+  /**
+   * @var array
+   */
+  protected $form_state;
+
   public function setUp() {
     parent::setUp();
     $this->installSchema('system', array('key_value_expire'));
diff --git a/core/modules/system/src/Tests/Path/PathUnitTestBase.php b/core/modules/system/src/Tests/Path/PathUnitTestBase.php
index 4807d47..618d72e 100644
--- a/core/modules/system/src/Tests/Path/PathUnitTestBase.php
+++ b/core/modules/system/src/Tests/Path/PathUnitTestBase.php
@@ -15,6 +15,11 @@
  */
 abstract class PathUnitTestBase extends DrupalUnitTestBase {
 
+  /**
+   * @var \Drupal\system\Tests\Path\UrlAliasFixtures
+   */
+  protected $fixtures;
+
   public function setUp() {
     parent::setUp();
     $this->fixtures = new UrlAliasFixtures();
diff --git a/core/modules/system/src/Tests/System/ScriptTest.php b/core/modules/system/src/Tests/System/ScriptTest.php
index 0be6217..6f6d871 100644
--- a/core/modules/system/src/Tests/System/ScriptTest.php
+++ b/core/modules/system/src/Tests/System/ScriptTest.php
@@ -16,6 +16,11 @@
  */
 class ScriptTest extends DrupalUnitTestBase {
 
+  protected function setUp() {
+    parent::setUp();
+    require_once DRUPAL_ROOT . '/core/includes/install.inc';
+  }
+
   /**
    * Tests password-hash.sh.
    */
diff --git a/core/modules/system/src/Tests/TypedData/TypedDataTest.php b/core/modules/system/src/Tests/TypedData/TypedDataTest.php
index bc9bd8c..7413592 100644
--- a/core/modules/system/src/Tests/TypedData/TypedDataTest.php
+++ b/core/modules/system/src/Tests/TypedData/TypedDataTest.php
@@ -273,12 +273,12 @@ public function testGetAndSet() {
     $this->assertEqual($typed_data->validate()->count(), 0);
     // Try setting by URI.
     $typed_data->setValue($files[1]->getFileUri());
-    $this->assertEqual(is_resource($typed_data->getValue()), fopen($files[1]->getFileUri(), 'r'), 'Binary value was changed.');
+    $this->assertEqual(fgets($typed_data->getValue()), fgets(fopen($files[1]->getFileUri(), 'r')), 'Binary value was changed.');
     $this->assertTrue(is_string($typed_data->getString()), 'Binary value was converted to string');
     $this->assertEqual($typed_data->validate()->count(), 0);
     // Try setting by resource.
     $typed_data->setValue(fopen($files[2]->getFileUri(), 'r'));
-    $this->assertEqual(is_resource($typed_data->getValue()), fopen($files[2]->getFileUri(), 'r'), 'Binary value was changed.');
+    $this->assertEqual(fgets($typed_data->getValue()), fgets(fopen($files[2]->getFileUri(), 'r')), 'Binary value was changed.');
     $this->assertTrue(is_string($typed_data->getString()), 'Binary value was converted to string');
     $this->assertEqual($typed_data->validate()->count(), 0);
     $typed_data->setValue(NULL);
diff --git a/core/modules/text/src/Tests/Formatter/TextFormatterTest.php b/core/modules/text/src/Tests/Formatter/TextFormatterTest.php
index 4d99767..143928a 100644
--- a/core/modules/text/src/Tests/Formatter/TextFormatterTest.php
+++ b/core/modules/text/src/Tests/Formatter/TextFormatterTest.php
@@ -119,7 +119,6 @@ public function testFormatters() {
 
       // Verify the unprocessed text field formatter's render array.
       $build = $entity->get('unprocessed_text')->view(array('type' => $formatter));
-      debug($build[0]);
       $this->assertEqual($build[0]['#markup'], 'Hello, world!');
       $this->assertTrue(!isset($build[0]['#cache']), format_string('The @formatter formatter has the expected cache tags when formatting an unprocessed text field.', array('@formatter' => $formatter)));
     }
diff --git a/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php b/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php
index 167bcec..3af2dce 100644
--- a/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php
+++ b/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php
@@ -30,6 +30,71 @@ class TextPlainUnitTest extends DrupalUnitTestBase {
    */
   public static $modules = array('entity', 'field', 'text', 'entity_test', 'system', 'filter', 'user');
 
+  /**
+   * @var string
+   */
+  protected $entity_type;
+
+  /**
+   * @var string
+   */
+  protected $bundle;
+
+  /**
+   * @var string
+   */
+  protected $field_name;
+
+  /**
+   * @var string
+   */
+  protected $field_type;
+
+  /**
+   * @var array
+   */
+  protected $field_settings;
+
+  /**
+   * @var array
+   */
+  protected $instance_settings;
+
+  /**
+   * @var string
+   */
+  protected $formatter_type;
+
+  /**
+   * @var array
+   */
+  protected $formatter_settings;
+
+  /**
+   * @var \Drupal\field\Entity\FieldStorageConfig
+   */
+  protected $fieldStorage;
+
+  /**
+   * @var \Drupal\field\Entity\FieldInstanceConfig
+   */
+  protected $instance;
+
+  /**
+   * @var string
+   */
+  protected $view_mode;
+
+  /**
+   * @var \Drupal\entity\Entity\EntityViewDisplay
+   */
+  protected $display;
+
+  /**
+   * @var string
+   */
+  protected $langcode;
+
   function setUp() {
     parent::setUp();
 
diff --git a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php
index 47849b9..492218f 100644
--- a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php
+++ b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php
@@ -30,6 +30,7 @@ class UserAccountFormFieldsTest extends DrupalUnitTestBase {
    */
   function testInstallConfigureForm() {
     require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
+    require_once DRUPAL_ROOT . '/core/includes/install.inc';
     $install_state = install_state_defaults();
     $form_state = new FormState();
     $form_state['build_info']['args'][] = &$install_state;
diff --git a/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php b/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php
index 3c29b9e..8eb006d 100644
--- a/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php
+++ b/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php
@@ -24,7 +24,7 @@ class RowEntityRenderersTest extends ViewUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('entity', 'field', 'filter', 'text', 'node', 'user', 'language', 'menu_link');
+  public static $modules = array('entity', 'field', 'filter', 'text', 'node', 'user', 'language');
 
   /**
    * Views used by this test.
diff --git a/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php
index cdd1626..e019168 100644
--- a/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php
+++ b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php
@@ -23,6 +23,11 @@
   public static $modules = array('system', 'user', 'entity', 'field');
 
   /**
+   * @var \Drupal\user\Entity\User
+   */
+  protected $root_user;
+
+  /**
    * Overrides \Drupal\views\Tests\ViewUnitTestBase::setUpFixtures().
    */
   protected function setUpFixtures() {
diff --git a/core/modules/views/src/Tests/Plugin/RowEntityTest.php b/core/modules/views/src/Tests/Plugin/RowEntityTest.php
index 6fb65d3..583fb61 100644
--- a/core/modules/views/src/Tests/Plugin/RowEntityTest.php
+++ b/core/modules/views/src/Tests/Plugin/RowEntityTest.php
@@ -24,7 +24,7 @@ class RowEntityTest extends ViewUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('taxonomy', 'text', 'filter', 'field', 'entity', 'system', 'menu_link');
+  public static $modules = array('taxonomy', 'text', 'filter', 'field', 'entity', 'system');
 
   /**
    * Views used by this test.
diff --git a/core/modules/views/src/Tests/ViewExecutableTest.php b/core/modules/views/src/Tests/ViewExecutableTest.php
index 11a1b7f..fd7f628 100644
--- a/core/modules/views/src/Tests/ViewExecutableTest.php
+++ b/core/modules/views/src/Tests/ViewExecutableTest.php
@@ -30,7 +30,7 @@
  */
 class ViewExecutableTest extends ViewUnitTestBase {
 
-  public static $modules = array('system', 'node', 'comment', 'user', 'filter', 'entity', 'field', 'field_sql_storage', 'text');
+  public static $modules = array('system', 'node', 'comment', 'user', 'filter', 'entity', 'field', 'text');
 
   /**
    * Views used by this test.
diff --git a/core/modules/views/src/Tests/ViewStorageTest.php b/core/modules/views/src/Tests/ViewStorageTest.php
index 08c9e27..fc78a9e 100644
--- a/core/modules/views/src/Tests/ViewStorageTest.php
+++ b/core/modules/views/src/Tests/ViewStorageTest.php
@@ -186,7 +186,6 @@ protected function displayTests() {
    */
   protected function displayMethodTests() {
     // Enable the system module so l() can work using url_alias table.
-    $this->enableModules(array('system'));
     $this->installSchema('system', 'url_alias');
 
     $config['display'] = array(
diff --git a/core/modules/views/src/Tests/Wizard/WizardPluginBaseUnitTest.php b/core/modules/views/src/Tests/Wizard/WizardPluginBaseUnitTest.php
index 97807b2..9f2ab31 100644
--- a/core/modules/views/src/Tests/Wizard/WizardPluginBaseUnitTest.php
+++ b/core/modules/views/src/Tests/Wizard/WizardPluginBaseUnitTest.php
@@ -25,7 +25,7 @@ class WizardPluginBaseUnitTest extends ViewUnitTestBase {
    *
    * @var array
    */
-  public static $modules = array('language', 'system', 'user');
+  public static $modules = array('language', 'system', 'user', 'views_ui');
 
   /**
    * Contains thw wizard plugin manager.
@@ -39,8 +39,6 @@ protected function setUp() {
 
     $this->installConfig(array('language'));
 
-    $this->enableModules(array('views_ui'));
-
     $this->wizard = $this->container->get('plugin.manager.views.wizard')->createInstance('standard:views_test_data', array());
   }
 
-- 
1.7.11.msysgit.1


From 569ab0ed0ac61d74ef10b0d0dc45a866df8494c7 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 27 Jul 2014 02:21:02 +0200
Subject: [PATCH 06/29] Issue #2304461 by sun: Updated File API tests.

---
 core/modules/file/src/Tests/FileManagedUnitTestBase.php       |  2 ++
 core/modules/file/src/Tests/ValidatorTest.php                 |  1 +
 core/modules/system/src/Tests/File/DirectoryTest.php          | 10 ++++++----
 core/modules/system/src/Tests/File/FileTestBase.php           | 11 ++++++++---
 core/modules/system/src/Tests/File/HtaccessUnitTest.php       |  5 +++--
 .../modules/system/src/Tests/File/RemoteFileDirectoryTest.php |  7 -------
 .../system/src/Tests/File/RemoteFileScanDirectoryTest.php     |  7 -------
 .../system/src/Tests/File/RemoteFileUnmanagedCopyTest.php     |  7 -------
 .../src/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php |  7 -------
 .../system/src/Tests/File/RemoteFileUnmanagedDeleteTest.php   |  7 -------
 .../system/src/Tests/File/RemoteFileUnmanagedMoveTest.php     |  7 -------
 .../system/src/Tests/File/RemoteFileUnmanagedSaveDataTest.php |  7 -------
 core/modules/system/src/Tests/File/StreamWrapperTest.php      |  7 -------
 13 files changed, 20 insertions(+), 65 deletions(-)

diff --git a/core/modules/file/src/Tests/FileManagedUnitTestBase.php b/core/modules/file/src/Tests/FileManagedUnitTestBase.php
index dfa2234..4655374 100644
--- a/core/modules/file/src/Tests/FileManagedUnitTestBase.php
+++ b/core/modules/file/src/Tests/FileManagedUnitTestBase.php
@@ -32,6 +32,8 @@ function setUp() {
     $this->installEntitySchema('file');
     $this->installEntitySchema('user');
     $this->installSchema('file', array('file_usage'));
+    // @todo system_cron() hard-codes database queries operating on 'queue'.
+    $this->installSchema('system', array('queue'));
 
     // Make sure that a user with uid 1 exists, self::createFile() relies on
     // it.
diff --git a/core/modules/file/src/Tests/ValidatorTest.php b/core/modules/file/src/Tests/ValidatorTest.php
index 6176225..5479129 100644
--- a/core/modules/file/src/Tests/ValidatorTest.php
+++ b/core/modules/file/src/Tests/ValidatorTest.php
@@ -99,6 +99,7 @@ function testFileValidateImageResolution() {
       // Once again, now with negative width and height to force an error.
       copy('core/misc/druplicon.png', 'temporary://druplicon.png');
       $this->image->setFileUri('temporary://druplicon.png');
+      $this->setExpectedLogMessage(WATCHDOG_WARNING, "Invalid width (%i) specified for the image 'scale' operation");
       $errors = file_validate_image_resolution($this->image, '-10x-5');
       $this->assertEqual(count($errors), 1, 'An error reported for an oversized image that can not be scaled down.', 'File');
 
diff --git a/core/modules/system/src/Tests/File/DirectoryTest.php b/core/modules/system/src/Tests/File/DirectoryTest.php
index b402227..fb2c92b 100644
--- a/core/modules/system/src/Tests/File/DirectoryTest.php
+++ b/core/modules/system/src/Tests/File/DirectoryTest.php
@@ -46,9 +46,11 @@ function testFileCheckLocalDirectoryHandling() {
     $this->assertDirectoryPermissions($directory, $old_mode);
 
     // Check creating a directory using an absolute path.
-    $absolute_path = drupal_realpath($directory) . '/' . $this->randomMachineName() . '/' . $this->randomMachineName();
-    $this->assertTrue(drupal_mkdir($absolute_path, 0775, TRUE), 'No error reported when creating new absolute directories.', 'File');
-    $this->assertDirectoryPermissions($absolute_path, 0775);
+    if ($absolute_path = drupal_realpath($directory)) {
+      $absolute_path = $absolute_path . '/' . $this->randomMachineName() . '/' . $this->randomMachineName();
+      $this->assertTrue(drupal_mkdir($absolute_path, 0775, TRUE), 'No error reported when creating new absolute directories.', 'File');
+      $this->assertDirectoryPermissions($absolute_path, 0775);
+    }
   }
 
   /**
@@ -68,7 +70,7 @@ function testFileCheckDirectoryHandling() {
     // Make sure directory actually exists.
     $this->assertTrue(is_dir($directory), 'Directory actually exists.', 'File');
 
-    if (substr(PHP_OS, 0, 3) != 'WIN') {
+    if (substr(PHP_OS, 0, 3) != 'WIN' || !realpath($directory)) {
       // PHP on Windows doesn't support any kind of useful read-only mode for
       // directories. When executing a chmod() on a directory, PHP only sets the
       // read-only flag, which doesn't prevent files to actually be written
diff --git a/core/modules/system/src/Tests/File/FileTestBase.php b/core/modules/system/src/Tests/File/FileTestBase.php
index d939255..6a063d4 100644
--- a/core/modules/system/src/Tests/File/FileTestBase.php
+++ b/core/modules/system/src/Tests/File/FileTestBase.php
@@ -41,7 +41,10 @@ function setUp() {
     $this->installConfig(array('system'));
     $this->registerStreamWrapper('private', 'Drupal\Core\StreamWrapper\PrivateStream');
 
-    if (isset($this->scheme)) {
+    // hook_stream_wrappers() of enabled $modules gets invoked already. Only
+    // register a custom test stream wrapper if both a scheme and a class have
+    // been provided.
+    if (isset($this->scheme) && isset($this->classname)) {
       $this->registerStreamWrapper($this->scheme, $this->classname);
     }
   }
@@ -68,7 +71,8 @@ function assertFilePermissions($filepath, $expected_mode, $message = NULL) {
     // read/write/execute bits. On Windows, chmod() ignores the "group" and
     // "other" bits, and fileperms() returns the "user" bits in all three
     // positions. $expected_mode is updated to reflect this.
-    if (substr(PHP_OS, 0, 3) == 'WIN') {
+    // This only affects real files that exist in the local filesystem.
+    if (substr(PHP_OS, 0, 3) == 'WIN' && realpath($filepath)) {
       // Reset the "group" and "other" bits.
       $expected_mode = $expected_mode & 0700;
       // Shift the "user" bits to the "group" and "other" positions also.
@@ -104,7 +108,8 @@ function assertDirectoryPermissions($directory, $expected_mode, $message = NULL)
     // read/write/execute bits. On Windows, chmod() ignores the "group" and
     // "other" bits, and fileperms() returns the "user" bits in all three
     // positions. $expected_mode is updated to reflect this.
-    if (substr(PHP_OS, 0, 3) == 'WIN') {
+    // This only affects real files that exist in the local filesystem.
+    if (substr(PHP_OS, 0, 3) == 'WIN' && realpath($directory)) {
       // Reset the "group" and "other" bits.
       $expected_mode = $expected_mode & 0700;
       // Shift the "user" bits to the "group" and "other" positions also.
diff --git a/core/modules/system/src/Tests/File/HtaccessUnitTest.php b/core/modules/system/src/Tests/File/HtaccessUnitTest.php
index 4fb7fed..2ac2bfa 100644
--- a/core/modules/system/src/Tests/File/HtaccessUnitTest.php
+++ b/core/modules/system/src/Tests/File/HtaccessUnitTest.php
@@ -22,8 +22,8 @@ class HtaccessUnitTest extends DrupalUnitTestBase {
    */
   function testHtaccessSave() {
     // Prepare test directories.
-    $public = $this->public_files_directory . '/test/public';
-    $private = $this->public_files_directory . '/test/private';
+    $public = $this->siteDirectory . '/files/test/public';
+    $private = $this->siteDirectory . '/files/test/private';
     $stream = 'public://test/stream';
 
     // Verify that file_save_htaccess() returns FALSE if .htaccess cannot be
@@ -31,6 +31,7 @@ function testHtaccessSave() {
     // Note: We cannot test the condition of a directory lacking write
     // permissions, since at least on Windows file_save_htaccess() succeeds
     // even when changing directory permissions to 0000.
+    $this->setExpectedLogMessage(WATCHDOG_ERROR, "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %s directory which contains the following lines: %a");
     $this->assertFalse(file_save_htaccess($public, FALSE));
 
     // Create public .htaccess file.
diff --git a/core/modules/system/src/Tests/File/RemoteFileDirectoryTest.php b/core/modules/system/src/Tests/File/RemoteFileDirectoryTest.php
index 8ebe597..4400fb6 100644
--- a/core/modules/system/src/Tests/File/RemoteFileDirectoryTest.php
+++ b/core/modules/system/src/Tests/File/RemoteFileDirectoryTest.php
@@ -28,13 +28,6 @@ class RemoteFileDirectoryTest extends DirectoryTest {
    */
   protected $scheme = 'dummy-remote';
 
-  /**
-   * A fully-qualified stream wrapper class name to register for the test.
-   *
-   * @var string
-   */
-  protected $classname = 'Drupal\file_test\DummyRemoteStreamWrapper';
-
   function setUp() {
     parent::setUp();
     \Drupal::config('system.file')->set('default_scheme', 'dummy-remote')->save();
diff --git a/core/modules/system/src/Tests/File/RemoteFileScanDirectoryTest.php b/core/modules/system/src/Tests/File/RemoteFileScanDirectoryTest.php
index f09e299..4b335c2 100644
--- a/core/modules/system/src/Tests/File/RemoteFileScanDirectoryTest.php
+++ b/core/modules/system/src/Tests/File/RemoteFileScanDirectoryTest.php
@@ -28,13 +28,6 @@ class RemoteFileScanDirectoryTest extends ScanDirectoryTest {
    */
   protected $scheme = 'dummy-remote';
 
-  /**
-   * A fully-qualified stream wrapper class name to register for the test.
-   *
-   * @var string
-   */
-  protected $classname = 'Drupal\file_test\DummyRemoteStreamWrapper';
-
   function setUp() {
     parent::setUp();
     \Drupal::config('system.file')->set('default_scheme', 'dummy-remote')->save();
diff --git a/core/modules/system/src/Tests/File/RemoteFileUnmanagedCopyTest.php b/core/modules/system/src/Tests/File/RemoteFileUnmanagedCopyTest.php
index 18828a1..2878de6 100644
--- a/core/modules/system/src/Tests/File/RemoteFileUnmanagedCopyTest.php
+++ b/core/modules/system/src/Tests/File/RemoteFileUnmanagedCopyTest.php
@@ -28,13 +28,6 @@ class RemoteFileUnmanagedCopyTest extends UnmanagedCopyTest {
    */
   protected $scheme = 'dummy-remote';
 
-  /**
-   * A fully-qualified stream wrapper class name to register for the test.
-   *
-   * @var string
-   */
-  protected $classname = 'Drupal\file_test\DummyRemoteStreamWrapper';
-
   function setUp() {
     parent::setUp();
     \Drupal::config('system.file')->set('default_scheme', 'dummy-remote')->save();
diff --git a/core/modules/system/src/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php b/core/modules/system/src/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php
index cb81a60..f27f624 100644
--- a/core/modules/system/src/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php
+++ b/core/modules/system/src/Tests/File/RemoteFileUnmanagedDeleteRecursiveTest.php
@@ -28,13 +28,6 @@ class RemoteFileUnmanagedDeleteRecursiveTest extends UnmanagedDeleteRecursiveTes
    */
   protected $scheme = 'dummy-remote';
 
-  /**
-   * A fully-qualified stream wrapper class name to register for the test.
-   *
-   * @var string
-   */
-  protected $classname = 'Drupal\file_test\DummyRemoteStreamWrapper';
-
   function setUp() {
     parent::setUp();
     \Drupal::config('system.file')->set('default_scheme', 'dummy-remote')->save();
diff --git a/core/modules/system/src/Tests/File/RemoteFileUnmanagedDeleteTest.php b/core/modules/system/src/Tests/File/RemoteFileUnmanagedDeleteTest.php
index 4247cd4..10f3ba9 100644
--- a/core/modules/system/src/Tests/File/RemoteFileUnmanagedDeleteTest.php
+++ b/core/modules/system/src/Tests/File/RemoteFileUnmanagedDeleteTest.php
@@ -28,13 +28,6 @@ class RemoteFileUnmanagedDeleteTest extends UnmanagedDeleteTest {
    */
   protected $scheme = 'dummy-remote';
 
-  /**
-   * A fully-qualified stream wrapper class name to register for the test.
-   *
-   * @var string
-   */
-  protected $classname = 'Drupal\file_test\DummyRemoteStreamWrapper';
-
   function setUp() {
     parent::setUp();
     \Drupal::config('system.file')->set('default_scheme', 'dummy-remote')->save();
diff --git a/core/modules/system/src/Tests/File/RemoteFileUnmanagedMoveTest.php b/core/modules/system/src/Tests/File/RemoteFileUnmanagedMoveTest.php
index 9714778..b7afa7c 100644
--- a/core/modules/system/src/Tests/File/RemoteFileUnmanagedMoveTest.php
+++ b/core/modules/system/src/Tests/File/RemoteFileUnmanagedMoveTest.php
@@ -28,13 +28,6 @@ class RemoteFileUnmanagedMoveTest extends UnmanagedMoveTest {
    */
   protected $scheme = 'dummy-remote';
 
-  /**
-   * A fully-qualified stream wrapper class name to register for the test.
-   *
-   * @var string
-   */
-  protected $classname = 'Drupal\file_test\DummyRemoteStreamWrapper';
-
   function setUp() {
     parent::setUp();
     \Drupal::config('system.file')->set('default_scheme', 'dummy-remote')->save();
diff --git a/core/modules/system/src/Tests/File/RemoteFileUnmanagedSaveDataTest.php b/core/modules/system/src/Tests/File/RemoteFileUnmanagedSaveDataTest.php
index 47686ac..dfc420e 100644
--- a/core/modules/system/src/Tests/File/RemoteFileUnmanagedSaveDataTest.php
+++ b/core/modules/system/src/Tests/File/RemoteFileUnmanagedSaveDataTest.php
@@ -28,13 +28,6 @@ class RemoteFileUnmanagedSaveDataTest extends UnmanagedSaveDataTest {
    */
   protected $scheme = 'dummy-remote';
 
-  /**
-   * A fully-qualified stream wrapper class name to register for the test.
-   *
-   * @var string
-   */
-  protected $classname = 'Drupal\file_test\DummyRemoteStreamWrapper';
-
   function setUp() {
     parent::setUp();
     \Drupal::config('system.file')->set('default_scheme', 'dummy-remote')->save();
diff --git a/core/modules/system/src/Tests/File/StreamWrapperTest.php b/core/modules/system/src/Tests/File/StreamWrapperTest.php
index 755e988..dd8efe8 100644
--- a/core/modules/system/src/Tests/File/StreamWrapperTest.php
+++ b/core/modules/system/src/Tests/File/StreamWrapperTest.php
@@ -17,13 +17,6 @@
 class StreamWrapperTest extends FileTestBase {
 
   /**
-   * Modules to enable.
-   *
-   * @var array
-   */
-  public static $modules = array('file_test');
-
-  /**
    * A stream wrapper scheme to register for the test.
    *
    * @var string
-- 
1.7.11.msysgit.1


From 8b989d8703147460d602d573094da21ceae8db82 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Thu, 31 Jul 2014 21:16:48 +0200
Subject: [PATCH 07/29] Issue #2304461 by sun: Updated Database tests.

---
 .../system/src/Tests/Database/DatabaseTestBase.php | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/core/modules/system/src/Tests/Database/DatabaseTestBase.php b/core/modules/system/src/Tests/Database/DatabaseTestBase.php
index da14f5c..13dc1ec 100644
--- a/core/modules/system/src/Tests/Database/DatabaseTestBase.php
+++ b/core/modules/system/src/Tests/Database/DatabaseTestBase.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\system\Tests\Database;
 
+use Drupal\Core\Database\Database;
 use Drupal\simpletest\DrupalUnitTestBase;
 
 /**
@@ -19,6 +20,11 @@
 
   public static $modules = array('database_test');
 
+  /**
+   * @var string
+   */
+  protected $sqliteDb;
+
   function setUp() {
     parent::setUp();
     $this->installSchema('database_test', array(
@@ -35,6 +41,37 @@ function setUp() {
   }
 
   /**
+   * {@inheritdoc}
+   *
+   * - SQLite :memory: creates a new database for each connection.
+   * - PHP's SQLite extension does not support stream wrappers.
+   * - Shared in-memory database DSNs trigger open_basedir restrictions.
+   *
+   * Therefore, create a real database file on disk.
+   *
+   * @see http://www.sqlite.org/inmemorydb.html
+   * @see https://bugs.php.net/bug.php?id=55154
+   */
+  protected function getDatabaseConnectionInfo() {
+    $this->sqliteDb = tempnam(sys_get_temp_dir(), 'sql');
+
+    $databases['default']['default'] = array(
+      'driver' => 'sqlite',
+      'namespace' => 'Drupal\\Core\\Database\\Driver\\sqlite',
+      'database' => $this->sqliteDb,
+    );
+    return $databases;
+  }
+
+  protected function tearDown() {
+    // Tear down all database connections and the container first.
+    parent::tearDown();
+    // Permission denied on Windows.
+    @unlink($this->sqliteDb);
+    unset($this->sqliteDb);
+  }
+
+  /**
    * Sets up tables for NULL handling.
    */
   function ensureSampleDataNull() {
-- 
1.7.11.msysgit.1


From 5538adcc98013d91a50ea40b8e3b802d51625920 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Thu, 31 Jul 2014 23:13:15 +0200
Subject: [PATCH 08/29] Issue #2304461 by sun: Updated ModuleHandlerTest.

---
 .../src/Tests/Extension/ModuleHandlerTest.php      | 26 +++++++++-------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php
index 820e4aa..9b0e40e 100644
--- a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php
+++ b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php
@@ -23,6 +23,11 @@ class ModuleHandlerTest extends KernelTestBase {
    */
   public static $modules = array('system');
 
+  protected function setUp() {
+    parent::setUp();
+    require_once DRUPAL_ROOT . '/core/includes/install.inc';
+  }
+
   /**
    * {@inheritdoc}
    */
@@ -37,24 +42,14 @@ public function containerBuild(ContainerBuilder $container) {
    * The basic functionality of retrieving enabled modules.
    */
   function testModuleList() {
-    // Build a list of modules, sorted alphabetically.
-    $profile_info = install_profile_info('testing', 'en');
-    $module_list = $profile_info['dependencies'];
+    $module_list = array();
+    $module_list[] = 'system';
 
-    // Installation profile is a module that is expected to be loaded.
-    $module_list[] = 'testing';
-
-    sort($module_list);
-    // Compare this list to the one returned by the module handler. We expect
-    // them to match, since all default profile modules have a weight equal to 0
-    // (except for block.module, which has a lower weight but comes first in
-    // the alphabet anyway).
-    $this->assertModuleList($module_list, 'Testing profile');
+    $this->assertModuleList($module_list, 'Initial');
 
     // Try to install a new module.
     $this->moduleHandler()->install(array('ban'));
-    $module_list[] = 'ban';
-    sort($module_list);
+    array_unshift($module_list, 'ban');
     $this->assertModuleList($module_list, 'After adding a module');
 
     // Try to mess with the module weights.
@@ -85,8 +80,7 @@ function testModuleList() {
   protected function assertModuleList(Array $expected_values, $condition) {
     $expected_values = array_values(array_unique($expected_values));
     $enabled_modules = array_keys($this->container->get('module_handler')->getModuleList());
-    $enabled_modules = sort($enabled_modules);
-    $this->assertEqual($expected_values, $enabled_modules, format_string('@condition: extension handler returns correct results', array('@condition' => $condition)));
+    $this->assertIdentical($enabled_modules, $expected_values, format_string('@condition: extension handler returns correct results', array('@condition' => $condition)));
   }
 
   /**
-- 
1.7.11.msysgit.1


From 4b77e886a2ee2f9e35c1061aa792df566a053d1d Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Fri, 1 Aug 2014 20:53:18 +0200
Subject: [PATCH 09/29] Issue #2304461 by sun: Fixed bogus error reporting in
 ViewExecutable.

---
 core/modules/views/src/Tests/ViewExecutableTest.php | 13 +++++++++----
 core/modules/views/src/ViewExecutable.php           |  2 +-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/core/modules/views/src/Tests/ViewExecutableTest.php b/core/modules/views/src/Tests/ViewExecutableTest.php
index fd7f628..436b357 100644
--- a/core/modules/views/src/Tests/ViewExecutableTest.php
+++ b/core/modules/views/src/Tests/ViewExecutableTest.php
@@ -227,10 +227,15 @@ public function testDisplays() {
     // Destroy the view, so we can start again and test an invalid display.
     $view->destroy();
 
-    $count_before = count($this->assertions);
-    $view->setDisplay('invalid');
-    $count_after = count($this->assertions);
-    $this->assertTrue($count_after - $count_before, 'Error is triggered while calling the wrong display.');
+    try {
+      $error_triggered = FALSE;
+      $view->setDisplay('invalid');
+    }
+    catch (\PHPUnit_Framework_Error $e) {
+      $error_triggered = TRUE;
+      $this->assertEqual("setDisplay() called with invalid display ID 'invalid'", $e->getMessage());
+    }
+    $this->assertTrue($error_triggered, 'Error is triggered while calling the wrong display.');
 
     $this->assertEqual($view->current_display, 'default', 'If setDisplay is called with an invalid display id the default display should be used.');
     $this->assertEqual(spl_object_hash($view->display_handler), spl_object_hash($view->displayHandlers->get('default')));
diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php
index d81680e..65255c1 100644
--- a/core/modules/views/src/ViewExecutable.php
+++ b/core/modules/views/src/ViewExecutable.php
@@ -692,7 +692,7 @@ public function setDisplay($display_id = NULL) {
 
     // Ensure the requested display exists.
     if (!$this->displayHandlers->has($display_id)) {
-      debug(format_string('setDisplay() called with invalid display ID "@display".', array('@display' => $display_id)));
+      trigger_error(sprintf("setDisplay() called with invalid display ID '%s'", $display_id), E_USER_ERROR);
       return FALSE;
     }
 
-- 
1.7.11.msysgit.1


From 0b8f0e6a2cf909fac9d6e468da3ee306ce9ab33a Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 3 Aug 2014 18:23:51 +0200
Subject: [PATCH 10/29] Issue #2304461 by sun: Updated DrupalKernelTest.

---
 .../src/Tests/DrupalKernel/DrupalKernelTest.php    | 28 ++++++++--------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php
index d92ef59..94b92ff 100644
--- a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php
+++ b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php
@@ -16,30 +16,22 @@
  * Tests DIC compilation to disk.
  *
  * @group DrupalKernel
+ * @runTestsInSeparateProcesses
  */
 class DrupalKernelTest extends DrupalUnitTestBase {
 
-  /**
-   * @var \Composer\Autoload\ClassLoader
-   */
-  protected $classloader;
-
-  function setUp() {
-    // DrupalKernel relies on global $config_directories and requires those
-    // directories to exist. Therefore, create the directories, but do not
-    // invoke KernelTestBase::setUp(), since that would set up further
-    // environment aspects, which would distort this test, because it tests
-    // the DrupalKernel (re-)building itself.
-    $this->prepareConfigDirectories();
+  protected function setUp() {
+    // DrupalKernel requires config directories to exist. Therefore, boot the
+    // base test environment, but do not invoke KernelTestBase::bootKernel(),
+    // since that would distort this test, as it tests DrupalKernel itself.
+    $this->bootEnvironment();
 
     $this->settingsSet('php_storage', array('service_container' => array(
       'bin' => 'service_container',
       'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage',
-      'directory' => DRUPAL_ROOT . '/' . $this->public_files_directory . '/php',
+      'directory' => $this->siteDirectory . '/php',
       'secret' => Settings::getHashSalt(),
     )));
-
-    $this->classloader = drupal_classloader();
   }
 
   /**
@@ -59,8 +51,8 @@ function setUp() {
    */
   protected function getTestKernel(Request $request, array $modules_enabled = NULL, $read_only = FALSE) {
     // Manually create kernel to avoid replacing settings.
-    $kernel = DrupalKernel::createFromRequest($request, drupal_classloader(), 'testing');
-    $this->settingsSet('hash_salt', $this->databasePrefix);
+    $kernel = new DrupalKernel('testing', $this->classLoader);
+    $kernel->setSitePath($this->siteDirectory);
     if (isset($modules_enabled)) {
       $kernel->updateModules($modules_enabled);
     }
@@ -69,7 +61,7 @@ protected function getTestKernel(Request $request, array $modules_enabled = NULL
     if ($read_only) {
       $php_storage = Settings::get('php_storage');
       $php_storage['service_container']['class'] = 'Drupal\Component\PhpStorage\FileReadOnlyStorage';
-      $this->settingsSet('php_storage', $php_storage);
+      $this->setSetting('php_storage', $php_storage);
     }
     return $kernel;
   }
-- 
1.7.11.msysgit.1


From d32a5065635ee6ceaa69e9a26e0c9d38b5b0c3fa Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Thu, 31 Jul 2014 19:35:05 +0200
Subject: [PATCH 11/29] [FIXME] PhpStorageFactory does not support stream
 wrappers.

---
 core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php     |  2 +-
 .../src/Tests/Cache/GenericCacheBackendUnitTestBase.php   |  4 ++--
 .../modules/system/src/Tests/Cache/PhpBackendUnitTest.php | 11 +++++++++++
 .../system/src/Tests/DrupalKernel/DrupalKernelTest.php    | 15 +++++++++------
 .../system/src/Tests/PhpStorage/PhpStorageFactoryTest.php |  2 +-
 5 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php b/core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php
index 3386bba..72d5f31 100644
--- a/core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php
+++ b/core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php
@@ -52,7 +52,7 @@ static function get($name) {
       $configuration['bin'] = $name;
     }
     if (!isset($configuration['directory'])) {
-      $configuration['directory'] = DRUPAL_ROOT . '/' . PublicStream::basePath() . '/php';
+      $configuration['directory'] = PublicStream::basePath() . '/php';
     }
     return new $class($configuration);
   }
diff --git a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php
index debff49..23ddbdc 100644
--- a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php
+++ b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php
@@ -106,7 +106,7 @@ protected function getCacheBackend($bin = null) {
     return $this->cachebackends[$bin];
   }
 
-  public function setUp() {
+  protected function setUp() {
     $this->cachebackends = array();
     $this->defaultValue = $this->randomMachineName(10);
 
@@ -115,7 +115,7 @@ public function setUp() {
     $this->setUpCacheBackend();
   }
 
-  public function tearDown() {
+  protected function tearDown() {
     // Destruct the registered backend, each test will get a fresh instance,
     // properly emptying it here ensure that on persistent data backends they
     // will come up empty the next test.
diff --git a/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php b/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php
index 57df19b..c535688 100644
--- a/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php
+++ b/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php
@@ -16,6 +16,17 @@
  */
 class PhpBackendUnitTest extends GenericCacheBackendUnitTestBase {
 
+  protected function setUp() {
+    parent::setUp();
+
+    $this->setSetting('php_storage', array(
+      'default' => array(
+        // tempnam() does not work with stream wrappers.
+        'class' => 'Drupal\Component\PhpStorage\FileStorage',
+      ),
+    ));
+  }
+
   /**
    * Creates a new instance of MemoryBackend.
    *
diff --git a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php
index 94b92ff..87a4cf1 100644
--- a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php
+++ b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php
@@ -26,12 +26,15 @@ protected function setUp() {
     // since that would distort this test, as it tests DrupalKernel itself.
     $this->bootEnvironment();
 
-    $this->settingsSet('php_storage', array('service_container' => array(
-      'bin' => 'service_container',
-      'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage',
-      'directory' => $this->siteDirectory . '/php',
-      'secret' => Settings::getHashSalt(),
-    )));
+    $this->setSetting('php_storage', array(
+      'service_container' => array(
+        'bin' => 'service_container',
+        // tempnam() does not work with stream wrappers.
+        'class' => 'Drupal\Component\PhpStorage\FileStorage',
+        'directory' => $this->siteDirectory . '/php',
+        'secret' => Settings::getHashSalt(),
+      ),
+    ));
   }
 
   /**
diff --git a/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php b/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php
index 166f3ff..26c4366 100644
--- a/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php
+++ b/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php
@@ -59,7 +59,7 @@ public function testGetOverride() {
     $this->setSettings('test', array('directory' => NULL));
     $php = PhpStorageFactory::get('test');
     $this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.');
-    $this->assertIdentical(DRUPAL_ROOT . '/' . PublicStream::basePath() . '/php', $php->getConfigurationValue('directory'), 'Default file directory was used.');
+    $this->assertIdentical(PublicStream::basePath() . '/php', $php->getConfigurationValue('directory'), 'Default file directory was used.');
 
     // Test that a default storage class is set if it's empty.
     $this->setSettings('test', array('class' => NULL));
-- 
1.7.11.msysgit.1


From 0298d129bfdeb7e50b8991e4faa6367f1ab86569 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Thu, 31 Jul 2014 23:12:01 +0200
Subject: [PATCH 12/29] [FIXME] drupal_rewrite_settings() does not support
 stream wrappers.

---
 core/includes/install.inc                                    | 4 ++--
 core/modules/system/src/Tests/System/SettingsRewriteTest.php | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/core/includes/install.inc b/core/includes/install.inc
index d1c1596..643d610 100644
--- a/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -209,7 +209,7 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) {
     }
     $variable_names['$'. $setting] = $setting;
   }
-  $contents = file_get_contents(DRUPAL_ROOT . '/' . $settings_file);
+  $contents = file_get_contents($settings_file);
   if ($contents !== FALSE) {
     // Initialize the contents for the settings.php file if it is empty.
     if (trim($contents) === '') {
@@ -314,7 +314,7 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) {
     }
 
     // Write the new settings file.
-    if (file_put_contents(DRUPAL_ROOT . '/' . $settings_file, $buffer) === FALSE) {
+    if (file_put_contents($settings_file, $buffer) === FALSE) {
       throw new Exception(t('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file)));
     }
     else {
diff --git a/core/modules/system/src/Tests/System/SettingsRewriteTest.php b/core/modules/system/src/Tests/System/SettingsRewriteTest.php
index 741f92c..6bf0bd7 100644
--- a/core/modules/system/src/Tests/System/SettingsRewriteTest.php
+++ b/core/modules/system/src/Tests/System/SettingsRewriteTest.php
@@ -100,9 +100,9 @@ function testDrupalRewriteSettings() {
     );
     foreach ($tests as $test) {
       $filename = Settings::get('file_public_path', conf_path() . '/files') . '/mock_settings.php';
-      file_put_contents(DRUPAL_ROOT . '/' . $filename, "<?php\n" . $test['original'] . "\n");
+      file_put_contents($filename, "<?php\n" . $test['original'] . "\n");
       drupal_rewrite_settings($test['settings'], $filename);
-      $this->assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
+      $this->assertEqual(file_get_contents($filename), "<?php\n" . $test['expected'] . "\n");
     }
 
     // Test that <?php gets added to the start of an empty settings file.
@@ -118,12 +118,12 @@ function testDrupalRewriteSettings() {
     );
     // Make an empty file.
     $filename = Settings::get('file_public_path', conf_path() . '/files') . '/mock_settings.php';
-    file_put_contents(DRUPAL_ROOT . '/' . $filename, "");
+    file_put_contents($filename, "");
 
     // Write the setting to the file.
     drupal_rewrite_settings($test['settings'], $filename);
 
     // Check that the result is just the php opening tag and the settings.
-    $this->assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
+    $this->assertEqual(file_get_contents($filename), "<?php\n" . $test['expected'] . "\n");
   }
 }
-- 
1.7.11.msysgit.1


From fdeba51c88ef8a19190259835a7647b5e6899542 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Fri, 1 Aug 2014 19:24:19 +0200
Subject: [PATCH 13/29] [FIXME] Config\FileStorage does not support stream
 wrappers.

---
 core/lib/Drupal/Core/Config/FileStorage.php | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php
index 88af39e..13f0207 100644
--- a/core/lib/Drupal/Core/Config/FileStorage.php
+++ b/core/lib/Drupal/Core/Config/FileStorage.php
@@ -200,19 +200,23 @@ public function decode($raw) {
    * Implements Drupal\Core\Config\StorageInterface::listAll().
    */
   public function listAll($prefix = '') {
-    // glob() silently ignores the error of a non-existing search directory,
-    // even with the GLOB_ERR flag.
     $dir = $this->getCollectionDirectory();
-    if (!file_exists($dir)) {
+    if (!is_dir($dir)) {
       return array();
     }
     $extension = '.' . static::getFileExtension();
-    // \GlobIterator on Windows requires an absolute path.
-    $files = new \GlobIterator(realpath($dir) . '/' . $prefix . '*' . $extension);
+
+    // glob() directly calls into libc glob(), which is not aware of PHP stream
+    // wrappers. Same for \GlobIterator (which additionally requires an absolute
+    // realpath() on Windows).
+    // @see https://github.com/mikey179/vfsStream/issues/2
+    $files = scandir($dir);
 
     $names = array();
     foreach ($files as $file) {
-      $names[] = $file->getBasename($extension);
+      if ($file[0] !== '.' && fnmatch($prefix . '*' . $extension, $file)) {
+        $names[] = basename($file, $extension);
+      }
     }
 
     return $names;
@@ -306,13 +310,15 @@ protected function getAllCollectionNamesHelper($directory) {
             $collections[] = $collection . '.' . $sub_collection;
           }
         }
-        // Check that the collection is valid by searching if for configuration
+        // Check that the collection is valid by searching it for configuration
         // objects. A directory without any configuration objects is not a valid
         // collection.
-        // \GlobIterator on Windows requires an absolute path.
-        $files = new \GlobIterator(realpath($directory . '/' . $collection) . '/*.' . $this->getFileExtension());
-        if (count($files)) {
-          $collections[] = $collection;
+        // @see \Drupal\Core\Config\FileStorage::listAll()
+        foreach (scandir($directory . '/' . $collection) as $file) {
+          if ($file[0] !== '.' && fnmatch('*.' . $this->getFileExtension(), $file)) {
+            $collections[] = $collection;
+            break;
+          }
         }
       }
     }
-- 
1.7.11.msysgit.1


From 1f50e0c07e53a680b0f9f0f1d563a0e2250b21ca Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Fri, 1 Aug 2014 21:57:07 +0200
Subject: [PATCH 14/29] Issue #2301245 by sun: Fixed Entity system invokes
 non-existing theme hooks: "Theme hook $entity_type_id
 not found.".

---
 core/includes/theme.inc                                        |  7 ++-----
 core/modules/block_content/src/BlockContentViewBuilder.php     |  9 +++++++++
 core/modules/contact/src/MessageViewBuilder.php                |  9 +++++++++
 .../tests/modules/entity_test/src/EntityTestViewBuilder.php    | 10 ++++++++++
 4 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index edcdad9..fb04c40 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -459,7 +459,7 @@ function _theme($hook, $variables = array()) {
       // Only log a message when not trying theme suggestions ($hook being an
       // array).
       if (!isset($candidate)) {
-        \Drupal::logger('theme')->warning('Theme hook %hook not found.', array('%hook' => $hook));
+        trigger_error(sprintf("Theme hook %s not found.", $hook), E_USER_ERROR);
       }
       // There is no theme implementation for the hook passed. Return FALSE so
       // the function calling _theme() can differentiate between a hook that
@@ -2468,10 +2468,7 @@ function template_preprocess_field_multiple_value_form(&$variables) {
       t('Order', array(), array('context' => 'Sort order')),
     );
     if (!empty($element['#required'])) {
-      $header[0]['data']['required'] = array(
-        '#theme' => 'form_required_marker',
-        '#element' => $element,
-      );
+      $header[0]['data']['#prefix'] = '<h4 class="label form-required">';
     }
     $rows = array();
 
diff --git a/core/modules/block_content/src/BlockContentViewBuilder.php b/core/modules/block_content/src/BlockContentViewBuilder.php
index 0977e9f..545dd91 100644
--- a/core/modules/block_content/src/BlockContentViewBuilder.php
+++ b/core/modules/block_content/src/BlockContentViewBuilder.php
@@ -19,6 +19,15 @@ class BlockContentViewBuilder extends EntityViewBuilder {
   /**
    * {@inheritdoc}
    */
+  protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) {
+    $build = parent::getBuildDefaults($entity, $view_mode, $langcode);
+    unset($build['#theme']);
+    return $build;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
   protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL) {
     parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
     // Add contextual links for this custom block.
diff --git a/core/modules/contact/src/MessageViewBuilder.php b/core/modules/contact/src/MessageViewBuilder.php
index 4cbbd2c..3295dbc 100644
--- a/core/modules/contact/src/MessageViewBuilder.php
+++ b/core/modules/contact/src/MessageViewBuilder.php
@@ -20,6 +20,15 @@ class MessageViewBuilder extends EntityViewBuilder {
   /**
    * {@inheritdoc}
    */
+  protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) {
+    $build = parent::getBuildDefaults($entity, $view_mode, $langcode);
+    unset($build['#theme']);
+    return $build;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
   public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) {
     parent::buildComponents($build, $entities, $displays, $view_mode, $langcode);
 
diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilder.php b/core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilder.php
index 535faff..3456512 100644
--- a/core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilder.php
+++ b/core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilder.php
@@ -8,6 +8,7 @@
 namespace Drupal\entity_test;
 
 use Drupal\Component\Utility\String;
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityViewBuilder;
 
 /**
@@ -20,6 +21,15 @@ class EntityTestViewBuilder extends EntityViewBuilder {
   /**
    * {@inheritdoc}
    */
+  protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) {
+    $build = parent::getBuildDefaults($entity, $view_mode, $langcode);
+    unset($build['#theme']);
+    return $build;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
   public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) {
     parent::buildComponents($build, $entities, $displays, $view_mode, $langcode);
 
-- 
1.7.11.msysgit.1


From 856cd6ed042419a011f91ca20cdba1360deddc31 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sat, 2 Aug 2014 00:16:12 +0200
Subject: [PATCH 15/29] Issue #2261477 by neclimdul, sun: Remove broken
 ScriptTest.

---
 .../modules/system/src/Tests/System/ScriptTest.php | 69 ----------------------
 core/scripts/password-hash.sh                      |  5 +-
 core/scripts/rebuild_token_calculator.sh           |  5 +-
 3 files changed, 2 insertions(+), 77 deletions(-)
 delete mode 100644 core/modules/system/src/Tests/System/ScriptTest.php

diff --git a/core/modules/system/src/Tests/System/ScriptTest.php b/core/modules/system/src/Tests/System/ScriptTest.php
deleted file mode 100644
index 6f6d871..0000000
--- a/core/modules/system/src/Tests/System/ScriptTest.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\system\Tests\System\ScriptTest.
- */
-
-namespace Drupal\system\Tests\System;
-
-use Drupal\simpletest\DrupalUnitTestBase;
-
-/**
- * Tests core shell scripts.
- *
- * @group system
- */
-class ScriptTest extends DrupalUnitTestBase {
-
-  protected function setUp() {
-    parent::setUp();
-    require_once DRUPAL_ROOT . '/core/includes/install.inc';
-  }
-
-  /**
-   * Tests password-hash.sh.
-   */
-  public function testPasswordHashSh() {
-    // The script requires a settings.php with a hash salt setting.
-    $filename = $this->siteDirectory . '/settings.php';
-    touch($filename);
-    $settings['settings']['hash_salt'] = (object) array(
-      'value' => 'some_random_key',
-      'required' => TRUE,
-    );
-    drupal_rewrite_settings($settings, $filename);
-    $_SERVER['argv'] = array(
-      'core/scripts/password-hash.sh',
-      'xyz',
-    );
-    ob_start();
-    include DRUPAL_ROOT . '/core/scripts/password-hash.sh';
-    $this->setRawContent(ob_get_contents());
-    ob_end_clean();
-    $this->assertRaw('hash: $S$');
-  }
-
-  /**
-   * Tests rebuild_token_calculator.sh.
-   */
-  public function testRebuildTokenCalculatorSh() {
-    // The script requires a settings.php with a hash salt setting.
-    $filename = $this->siteDirectory . '/settings.php';
-    touch($filename);
-    $settings['settings']['hash_salt'] = (object) array(
-      'value' => 'some_random_key',
-      'required' => TRUE,
-    );
-    drupal_rewrite_settings($settings, $filename);
-    $_SERVER['argv'] = array(
-      'core/scripts/rebuild_token_calculator.sh',
-    );
-    ob_start();
-    include DRUPAL_ROOT . '/core/scripts/rebuild_token_calculator.sh';
-    $this->setRawContent(ob_get_contents());
-    ob_end_clean();
-    $this->assertRaw('token=');
-  }
-
-}
diff --git a/core/scripts/password-hash.sh b/core/scripts/password-hash.sh
index ee3c102..9e66a16 100755
--- a/core/scripts/password-hash.sh
+++ b/core/scripts/password-hash.sh
@@ -11,10 +11,7 @@
 use Drupal\Core\DrupalKernel;
 use Symfony\Component\HttpFoundation\Request;
 
-// Check for $_SERVER['argv'] instead of PHP_SAPI === 'cli' to allow this script
-// to be tested with the Simpletest UI test runner.
-// @see \Drupal\system\Tests\System\ScriptTest
-if (!isset($_SERVER['argv']) || !is_array($_SERVER['argv'])) {
+if (PHP_SAPI !== 'cli') {
   return;
 }
 
diff --git a/core/scripts/rebuild_token_calculator.sh b/core/scripts/rebuild_token_calculator.sh
index bcfd2b6..87c3069 100755
--- a/core/scripts/rebuild_token_calculator.sh
+++ b/core/scripts/rebuild_token_calculator.sh
@@ -11,10 +11,7 @@
 use Drupal\Core\Site\Settings;
 use Symfony\Component\HttpFoundation\Request;
 
-// Check for $_SERVER['argv'] instead of PHP_SAPI === 'cli' to allow this script
-// to be tested with the Simpletest UI test runner.
-// @see \Drupal\system\Tests\System\ScriptTest
-if (!isset($_SERVER['argv']) || !is_array($_SERVER['argv'])) {
+if (PHP_SAPI !== 'cli') {
   return;
 }
 
-- 
1.7.11.msysgit.1


From 0ee625dd377dff956f1969ee9601a1ad5fabfe20 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Mon, 4 Aug 2014 16:37:35 +0200
Subject: [PATCH 16/29] Issue #2304461 by sun: Use setExpectedLogMessage()
 where necessary.

---
 core/modules/system/src/Tests/Entity/EntityApiTest.php           | 2 ++
 core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php | 1 +
 core/modules/system/src/Tests/File/UnmanagedDeleteTest.php       | 1 +
 core/modules/system/src/Tests/Image/ToolkitGdTest.php            | 3 ++-
 core/modules/views/src/Tests/Handler/AreaTextTest.php            | 1 +
 core/modules/views/src/Tests/Plugin/DisplayPageTest.php          | 3 +++
 6 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/core/modules/system/src/Tests/Entity/EntityApiTest.php b/core/modules/system/src/Tests/Entity/EntityApiTest.php
index 1f2dfde..d1d2baf 100644
--- a/core/modules/system/src/Tests/Entity/EntityApiTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityApiTest.php
@@ -98,6 +98,7 @@ public function testEntityStorageExceptionHandling() {
     $entity = entity_create('entity_test', array('name' => 'test'));
     try {
       $GLOBALS['entity_test_throw_exception'] = TRUE;
+      $this->setExpectedLogMessage(WATCHDOG_ERROR, 'Exception: Entity presave exception in entity_test_entity_presave() %s');
       $entity->save();
       $this->fail('Entity presave EntityStorageException thrown but not caught.');
     }
@@ -119,6 +120,7 @@ public function testEntityStorageExceptionHandling() {
     $entity->save();
     try {
       $GLOBALS['entity_test_throw_exception'] = TRUE;
+      $this->setExpectedLogMessage(WATCHDOG_ERROR, 'Exception: Entity predelete exception in entity_test_entity_predelete() %s');
       $entity->delete();
       $this->fail('Entity predelete EntityStorageException not thrown.');
     }
diff --git a/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php b/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php
index c9cb68b..8eb9986 100644
--- a/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php
+++ b/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php
@@ -56,6 +56,7 @@ function testWriteFunctions() {
     $handle = fopen($uri, 'r');
     $this->assertTrue($handle, 'Able to open a file for reading with the read-only stream wrapper.');
     // Attempt to change file permissions
+    $this->setExpectedLogMessage(WATCHDOG_ERROR, 'The file permissions could not be set on dummy-readonly://%s');
     $this->assertFalse(@drupal_chmod($uri, 0777), 'Unable to change file permissions when using read-only stream wrapper.');
     // Attempt to acquire an exclusive lock for writing
     $this->assertFalse(@flock($handle, LOCK_EX | LOCK_NB), 'Unable to acquire an exclusive lock using the read-only stream wrapper.');
diff --git a/core/modules/system/src/Tests/File/UnmanagedDeleteTest.php b/core/modules/system/src/Tests/File/UnmanagedDeleteTest.php
index 4c649da..6f7eb5e 100644
--- a/core/modules/system/src/Tests/File/UnmanagedDeleteTest.php
+++ b/core/modules/system/src/Tests/File/UnmanagedDeleteTest.php
@@ -41,6 +41,7 @@ function testDirectory() {
     $directory = $this->createDirectory();
 
     // Try to delete a directory
+    $this->setExpectedLogMessage(WATCHDOG_ERROR, $this->scheme . '%s is a directory and cannot be removed using file_unmanaged_delete().');
     $this->assertFalse(file_unmanaged_delete($directory), 'Could not delete the delete directory.');
     $this->assertTrue(file_exists($directory), 'Directory has not been deleted.');
   }
diff --git a/core/modules/system/src/Tests/Image/ToolkitGdTest.php b/core/modules/system/src/Tests/Image/ToolkitGdTest.php
index 3d1542c..6a8c1cc 100644
--- a/core/modules/system/src/Tests/Image/ToolkitGdTest.php
+++ b/core/modules/system/src/Tests/Image/ToolkitGdTest.php
@@ -267,7 +267,7 @@ function testManipulations() {
           $correct_dimensions_object = FALSE;
         }
 
-        $directory = $this->public_files_directory .'/imagetest';
+        $directory = $this->siteDirectory . '/files/imagetest';
         file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
         $file_path = $directory . '/' . $op . image_type_to_extension($image->getToolkit()->getType());
         $image->save($file_path);
@@ -328,6 +328,7 @@ function testMissingOperation() {
     }
 
     // Try perform a missing toolkit operation.
+    $this->setExpectedLogMessage(WATCHDOG_ERROR, "The selected image handling toolkit 'gd' can not process operation 'missing_op'.");
     $this->assertFalse($image->apply('missing_op', array()), 'Calling a missing image toolkit operation plugin fails.');
   }
 
diff --git a/core/modules/views/src/Tests/Handler/AreaTextTest.php b/core/modules/views/src/Tests/Handler/AreaTextTest.php
index d0eaf14..7f64ea6 100644
--- a/core/modules/views/src/Tests/Handler/AreaTextTest.php
+++ b/core/modules/views/src/Tests/Handler/AreaTextTest.php
@@ -54,6 +54,7 @@ public function testAreaText() {
 
     $view->display_handler->handlers['header']['area']->options['format'] = $this->randomString();
     $build = $view->display_handler->handlers['header']['area']->render();
+    $this->setExpectedLogMessage(WATCHDOG_ALERT, 'Missing text format: %s');
     $this->assertEqual('', drupal_render($build), 'Nonexistent format should return empty markup.');
 
     $view->display_handler->handlers['header']['area']->options['format'] = filter_default_format();
diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php
index 97e5cb9..2229790 100644
--- a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php
+++ b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php
@@ -58,14 +58,17 @@ protected function setUp() {
   public function testPageResponses() {
     \Drupal::currentUser()->setAccount(new AnonymousUserSession());
     $subrequest = Request::create('/test_page_display_403', 'GET');
+    $this->setExpectedLogMessage(WATCHDOG_WARNING, 'test_page_display_403');
     $response = $this->container->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
     $this->assertEqual($response->getStatusCode(), 403);
 
     $subrequest = Request::create('/test_page_display_404', 'GET');
+    $this->setExpectedLogMessage(WATCHDOG_WARNING, 'test_page_display_404');
     $response = $this->container->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
     $this->assertEqual($response->getStatusCode(), 404);
 
     $subrequest = Request::create('/test_page_display_200', 'GET');
+    $this->setExpectedLogMessage(WATCHDOG_WARNING, 'test_page_display_200');
     $response = $this->container->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
     $this->assertEqual($response->getStatusCode(), 200);
 
-- 
1.7.11.msysgit.1


From f7a19a979ff54f4e086479e7e22ee3647575cab0 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 3 Aug 2014 19:11:37 +0200
Subject: [PATCH 17/29] Issue #2304461 by sun: Fixed
 EntityUnitTestBase::$entityManager references
 container.

---
 core/modules/system/src/Tests/Entity/EntityUnitTestBase.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php b/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
index bcc086c..dec6094 100644
--- a/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
+++ b/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
@@ -36,7 +36,7 @@
    */
   protected $state;
 
-  public function setUp() {
+  protected function setUp() {
     parent::setUp();
 
     $this->entityManager = $this->container->get('entity.manager');
@@ -50,6 +50,12 @@ public function setUp() {
     $this->installConfig(array('field'));
   }
 
+  protected function tearDown() {
+    $this->entityManager = NULL;
+    $this->state = NULL;
+    parent::tearDown();
+  }
+
   /**
    * Creates a user.
    *
-- 
1.7.11.msysgit.1


From b92cffe6ba40c634a43b9616b7ba2fe6e94b7f58 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 3 Aug 2014 22:08:36 +0200
Subject: [PATCH 18/29] Fixed SQLite does not interpret '\_' as string literal
 in LIKE without ESCAPE.

---
 core/lib/Drupal/Core/Config/DatabaseStorage.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php
index 20e5f1b..57293e5 100644
--- a/core/lib/Drupal/Core/Config/DatabaseStorage.php
+++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php
@@ -269,7 +269,7 @@ public function decode($raw) {
    */
   public function listAll($prefix = '') {
     try {
-      return $this->connection->query('SELECT name FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name LIKE :name', array(
+      return $this->connection->query('SELECT name FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name LIKE :name ESCAPE \'\\\'', array(
         ':collection' => $this->collection,
         ':name' => $this->connection->escapeLike($prefix) . '%',
       ), $this->options)->fetchCol();
-- 
1.7.11.msysgit.1


From e9508aba33c3de3d5bd923511d953949c7d1a0b3 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Mon, 4 Aug 2014 21:15:11 +0200
Subject: [PATCH 19/29] Fixed SQLite does not support CONCAT_WS().

---
 .../Core/Database/Driver/sqlite/Connection.php       | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
index 6cacf4e..82a1234 100644
--- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
+++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
@@ -122,6 +122,7 @@ public static function open(array &$connection_options = array()) {
     $pdo->sqliteCreateFunction('length', 'strlen', 1);
     $pdo->sqliteCreateFunction('md5', 'md5', 1);
     $pdo->sqliteCreateFunction('concat', array(__CLASS__, 'sqlFunctionConcat'));
+    $pdo->sqliteCreateFunction('concat_ws', array(__CLASS__, 'sqlFunctionConcatWs'));
     $pdo->sqliteCreateFunction('substring', array(__CLASS__, 'sqlFunctionSubstring'), 3);
     $pdo->sqliteCreateFunction('substring_index', array(__CLASS__, 'sqlFunctionSubstringIndex'), 3);
     $pdo->sqliteCreateFunction('rand', array(__CLASS__, 'sqlFunctionRand'));
@@ -200,6 +201,25 @@ public static function sqlFunctionConcat() {
   }
 
   /**
+   * SQLite compatibility implementation for the CONCAT_WS() SQL function.
+   *
+   * @see http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_concat-ws
+   */
+  public static function sqlFunctionConcatWs() {
+    $args = func_get_args();
+    $separator = array_shift($args);
+    // If the separator is NULL, the result is NULL.
+    if ($separator === FALSE || is_null($separator)) {
+      return NULL;
+    }
+    // Skip any NULL values after the separator argument.
+    $args = array_filter($args, function ($value) {
+      return !is_null($value);
+    });
+    return implode($separator, $args);
+  }
+
+  /**
    * SQLite compatibility implementation for the SUBSTRING() SQL function.
    */
   public static function sqlFunctionSubstring($string, $from, $length) {
-- 
1.7.11.msysgit.1


From 95e5fd3cacbe6de447e93585f6051b4484abd7b8 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Tue, 5 Aug 2014 17:25:20 +0200
Subject: [PATCH 20/29] Fixed SQLite: StatementPrefetch is dead code due to
 logic error.

---
 .../Core/Database/Driver/sqlite/Connection.php     | 71 +++++++++++++++++++++-
 1 file changed, 68 insertions(+), 3 deletions(-)

diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
index 82a1234..42652bf 100644
--- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
+++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
@@ -68,9 +68,6 @@ class Connection extends DatabaseConnection {
   public function __construct(\PDO $connection, array $connection_options) {
     parent::__construct($connection, $connection_options);
 
-    // We don't need a specific PDOStatement class here, we simulate it below.
-    $this->statementClass = NULL;
-
     // This driver defaults to transaction support, except if explicitly passed FALSE.
     $this->transactionSupport = $this->transactionalDDLSupport = !isset($connection_options['transactions']) || $connection_options['transactions'] !== FALSE;
 
@@ -264,6 +261,74 @@ public static function sqlFunctionRegexp($string, $pattern) {
   }
 
   /**
+   * {@inheritdoc}
+   */
+  protected function expandArguments(&$query, &$args) {
+    $modified = parent::expandArguments($query, $args);
+
+    // The PDO SQLite driver always replaces placeholders with strings, which
+    // breaks numeric expressions (e.g., COUNT(*) >= :count). Replace numeric
+    // placeholders in the query to work around this bug.
+    // @see http://bugs.php.net/bug.php?id=45259
+    if (empty($args)) {
+      return $modified;
+    }
+    // Check if $args is a simple numeric array.
+    if (range(0, count($args) - 1) === array_keys($args)) {
+      // In that case, we have unnamed placeholders.
+      $count = 0;
+      $new_args = array();
+      foreach ($args as $value) {
+        if (is_float($value) || is_int($value) || is_numeric($value)) {
+          if (is_float($value)) {
+            // Force the conversion to float so as not to loose precision
+            // in the automatic cast.
+            $value = sprintf('%F', $value);
+          }
+          $query = substr_replace($query, $value, strpos($query, '?'), 1);
+        }
+        else {
+          $placeholder = ':db_statement_placeholder_' . $count++;
+          $query = substr_replace($query, $placeholder, strpos($query, '?'), 1);
+          $new_args[$placeholder] = $value;
+        }
+      }
+      $args = $new_args;
+      $modified = TRUE;
+    }
+    // Otherwise this is using named placeholders.
+    else {
+      foreach ($args as $placeholder => $value) {
+        if (is_float($value) || is_int($value) || is_numeric($value)) {
+          if (is_float($value)) {
+            // Force the conversion to float so as not to loose precision
+            // in the automatic cast.
+            $value = sprintf('%F', $value);
+          }
+
+          // We will remove this placeholder from the query as PDO throws an
+          // exception if the number of placeholders in the query and the
+          // arguments does not match.
+          unset($args[$placeholder]);
+          // PDO allows placeholders to not be prefixed by a colon. See
+          // http://marc.info/?l=php-internals&m=111234321827149&w=2 for
+          // more.
+          if ($placeholder[0] != ':') {
+            $placeholder = ":$placeholder";
+          }
+          // When replacing the placeholders, make sure we search for the
+          // exact placeholder. For example, if searching for
+          // ':db_placeholder_1', do not replace ':db_placeholder_11'.
+          $query = preg_replace('/' . preg_quote($placeholder, '/') . '\b/', $value, $query);
+
+          $modified = TRUE;
+        }
+      }
+    }
+    return $modified;
+  }
+
+  /**
    * SQLite-specific implementation of DatabaseConnection::prepare().
    *
    * We don't use prepared statements at all at this stage. We just create
-- 
1.7.11.msysgit.1


From 04840bf4b4778f32fa284244085d9bf34a41a090 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Wed, 6 Aug 2014 01:35:32 +0200
Subject: [PATCH 21/29] Fixed SQLite: Bogus REGEXP user function.

---
 core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
index 42652bf..f8d1a90 100644
--- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
+++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
@@ -254,10 +254,16 @@ public static function sqlFunctionRand($seed = NULL) {
   /**
    * SQLite compatibility implementation for the REGEXP SQL operator.
    *
-   * The REGEXP operator is a special syntax for the regexp() user function.
+   * The REGEXP operator is natively known, but not implemented by default.
+   *
+   * @see http://www.sqlite.org/lang_expr.html#regexp
    */
-  public static function sqlFunctionRegexp($string, $pattern) {
-    return preg_match('#' . str_replace('#', '\#', $pattern) . '#i', $string);
+  public static function sqlFunctionRegexp($pattern, $subject) {
+    // preg_quote() cannot be used here, since $pattern may contain reserved
+    // regular expression characters already (such as ^, $, etc). Therefore,
+    // use a rare character as PCRE delimiter.
+    $pattern = '#' . addcslashes($pattern, '#') . '#i';
+    return preg_match($pattern, $subject);
   }
 
   /**
-- 
1.7.11.msysgit.1


From 0dfce716c7cc50495af4065b85c61a74ba672fa5 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Wed, 6 Aug 2014 01:37:10 +0200
Subject: [PATCH 22/29] Fixed SQLite Insert query does not account for INSERT
 FROM ... SELECT.

---
 core/lib/Drupal/Core/Database/Driver/sqlite/Insert.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Insert.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Insert.php
index 3a0bcaa..8882fcd 100644
--- a/core/lib/Drupal/Core/Database/Driver/sqlite/Insert.php
+++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Insert.php
@@ -22,7 +22,7 @@ public function execute() {
     if (!$this->preExecute()) {
       return NULL;
     }
-    if (count($this->insertFields)) {
+    if (count($this->insertFields) || !empty($this->fromQuery)) {
       return parent::execute();
     }
     else {
@@ -35,7 +35,10 @@ public function __toString() {
     $comments = $this->connection->makeComment($this->comments);
 
     // Produce as many generic placeholders as necessary.
-    $placeholders = array_fill(0, count($this->insertFields), '?');
+    $placeholders = array();
+    if (!empty($this->insertFields)) {
+      $placeholders = array_fill(0, count($this->insertFields), '?');
+    }
 
     // If we're selecting from a SelectQuery, finish building the query and
     // pass it back, as any remaining options are irrelevant.
-- 
1.7.11.msysgit.1


From 2a7877ee02ea95e6bda3fbe8a43aed05b1507cc6 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Tue, 5 Aug 2014 21:23:23 +0200
Subject: [PATCH 23/29] Issue #2304461 by sun: Updated Views Date Handler for
 SQLite.

SQLite does not support advanced date/calendar operations (such as identifying 2000-01-01 as the 52nd week of 1999).
---
 core/modules/views/src/Plugin/views/query/Sql.php  | 15 ++++++++++++--
 .../views/src/Tests/Handler/ArgumentDateTest.php   | 23 +++++++++++++---------
 2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/core/modules/views/src/Plugin/views/query/Sql.php b/core/modules/views/src/Plugin/views/query/Sql.php
index 1cabb79..5950981 100644
--- a/core/modules/views/src/Plugin/views/query/Sql.php
+++ b/core/modules/views/src/Plugin/views/query/Sql.php
@@ -1641,7 +1641,7 @@ public function getDateField($field) {
         break;
       case 'sqlite':
         if (!empty($offset)) {
-          $field = "($field + '$offset_seconds')";
+          $field = "($field + $offset_seconds)";
         }
         break;
     }
@@ -1755,7 +1755,18 @@ public function getDateFormat($field, $format) {
           'A' => '',
         );
         $format = strtr($format, $replace);
-        return "strftime('$format', $field, 'unixepoch')";
+        $expression = "strftime('$format', $field, 'unixepoch')";
+        // The expression yields a string, but the comparison value is an
+        // integer in case the comparison value is a float, integer, or numeric.
+        // All of the above SQLite format tokens only produce integers. However,
+        // the given $format may contain 'Y-m-d', which results in a string.
+        // @see \Drupal\Core\Database\Driver\sqlite\Connection::expandArguments()
+        // @see http://www.sqlite.org/lang_datefunc.html
+        // @see http://www.sqlite.org/lang_expr.html#castexpr
+        if (preg_match('/^(?:%\w)+$/', $format)) {
+          $expression = "CAST($expression AS NUMERIC)";
+        }
+        return $expression;
     }
   }
 
diff --git a/core/modules/views/src/Tests/Handler/ArgumentDateTest.php b/core/modules/views/src/Tests/Handler/ArgumentDateTest.php
index 4c66e79..f6ba131 100644
--- a/core/modules/views/src/Tests/Handler/ArgumentDateTest.php
+++ b/core/modules/views/src/Tests/Handler/ArgumentDateTest.php
@@ -163,15 +163,20 @@ public function testWeekHandler() {
       ->execute();
 
     $view = Views::getView('test_argument_date');
-    $view->setDisplay('embed_3');
-    // The first jan 2000 was still in the last week of the previous year.
-    $this->executeView($view, array(52));
-    $expected = array();
-    $expected[] = array('id' => 1);
-    $expected[] = array('id' => 2);
-    $expected[] = array('id' => 3);
-    $this->assertIdenticalResultset($view, $expected, $this->columnMap);
-    $view->destroy();
+
+    // SQLite does not support advanced date operations (such as interpreting
+    // 2000-01-01 as the 52nd week of 1999).
+    if ($this->container->get('database')->driver() !== 'sqlite') {
+      $view->setDisplay('embed_3');
+      // The first jan 2000 was still in the last week of the previous year.
+      $this->executeView($view, array(52));
+      $expected = array();
+      $expected[] = array('id' => 1);
+      $expected[] = array('id' => 2);
+      $expected[] = array('id' => 3);
+      $this->assertIdenticalResultset($view, $expected, $this->columnMap);
+      $view->destroy();
+    }
 
     $view->setDisplay('embed_3');
     $this->executeView($view, array('02'));
-- 
1.7.11.msysgit.1


From 5d39a3c204e3572fa09627d9657a9160710d881e Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Tue, 5 Aug 2014 18:33:00 +0200
Subject: [PATCH 24/29] Issue #2315269 by sun:
 Entity/Query/Sql/QueryAggregate: PDOException: GROUP
 BY clause is required before HAVING.

---
 core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php b/core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php
index 9cf3bcd..0c01bb0 100644
--- a/core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityQueryAggregateTest.php
@@ -160,12 +160,14 @@ public function testAggregation() {
     // Apply aggregation and a condition which matches.
     $this->queryResult = $this->factory->getAggregate('entity_test')
       ->aggregate('id', 'COUNT')
+      ->groupBy('id')
       ->conditionAggregate('id', 'COUNT', 8)
       ->execute();
     $this->assertResults(array());
 
     // Don't call aggregate to test the implicit aggregate call.
     $this->queryResult = $this->factory->getAggregate('entity_test')
+      ->groupBy('id')
       ->conditionAggregate('id', 'COUNT', 8)
       ->execute();
     $this->assertResults(array());
@@ -173,6 +175,7 @@ public function testAggregation() {
     // Apply aggregation and a condition which matches.
     $this->queryResult = $this->factory->getAggregate('entity_test')
       ->aggregate('id', 'count')
+      ->groupBy('id')
       ->conditionAggregate('id', 'COUNT', 6)
       ->execute();
     $this->assertResults(array(array('id_count' => 6)));
-- 
1.7.11.msysgit.1


From f401275f0f15322a4cc943f67f155a33c9bf4cfd Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Wed, 6 Aug 2014 01:37:59 +0200
Subject: [PATCH 25/29] Issue #2304461 by sun: Fixed bogus expectations in
 ConfigFileContentTest.

---
 core/modules/config/src/Tests/ConfigFileContentTest.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/core/modules/config/src/Tests/ConfigFileContentTest.php b/core/modules/config/src/Tests/ConfigFileContentTest.php
index 0f5b8d0..2b3216e 100644
--- a/core/modules/config/src/Tests/ConfigFileContentTest.php
+++ b/core/modules/config/src/Tests/ConfigFileContentTest.php
@@ -111,16 +111,16 @@ function testReadWriteConfig() {
     $this->assertNull($config->get('i.dont.exist'), 'Non-existent nested value returned NULL.');
 
     // Read false value.
-    $this->assertEqual($config->get($false_key), '0', format_string("Boolean FALSE value returned the string '0'."));
+    $this->assertIdentical($config->get($false_key), FALSE);
 
     // Read true value.
-    $this->assertEqual($config->get($true_key), '1', format_string("Boolean TRUE value returned the string '1'."));
+    $this->assertIdentical($config->get($true_key), TRUE);
 
     // Read null value.
     $this->assertIdentical($config->get('null'), NULL);
 
     // Read false that had been nested in an array value.
-    $this->assertEqual($config->get($casting_array_false_value_key), '0', format_string("Nested boolean FALSE value returned the string '0'."));
+    $this->assertIdentical($config->get($casting_array_false_value_key), FALSE);
 
     // Unset a top level value.
     $config->clear($key);
-- 
1.7.11.msysgit.1


From 62248476624daabe93ad51e5c23f67c4028ea8d9 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Wed, 6 Aug 2014 01:38:55 +0200
Subject: [PATCH 26/29] Issue #2304461 by sun: Updated Config Storage tests.

---
 .../modules/config/src/Tests/Storage/CachedStorageTest.php |  2 +-
 core/modules/config/src/Tests/Storage/FileStorageTest.php  | 14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/core/modules/config/src/Tests/Storage/CachedStorageTest.php b/core/modules/config/src/Tests/Storage/CachedStorageTest.php
index 72beb6a..766a8a0 100644
--- a/core/modules/config/src/Tests/Storage/CachedStorageTest.php
+++ b/core/modules/config/src/Tests/Storage/CachedStorageTest.php
@@ -36,7 +36,7 @@ class CachedStorageTest extends ConfigStorageTestBase {
 
   function setUp() {
     parent::setUp();
-    $this->filestorage = new FileStorage($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]);
+    $this->filestorage = new FileStorage(config_get_config_directory());
     $this->storage = new CachedStorage($this->filestorage, \Drupal::service('cache_factory'));
     $this->cache = \Drupal::service('cache_factory')->get('config');
     // ::listAll() verifications require other configuration data to exist.
diff --git a/core/modules/config/src/Tests/Storage/FileStorageTest.php b/core/modules/config/src/Tests/Storage/FileStorageTest.php
index 6165044..b0eead1 100644
--- a/core/modules/config/src/Tests/Storage/FileStorageTest.php
+++ b/core/modules/config/src/Tests/Storage/FileStorageTest.php
@@ -18,8 +18,8 @@
 class FileStorageTest extends ConfigStorageTestBase {
   function setUp() {
     parent::setUp();
-    $this->storage = new FileStorage($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]);
-    $this->invalidStorage = new FileStorage($this->configDirectories[CONFIG_ACTIVE_DIRECTORY] . '/nonexisting');
+    $this->storage = new FileStorage(config_get_config_directory());
+    $this->invalidStorage = new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY) . '/nonexisting');
 
     // FileStorage::listAll() requires other configuration data to exist.
     $this->storage->write('system.performance', \Drupal::config('system.performance')->get());
@@ -56,10 +56,12 @@ public function testlistAll() {
     $this->assertIdentical($config_files, $expected_files, 'Relative path, two config files found.');
 
     // Initialize FileStorage with absolute file path.
-    $absolute_path = realpath($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]);
-    $storage_absolute_path = new FileStorage($absolute_path);
-    $config_files = $storage_absolute_path->listAll();
-    $this->assertIdentical($config_files, $expected_files, 'Absolute path, two config files found.');
+    $absolute_path = realpath(config_get_config_directory());
+    if ($absolute_path) {
+      $storage_absolute_path = new FileStorage($absolute_path);
+      $config_files = $storage_absolute_path->listAll();
+      $this->assertIdentical($config_files, $expected_files, 'Absolute path, two config files found.');
+    }
   }
 
 }
-- 
1.7.11.msysgit.1


From f1bc26a64493cabd5f83eb2f2380d610d398c6e5 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Wed, 6 Aug 2014 01:39:46 +0200
Subject: [PATCH 27/29] Issue #2304461 by sun: Updated File UrlRewritingTest
 to account for stream wrappers.

---
 core/modules/file/tests/file_test/file_test.module | 38 +++++++++++++++++++---
 .../system/src/Tests/File/UrlRewritingTest.php     | 26 +++++++++++----
 2 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/core/modules/file/tests/file_test/file_test.module b/core/modules/file/tests/file_test/file_test.module
index b1bdeb3..a08f940 100644
--- a/core/modules/file/tests/file_test/file_test.module
+++ b/core/modules/file/tests/file_test/file_test.module
@@ -271,14 +271,29 @@ function file_test_file_url_alter(&$uri) {
       // Public created files.
       else {
         $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
-        $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
+        // Account for (recursive) stream wrapper URIs (like vfsStream).
+        // Drupal does not have a concept to account for the case in which
+        // 'file_public_path' is a stream wrapper URI; it assumes that all
+        // public files are in the local filesystem. For now, since the case
+        // isn't possible on production sites, hard-code the public files
+        // directory of a fake test site, which is a sufficient manipulation
+        // for the corresponding test.
+        $path = $wrapper->getDirectoryPath();
+        if (strpos($path, '://') !== FALSE) {
+          $path = 'sites/test/files';
+        }
+        $path .= '/' . file_uri_target($uri);
       }
 
       // Clean up Windows paths.
       $path = str_replace('\\', '/', $path);
 
       // Generate a root-relative URL.
-      $uri = base_path() . '/' . $path;
+      $base_path = base_path();
+      if ($base_path !== '/') {
+        $base_path = $base_path . '/';
+      }
+      $uri = $base_path . $path;
     }
   }
   // Test alteration of file URLs to use protocol-relative URLs.
@@ -294,14 +309,29 @@ function file_test_file_url_alter(&$uri) {
       // Public created files.
       else {
         $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
-        $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
+        // Account for (recursive) stream wrapper URIs (like vfsStream).
+        // Drupal does not have a concept to account for the case in which
+        // 'file_public_path' is a stream wrapper URI; it assumes that all
+        // public files are in the local filesystem. For now, since the case
+        // isn't possible on production sites, hard-code the public files
+        // directory of a fake test site, which is a sufficient manipulation
+        // for the corresponding test.
+        $path = $wrapper->getDirectoryPath();
+        if (strpos($path, '://') !== FALSE) {
+          $path = 'sites/test/files';
+        }
+        $path .= '/' . file_uri_target($uri);
       }
 
       // Clean up Windows paths.
       $path = str_replace('\\', '/', $path);
 
       // Generate a protocol-relative URL.
-      $uri = '/' . base_path() . '/' . $path;
+      $base_path = base_path();
+      if ($base_path !== '/') {
+        $base_path = $base_path . '/';
+      }
+      $uri = '/' . $base_path . $path;
     }
   }
 }
diff --git a/core/modules/system/src/Tests/File/UrlRewritingTest.php b/core/modules/system/src/Tests/File/UrlRewritingTest.php
index 2c428ae..2ee799e 100644
--- a/core/modules/system/src/Tests/File/UrlRewritingTest.php
+++ b/core/modules/system/src/Tests/File/UrlRewritingTest.php
@@ -29,6 +29,10 @@ class UrlRewritingTest extends FileTestBase {
   function testShippedFileURL()  {
     // Test generating an URL to a shipped file (i.e. a file that is part of
     // Drupal core, a module or a theme, for example a JavaScript file).
+    $base_path = base_path();
+    if ($base_path !== '/') {
+      $base_path .= '/';
+    }
 
     // Test alteration of file URLs to use a CDN.
     \Drupal::state()->set('file_test.hook_file_url_alter', 'cdn');
@@ -43,19 +47,19 @@ function testShippedFileURL()  {
     \Drupal::state()->set('file_test.hook_file_url_alter', 'root-relative');
     $filepath = 'core/assets/vendor/jquery/jquery.js';
     $url = file_create_url($filepath);
-    $this->assertEqual(base_path() . '/' . $filepath, $url, 'Correctly generated a root-relative URL for a shipped file.');
+    $this->assertEqual($base_path . $filepath, $url, 'Correctly generated a root-relative URL for a shipped file.');
     $filepath = 'core/misc/favicon.ico';
     $url = file_create_url($filepath);
-    $this->assertEqual(base_path() . '/' . $filepath, $url, 'Correctly generated a root-relative URL for a shipped file.');
+    $this->assertEqual($base_path . $filepath, $url, 'Correctly generated a root-relative URL for a shipped file.');
 
     // Test alteration of file URLs to use protocol-relative URLs.
     \Drupal::state()->set('file_test.hook_file_url_alter', 'protocol-relative');
     $filepath = 'core/assets/vendor/jquery/jquery.js';
     $url = file_create_url($filepath);
-    $this->assertEqual('/' . base_path() . '/' . $filepath, $url, 'Correctly generated a protocol-relative URL for a shipped file.');
+    $this->assertEqual('/' . $base_path . $filepath, $url, 'Correctly generated a protocol-relative URL for a shipped file.');
     $filepath = 'core/misc/favicon.ico';
     $url = file_create_url($filepath);
-    $this->assertEqual('/' . base_path() . '/' . $filepath, $url, 'Correctly generated a protocol-relative URL for a shipped file.');
+    $this->assertEqual('/' . $base_path . $filepath, $url, 'Correctly generated a protocol-relative URL for a shipped file.');
   }
 
   /**
@@ -75,13 +79,23 @@ function testPublicManagedFileURL() {
     \Drupal::state()->set('file_test.hook_file_url_alter', 'root-relative');
     $uri = $this->createUri();
     $url = file_create_url($uri);
-    $this->assertEqual(base_path() . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a root-relative URL for a created file.');
+    if (realpath($public_directory_path)) {
+      $this->assertEqual(base_path() . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a root-relative URL for a created file.');
+    }
+    else {
+      $this->assertEqual('/sites/test/files/' . drupal_basename($uri), $url, 'Correctly generated a root-relative URL for a created file.');
+    }
 
     // Test alteration of file URLs to use a protocol-relative URLs.
     \Drupal::state()->set('file_test.hook_file_url_alter', 'protocol-relative');
     $uri = $this->createUri();
     $url = file_create_url($uri);
-    $this->assertEqual('/' . base_path() . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a protocol-relative URL for a created file.');
+    if (realpath($public_directory_path)) {
+      $this->assertEqual('/' . base_path() . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a protocol-relative URL for a created file.');
+    }
+    else {
+      $this->assertEqual('//sites/test/files/' . drupal_basename($uri), $url, 'Correctly generated a protocol-relative URL for a created file.');
+    }
   }
 
   /**
-- 
1.7.11.msysgit.1


From 92ccb4536640817bf220b2818d11782c3b4d520a Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Wed, 6 Aug 2014 21:17:24 +0200
Subject: [PATCH 28/29] Issue #2304461 by sun: Updated usage of deprecated
 properties/methods.

---
 core/modules/config/src/Tests/ConfigFileContentTest.php       | 2 +-
 core/modules/field/src/Tests/FieldImportCreateTest.php        | 2 +-
 core/modules/node/src/Tests/Config/NodeImportCreateTest.php   | 2 +-
 core/modules/system/src/Tests/Extension/ModuleHandlerTest.php | 2 +-
 core/modules/system/src/Tests/File/DirectoryTest.php          | 2 +-
 core/modules/system/src/Tests/File/UnmanagedSaveDataTest.php  | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/core/modules/config/src/Tests/ConfigFileContentTest.php b/core/modules/config/src/Tests/ConfigFileContentTest.php
index 2b3216e..6408d39 100644
--- a/core/modules/config/src/Tests/ConfigFileContentTest.php
+++ b/core/modules/config/src/Tests/ConfigFileContentTest.php
@@ -200,7 +200,7 @@ function testSerialization() {
     );
 
     // Encode and write, and reload and decode the configuration data.
-    $filestorage = new FileStorage($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]);
+    $filestorage = new FileStorage(config_get_config_directory());
     $filestorage->write($name, $config_data);
     $config_parsed = $filestorage->read($name);
 
diff --git a/core/modules/field/src/Tests/FieldImportCreateTest.php b/core/modules/field/src/Tests/FieldImportCreateTest.php
index 4c56087..3841282 100644
--- a/core/modules/field/src/Tests/FieldImportCreateTest.php
+++ b/core/modules/field/src/Tests/FieldImportCreateTest.php
@@ -94,7 +94,7 @@ function testImportCreate() {
 
     // Add the new files to the staging directory.
     $src_dir = drupal_get_path('module', 'field_test_config') . '/staging';
-    $target_dir = $this->configDirectories[CONFIG_STAGING_DIRECTORY];
+    $target_dir = config_get_config_directory(CONFIG_STAGING_DIRECTORY);
     $this->assertTrue(file_unmanaged_copy("$src_dir/$field_storage_config_name.yml", "$target_dir/$field_storage_config_name.yml"));
     $this->assertTrue(file_unmanaged_copy("$src_dir/$instance_config_name.yml", "$target_dir/$instance_config_name.yml"));
     $this->assertTrue(file_unmanaged_copy("$src_dir/$field_storage_config_name_2.yml", "$target_dir/$field_storage_config_name_2.yml"));
diff --git a/core/modules/node/src/Tests/Config/NodeImportCreateTest.php b/core/modules/node/src/Tests/Config/NodeImportCreateTest.php
index c0d5bc7..a2badcb 100644
--- a/core/modules/node/src/Tests/Config/NodeImportCreateTest.php
+++ b/core/modules/node/src/Tests/Config/NodeImportCreateTest.php
@@ -64,7 +64,7 @@ public function testImportCreate() {
     $this->copyConfig($active, $staging);
     // Manually add new node type.
     $src_dir = drupal_get_path('module', 'node_test_config') . '/staging';
-    $target_dir = $this->configDirectories[CONFIG_STAGING_DIRECTORY];
+    $target_dir = config_get_config_directory(CONFIG_STAGING_DIRECTORY);
     $this->assertTrue(file_unmanaged_copy("$src_dir/$node_type_config_name.yml", "$target_dir/$node_type_config_name.yml"));
 
     // Import the content of the staging directory.
diff --git a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php
index 9b0e40e..c86e082 100644
--- a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php
+++ b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php
@@ -171,7 +171,7 @@ function testDependencyResolution() {
   function testUninstallProfileDependency() {
     $profile = 'minimal';
     $dependency = 'dblog';
-    $this->settingsSet('install_profile', $profile);
+    $this->setSetting('install_profile', $profile);
     $this->enableModules(array('module_test', $profile));
 
     drupal_static_reset('system_rebuild_module_data');
diff --git a/core/modules/system/src/Tests/File/DirectoryTest.php b/core/modules/system/src/Tests/File/DirectoryTest.php
index fb2c92b..14cf7fd 100644
--- a/core/modules/system/src/Tests/File/DirectoryTest.php
+++ b/core/modules/system/src/Tests/File/DirectoryTest.php
@@ -81,7 +81,7 @@ function testFileCheckDirectoryHandling() {
       $this->assertFalse(file_prepare_directory($directory, 0), 'Error reported for a non-writeable directory.', 'File');
 
       // Test directory permission modification.
-      $this->settingsSet('file_chmod_directory', 0777);
+      $this->setSetting('file_chmod_directory', 0777);
       $this->assertTrue(file_prepare_directory($directory, FILE_MODIFY_PERMISSIONS), 'No error reported when making directory writeable.', 'File');
     }
 
diff --git a/core/modules/system/src/Tests/File/UnmanagedSaveDataTest.php b/core/modules/system/src/Tests/File/UnmanagedSaveDataTest.php
index fc715c6..28b2e94 100644
--- a/core/modules/system/src/Tests/File/UnmanagedSaveDataTest.php
+++ b/core/modules/system/src/Tests/File/UnmanagedSaveDataTest.php
@@ -18,7 +18,7 @@ class UnmanagedSaveDataTest extends FileTestBase {
    */
   function testFileSaveData() {
     $contents = $this->randomMachineName(8);
-    $this->settingsSet('file_chmod_file', 0777);
+    $this->setSetting('file_chmod_file', 0777);
 
     // No filename.
     $filepath = file_unmanaged_save_data($contents);
-- 
1.7.11.msysgit.1


From 6a0d62eb2635ad0067fc62f7cd8979efbe17c93e Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Wed, 6 Aug 2014 23:02:05 +0200
Subject: [PATCH 29/29] Issue #2302165 by sun: Fixed loadByProperties()
 validation + bogus test code.

---
 core/lib/Drupal/Core/Menu/MenuTreeStorage.php              | 2 +-
 core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php
index c1c137f..2f127ef 100644
--- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php
+++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php
@@ -638,7 +638,7 @@ public function loadByProperties(array $properties) {
     $query = $this->connection->select($this->table, $this->options);
     $query->fields($this->table, $this->definitionFields());
     foreach ($properties as $name => $value) {
-      if (!in_array($name, $this->definitionFields())) {
+      if (!in_array($name, $this->definitionFields(), TRUE)) {
         $fields = implode(', ', $this->definitionFields());
         throw new \InvalidArgumentException(String::format('An invalid property name, @name was specified. Allowed property names are: @fields.', array('@name' => $name, '@fields' => $fields)));
       }
diff --git a/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php b/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php
index 7f39b37..da6d90a 100644
--- a/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php
+++ b/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php
@@ -317,7 +317,7 @@ public function testLoadByProperties() {
       $this->pass($msg);
     }
     $this->addMenuLink(1);
-    $properties = array(array('menu_name' => 'tools'));
+    $properties = array('menu_name' => 'tools');
     $links = $this->treeStorage->loadByProperties($properties);
     $this->assertEqual('tools', $links[1]['menu_name']);
   }
-- 
1.7.11.msysgit.1

