diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 82ac9ef..d87b737 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -269,7 +269,7 @@ function drupal_get_filename($type, $name, $filename = NULL) { * the 'module://', 'profile://' and 'theme://' stream wrappers should be used * for other use cases. * - * @param string $type + * @param string $type * The type of the item; one of 'core', 'profile', 'module', 'theme', or * 'theme_engine'. * @param $name diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php index 9eafe5b..490abcd 100644 --- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php @@ -62,14 +62,14 @@ public static function getType() { /** * Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::setUri(). */ - function setUri($uri) { + public function setUri($uri) { $this->uri = $uri; } /** * Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::getUri(). */ - function getUri() { + public function getUri() { return $this->uri; } @@ -109,7 +109,7 @@ protected function getTarget($uri = NULL) { /** * Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::realpath(). */ - function realpath() { + public function realpath() { return $this->getLocalPath(); } @@ -578,4 +578,5 @@ public function dir_closedir() { // have a return value. return TRUE; } + } diff --git a/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php b/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php index bdfba2a..0a878a3 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php @@ -69,4 +69,5 @@ public function getName() { public function getDescription() { return t('Local module files.'); } + } diff --git a/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php b/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php index 0f10819..de03e6d 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php @@ -50,4 +50,5 @@ public function getName() { public function getDescription() { return t('Local profile files.'); } + } diff --git a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php index 7c1c190..ea2297a 100644 --- a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php +++ b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php @@ -67,6 +67,7 @@ /** * Not visible in the UI or accessible via web, but readable and writable. + * * E.g. the temporary directory for uploads. */ const HIDDEN = 0x000C; diff --git a/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php b/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php index cf5ce38..a02b01a 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php @@ -77,12 +77,15 @@ protected function getOwnerName() { case 'current': $name = $this->getActiveTheme(); break; + case 'default': $name = $this->themeHandler->getDefault(); break; + case 'admin': $name = $this->configFactory->get('system.theme')->get('admin'); break; + } // Return name only for installed themes. if ($this->themeHandler->themeExists($name)) { @@ -124,4 +127,5 @@ public function getName() { public function getDescription() { return t('Local theme files.'); } + } diff --git a/core/modules/system/src/Tests/File/SystemStreamTest.php b/core/modules/system/src/Tests/File/SystemStreamTest.php index 02b75ab..1f7d42f 100644 --- a/core/modules/system/src/Tests/File/SystemStreamTest.php +++ b/core/modules/system/src/Tests/File/SystemStreamTest.php @@ -7,7 +7,7 @@ namespace Drupal\system\Tests\File; -use Drupal\Component\Utility\String; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Site\Settings; use Drupal\simpletest\KernelTestBase; @@ -26,6 +26,13 @@ class SystemStreamTest extends KernelTestBase { public static $modules = array('system', 'file', 'file_test'); /** + * The profile to install as a basis for testing. + * + * @var string + */ + protected $profile = 'standard'; + + /** * {@inheritdoc} */ public static function getInfo() { @@ -44,9 +51,9 @@ public function setUp() { drupal_static_reset('file_get_stream_wrappers'); // Add default profile for the purposes of this test. - new Settings(Settings::getAll() + array( - 'install_profile' => 'standard' - )); +// new Settings(Settings::getAll() + array( +// 'install_profile' => 'standard' +// )); } /** @@ -67,16 +74,16 @@ public function testInvalidStreamUriException() { ); /** @var \Drupal\Core\StreamWrapper\ModuleStream $instance */ - $instance = file_stream_wrapper_get_instance_by_scheme('module'); + $instance = \Drupal::service('stream_wrapper_manager')->getViaScheme('module'); foreach ($bad_uris as $bad_uri) { try { $instance->dirname($bad_uri); - $this->fail(String::format('Invalid uri %uri not detected.', array('%uri' => $bad_uri))); + $this->fail(SafeMarkup::format('Invalid uri %uri not detected.', array('%uri' => $bad_uri))); } catch (\InvalidArgumentException $e) { if ($e->getMessage() == 'Malformed uri parameter passed: ' . $bad_uri) { - $this->pass(String::format('Throw exception on invalid uri %uri supplied.', array('%uri' => $bad_uri))); + $this->pass(SafeMarkup::format('Throw exception on invalid uri %uri supplied.', array('%uri' => $bad_uri))); } else { throw new \InvalidArgumentException($e); @@ -91,7 +98,7 @@ public function testInvalidStreamUriException() { public function testModuleStream() { // Generate a module stream wrapper instance. /** @var \Drupal\Core\StreamWrapper\ModuleStream $instance */ - $instance = file_stream_wrapper_get_instance_by_scheme('module'); + $instance = \Drupal::service('stream_wrapper_manager')->getViaScheme('module'); // dirname() $data = $this->providerModuleStream('dirname'); @@ -107,7 +114,7 @@ public function testModuleStream() { } /** - * Provides test data for testModuleStream() + * Provides test data for testModuleStream(). */ protected function providerModuleStream($method) { $uris = array( @@ -159,7 +166,7 @@ protected function providerModuleStream($method) { public function testProfileStream() { // Generate a profile stream wrapper instance. /** @var \Drupal\Core\StreamWrapper\ProfileStream $instance */ - $instance = file_stream_wrapper_get_instance_by_scheme('profile'); + $instance = \Drupal::service('stream_wrapper_manager')->getViaScheme('profile'); // dirname() $data = $this->providerProfileStream('dirname'); @@ -175,7 +182,7 @@ public function testProfileStream() { } /** - * Provides test data for testProfileStream() + * Provides test data for testProfileStream(). */ protected function providerProfileStream($method) { $uris = array( @@ -194,8 +201,8 @@ protected function providerProfileStream($method) { array('profile://minimal/config/install', "Get the dirname of a resource located in a profile's subdirectory."), array('profile://minimal/config/install', "Get the dirname of a non-existent resource in profile's subdirectory."), array(new \InvalidArgumentException(), "Fail returning the dirname of a non-existent profile."), - array('profile://standard', String::format('Get the dirname of %current.', array('%current' => 'profile://current'))), - array('profile://standard', String::format('Get the dirname of a resource in %current path.', array('%current' => 'profile://current'))), + array('profile://standard', SafeMarkup::format('Get the dirname of %current.', array('%current' => 'profile://current'))), + array('profile://standard', SafeMarkup::format('Get the dirname of a resource in %current path.', array('%current' => 'profile://current'))), )); case 'realpath': @@ -205,8 +212,8 @@ protected function providerProfileStream($method) { array($base_path . '/core/profiles/minimal/config/install/block.block.stark_login.yml', "Get the realpath of a resource located in a profile's subdirectory."), array($base_path . '/core/profiles/minimal/config/install/node.type.article.yml', "Get the realpath of a non-existent resource in profile's subdirectory."), array(new \InvalidArgumentException(), "Fail returning the realpath for a non-existent profile."), - array($base_path . '/core/profiles/standard', String::format('Get the realpath of %current.', array('%current' => 'profile://current'))), - array($base_path . '/core/profiles/standard/standard.info.yml', String::format('Get the realpath of a resource in %current path.', array('%current' => 'profile://current'))), + array($base_path . '/core/profiles/standard', SafeMarkup::format('Get the realpath of %current.', array('%current' => 'profile://current'))), + array($base_path . '/core/profiles/standard/standard.info.yml', SafeMarkup::format('Get the realpath of a resource in %current path.', array('%current' => 'profile://current'))), )); case 'getExternalUrl': @@ -216,8 +223,8 @@ protected function providerProfileStream($method) { array($base_url . 'core/profiles/minimal/config/install/block.block.stark_login.yml', "Return the external url of a file located in a subdirectory."), array($base_url . 'core/profiles/minimal/config/install/node.type.article.yml', "Return the external url of a non-existent file located in a subdirectory."), array(new \InvalidArgumentException(), "Fail returning the external uri for a disabled profile."), - array($base_url . 'core/profiles/standard', String::format('Lookup the external url of %current for a partial URI.', array('%current' => 'profile://current'))), - array($base_url . 'core/profiles/standard/standard.info.yml', String::format('Lookup the external url of %current for a resource.', array('%current' => 'profile://current'))), + array($base_url . 'core/profiles/standard', SafeMarkup::format('Lookup the external url of %current for a partial URI.', array('%current' => 'profile://current'))), + array($base_url . 'core/profiles/standard/standard.info.yml', SafeMarkup::format('Lookup the external url of %current for a resource.', array('%current' => 'profile://current'))), )); } } @@ -234,20 +241,20 @@ public function testThemeStream() { $theme_handler->install(array('bartik', 'seven', 'stark')); // Set admin theme to Seven. - $system_theme = \Drupal::config('system.theme'); + $system_theme = \Drupal::configFactory()->getEditable('system.theme'); $this->assertNull($system_theme->get('admin'), 'No admin theme was set.'); $system_theme->set('admin', 'seven')->save(); - $this->assertEqual($system_theme->get('admin'), 'seven', String::format('Make %seven the admin theme.', array('%seven' => 'Seven'))); + $this->assertEqual($system_theme->get('admin'), 'seven', SafeMarkup::format('Make %seven the admin theme.', array('%seven' => 'Seven'))); // Set default theme to Bartik. $theme_handler->setDefault('bartik'); - $this->assertEqual($theme_handler->getDefault(), 'bartik', String::format('Make %bartik the default theme.', array('%bartik' => 'Bartik'))); + $this->assertEqual($theme_handler->getDefault(), 'bartik', SafeMarkup::format('Make %bartik the default theme.', array('%bartik' => 'Bartik'))); // Uninstall Stark theme. $theme_handler->uninstall(array('stark')); /** @var \Drupal\Core\StreamWrapper\ThemeStream $instance */ - $instance = file_stream_wrapper_get_instance_by_scheme('theme'); + $instance = \Drupal::service('stream_wrapper_manager')->getViaScheme('theme'); // dirname() $data = $this->providerThemeStream('dirname'); @@ -287,12 +294,12 @@ protected function providerThemeStream($method) { array('theme://seven', "Get the dirname of a resource located in a theme directory."), array('theme://bartik/color', "Get the dirname of a resource located in a theme's subdirectory."), array(new \InvalidArgumentException(), "Fail returning the dirname of a non-existent theme."), - array('theme://bartik', String::format('Get the dirname of %current.', array('%current' => 'theme://current'))), - array('theme://bartik', String::format('Get the dirname of a resource in %current.', array('%current' => 'theme://current'))), - array('theme://bartik', String::format('Get the dirname of %default.', array('%default' => 'theme://default'))), - array('theme://bartik', String::format('Get the dirname of a resource in %default.', array('%default' => 'theme://default'))), - array('theme://seven', String::format('Get the dirname of %admin.', array('%admin' => 'theme://admin'))), - array('theme://seven', String::format('Get the dirname of a non-existent resource in %admin.', array('%admin' => 'theme://admin'))), + array('theme://bartik', SafeMarkup::format('Get the dirname of %current.', array('%current' => 'theme://current'))), + array('theme://bartik', SafeMarkup::format('Get the dirname of a resource in %current.', array('%current' => 'theme://current'))), + array('theme://bartik', SafeMarkup::format('Get the dirname of %default.', array('%default' => 'theme://default'))), + array('theme://bartik', SafeMarkup::format('Get the dirname of a resource in %default.', array('%default' => 'theme://default'))), + array('theme://seven', SafeMarkup::format('Get the dirname of %admin.', array('%admin' => 'theme://admin'))), + array('theme://seven', SafeMarkup::format('Get the dirname of a non-existent resource in %admin.', array('%admin' => 'theme://admin'))), array(new \InvalidArgumentException(), "Fail returning the dirname for an uninstalled theme."), )); @@ -303,12 +310,12 @@ protected function providerThemeStream($method) { array($base_path . '/core/themes/seven/style.css', "Get the realpath of a resource located in a theme directory."), array($base_path . '/core/themes/bartik/color/preview.js', "Get the realpath of a resource located in a theme's subdirectory."), array(new \InvalidArgumentException(), "Fail returning the realpath of a non-existent theme."), - array($base_path . '/core/themes/bartik', String::format('Get the realpath of %current.', array('%current' => 'theme://current'))), - array($base_path . '/core/themes/bartik/logo.png', String::format('Get the realpath of a resource in %current.', array('%current' => 'theme://current'))), - array($base_path . '/core/themes/bartik', String::format('Get the realpath of %default.', array('%default' => 'theme://default'))), - array($base_path . '/core/themes/bartik/bartik.info.yml', String::format('Get the realpath of a resource in %default.', array('%default' => 'theme://default'))), - array($base_path . '/core/themes/seven', String::format('Get the realpath of %admin.', array('%admin' => 'theme://admin'))), - array($base_path . '/core/themes/seven/fake.info.yml', String::format('Get the realpath of a non-existent resource in %admin.', array('%admin' => 'theme://admin'))), + array($base_path . '/core/themes/bartik', SafeMarkup::format('Get the realpath of %current.', array('%current' => 'theme://current'))), + array($base_path . '/core/themes/bartik/logo.png', SafeMarkup::format('Get the realpath of a resource in %current.', array('%current' => 'theme://current'))), + array($base_path . '/core/themes/bartik', SafeMarkup::format('Get the realpath of %default.', array('%default' => 'theme://default'))), + array($base_path . '/core/themes/bartik/bartik.info.yml', SafeMarkup::format('Get the realpath of a resource in %default.', array('%default' => 'theme://default'))), + array($base_path . '/core/themes/seven', SafeMarkup::format('Get the realpath of %admin.', array('%admin' => 'theme://admin'))), + array($base_path . '/core/themes/seven/fake.info.yml', SafeMarkup::format('Get the realpath of a non-existent resource in %admin.', array('%admin' => 'theme://admin'))), array(new \InvalidArgumentException(), "Fail returning the realpath for an uninstalled theme."), )); @@ -319,12 +326,12 @@ protected function providerThemeStream($method) { array($base_url . 'core/themes/seven/style.css', "Lookup theme's external url for a resource located in a subdirectory."), array($base_url . 'core/themes/bartik/color/preview.js', "Lookup theme's external url for a resource."), array(new \InvalidArgumentException(), "Fail returning a non-existent theme's external url."), - array($base_url . 'core/themes/bartik', String::format('Lookup real external url of %current for a partial URI.', array('%current' => 'theme://current'))), - array($base_url . 'core/themes/bartik/logo.png', String::format('Lookup external url of %current for a resource.', array('%current' => 'theme://current'))), - array($base_url . 'core/themes/bartik', String::format('Lookup external url of %default for a partial URI.', array('%default' => 'theme://default'))), - array($base_url . 'core/themes/bartik/bartik.info.yml', String::format('Lookup external url of %default for a resource.', array('%default' => 'theme://default'))), - array($base_url . 'core/themes/seven', String::format('Lookup external url of %admin for a partial URI.', array('%admin' => 'theme://admin'))), - array($base_url . 'core/themes/seven/fake.info.yml', String::format('Lookup external url of %admin for a resource.', array('%admin' => 'theme://admin'))), + array($base_url . 'core/themes/bartik', SafeMarkup::format('Lookup real external url of %current for a partial URI.', array('%current' => 'theme://current'))), + array($base_url . 'core/themes/bartik/logo.png', SafeMarkup::format('Lookup external url of %current for a resource.', array('%current' => 'theme://current'))), + array($base_url . 'core/themes/bartik', SafeMarkup::format('Lookup external url of %default for a partial URI.', array('%default' => 'theme://default'))), + array($base_url . 'core/themes/bartik/bartik.info.yml', SafeMarkup::format('Lookup external url of %default for a resource.', array('%default' => 'theme://default'))), + array($base_url . 'core/themes/seven', SafeMarkup::format('Lookup external url of %admin for a partial URI.', array('%admin' => 'theme://admin'))), + array($base_url . 'core/themes/seven/fake.info.yml', SafeMarkup::format('Lookup external url of %admin for a resource.', array('%admin' => 'theme://admin'))), array(new \InvalidArgumentException(), "Fail returning a disabled theme's external url."), )); }