diff --git a/core/includes/file.inc b/core/includes/file.inc index d0ed095..dad8c61 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -191,12 +191,16 @@ function file_get_stream_wrappers($filter = STREAM_WRAPPERS_ALL) { $wrappers_storage = &drupal_static(__FUNCTION__); if (!isset($wrappers_storage)) { - $wrappers = \Drupal::moduleHandler()->invokeAll('stream_wrappers'); - foreach ($wrappers as $scheme => $info) { - // Add defaults. - $wrappers[$scheme] += array('type' => STREAM_WRAPPERS_NORMAL); + $wrappers = array(); + $container = \Drupal::getContainer(); + if (is_object($container) && $container->has('module_handler')) { + $wrappers = \Drupal::moduleHandler()->invokeAll('stream_wrappers'); + foreach ($wrappers as $scheme => $info) { + // Add defaults. + $wrappers[$scheme] += array('type' => STREAM_WRAPPERS_NORMAL); + } + drupal_alter('stream_wrappers', $wrappers); } - drupal_alter('stream_wrappers', $wrappers); $existing = stream_get_wrappers(); foreach ($wrappers as $scheme => $info) { // We only register classes that implement our interface. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index b7848de..d90c210 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -88,6 +88,19 @@ protected function setUp() { $this->keyValueFactory = new KeyValueMemoryFactory(); parent::setUp(); + + // UnitTestBase created a public files directory. Tests based on + // DrupalUnitTestBase are entitled to use Drupal's File API, so inject a + // 'public' stream wrapper. + // @todo Revamp Drupal's stream wrapper API for D8. + stream_wrapper_register('public', 'Drupal\Core\StreamWrapper\PublicStream'); + $wrappers = &drupal_static('file_get_stream_wrappers'); + $wrappers['public'] = array( + 'type' => STREAM_WRAPPERS_LOCAL_NORMAL, + 'class' => 'Drupal\Core\StreamWrapper\PublicStream', + ); + $wrappers[STREAM_WRAPPERS_ALL] = $wrappers; + // Build a minimal, partially mocked environment for unit tests. $this->containerBuild(\Drupal::getContainer()); // Make sure it survives kernel rebuilds. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 669c615..2af069f 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -963,6 +963,12 @@ protected function prepareEnvironment() { // Create and set new configuration directories. $this->prepareConfigDirectories(); + // Unregister all Drupal stream wrappers. + $wrappers = file_get_stream_wrappers(); + foreach ($wrappers as $scheme => $info) { + stream_wrapper_unregister($scheme); + } + // Reset statics before the old container is replaced so that objects with a // __destruct() method still have access to it. // @todo: Remove once they have been converted to services.