diff --git a/core/core.services.yml b/core/core.services.yml index 784d964..4d64d44 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1207,17 +1207,14 @@ services: - { name: stream_wrapper, scheme: temporary } stream_wrapper.module: class: Drupal\Core\StreamWrapper\ModuleStream - arguments: ['@request_stack', '@module_handler'] tags: - { name: stream_wrapper, scheme: module } stream_wrapper.theme: class: Drupal\Core\StreamWrapper\ThemeStream - arguments: ['@request_stack', '@theme_handler', '@theme.negotiator', '@config.factory', '@current_route_match'] tags: - { name: stream_wrapper, scheme: theme } stream_wrapper.profile: class: Drupal\Core\StreamWrapper\ProfileStream - arguments: ['@request_stack'] tags: - { name: stream_wrapper, scheme: profile } kernel_destruct_subscriber: diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php index 490abcd..1b1e371 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(). */ - public function setUri($uri) { + function setUri($uri) { $this->uri = $uri; } /** * Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::getUri(). */ - public function getUri() { + function getUri() { return $this->uri; } @@ -578,5 +578,4 @@ 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 0a878a3..3424c56 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php @@ -24,15 +24,10 @@ class ModuleStream extends SystemStream { /** * Constructs a ModuleStream wrapper object. - * - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack from which the current request is retrieved. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. */ - public function __construct(RequestStack $request_stack, ModuleHandlerInterface $module_handler) { - parent::__construct($request_stack); - $this->moduleHandler = $module_handler; + public function __construct() { + parent::__construct(); + $this->moduleHandler = \Drupal::moduleHandler(); } /** diff --git a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php index ea2297a..7c1c190 100644 --- a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php +++ b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperInterface.php @@ -67,7 +67,6 @@ /** * 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/SystemStream.php b/core/lib/Drupal/Core/StreamWrapper/SystemStream.php index a4d96a8..5bb3ca5 100644 --- a/core/lib/Drupal/Core/StreamWrapper/SystemStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/SystemStream.php @@ -25,12 +25,9 @@ /** * Constructs a new system stream. - * - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack from which the current request is retrieved. */ - public function __construct(RequestStack $request_stack) { - $this->request = $request_stack->getCurrentRequest(); + public function __construct() { + $this->request = \Drupal::service('request_stack')->getCurrentRequest(); } /** diff --git a/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php b/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php index a02b01a..3a60f0f 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php @@ -48,24 +48,13 @@ class ThemeStream extends SystemStream { /** * Constructs a new ThemeStream object. - * - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack from which the current request is retrieved. - * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler - * The theme handler. - * @param \Drupal\Core\Theme\ThemeNegotiatorInterface $theme_negotiator - * The theme negotiator. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config - * The config manager. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The route matcher. */ - public function __construct(RequestStack $request_stack, ThemeHandlerInterface $theme_handler, ThemeNegotiatorInterface $theme_negotiator, ConfigFactoryInterface $config, RouteMatchInterface $route_match) { - parent::__construct($request_stack); - $this->themeHandler = $theme_handler; - $this->themeNegotiator = $theme_negotiator; - $this->configFactory = $config; - $this->routeMatch = $route_match; + public function __construct() { + parent::__construct(); + $this->themeHandler = \Drupal::service('theme_handler'); + $this->themeNegotiator = \Drupal::service('theme.negotiator'); + $this->configFactory = \Drupal::configFactory(); + $this->routeMatch = \Drupal::service('current_route_match'); } /** @@ -77,15 +66,12 @@ 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)) { diff --git a/core/modules/system/src/Tests/File/SystemStreamTest.php b/core/modules/system/src/Tests/File/SystemStreamTest.php index 1f7d42f..5d4d505 100644 --- a/core/modules/system/src/Tests/File/SystemStreamTest.php +++ b/core/modules/system/src/Tests/File/SystemStreamTest.php @@ -9,58 +9,55 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Site\Settings; +use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Drupal\simpletest\KernelTestBase; /** - * Unit tests for system stream wrapper functions. + * Tests system stream wrapper functions. * * @group system */ class SystemStreamTest extends KernelTestBase { /** - * Modules to install for this test. - * - * @var array + * {@inheritdoc} */ - public static $modules = array('system', 'file', 'file_test'); + public static $modules = ['system', 'file', 'file_test']; /** - * The profile to install as a basis for testing. + * The stream wrapper manager service. * - * @var string - */ - protected $profile = 'standard'; - - /** - * {@inheritdoc} + * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface */ - public static function getInfo() { - return array( - 'name' => 'System Stream wrappers', - 'description' => 'Unit tests system stream wrapper functions.', - 'group' => 'File API', - ); - } + protected $streamWrapperManager; /** * {@inheritdoc} */ public function setUp() { parent::setUp(); - drupal_static_reset('file_get_stream_wrappers'); + drupal_static_reset('file_get_stream_wrappers'); + $this->streamWrapperManager = $this->container->get('stream_wrapper_manager'); + + /** @var \Drupal\Core\State\StateInterface $state */ + $state = $this->container->get('state'); + // Add 'minimal' profile to 'system.module.files' state to allow + // drupal_get_profile() to get the profile from state. drupal_get_profile() + // resolves only the current profile but reads also profiles from states. + // @see drupal_get_profile() + $system_module_files = $state->get('system.module.files', []); + $system_module_files += ['minimal' => 'core/profiles/minimal/minimal.info.yml']; + $state->set('system.module.files', $system_module_files); // Add default profile for the purposes of this test. -// new Settings(Settings::getAll() + array( -// 'install_profile' => 'standard' -// )); + new Settings(Settings::getAll() + ['install_profile' => 'minimal']); } /** * Test Invalid stream uri. */ public function testInvalidStreamUriException() { - $bad_uris = array( + $bad_uris = [ 'invalid/uri', 'invalid_uri', 'module/invalid/uri', @@ -71,19 +68,18 @@ public function testInvalidStreamUriException() { 'module//:invalid/uri', 'module//invalid_uri', 'module//invalid/uri', - ); + ]; - /** @var \Drupal\Core\StreamWrapper\ModuleStream $instance */ - $instance = \Drupal::service('stream_wrapper_manager')->getViaScheme('module'); + $instance = $this->streamWrapperManager->getViaScheme('module'); foreach ($bad_uris as $bad_uri) { try { $instance->dirname($bad_uri); - $this->fail(SafeMarkup::format('Invalid uri %uri not detected.', array('%uri' => $bad_uri))); + $this->fail(SafeMarkup::format('Invalid uri %uri not detected.', ['%uri' => $bad_uri])); } catch (\InvalidArgumentException $e) { if ($e->getMessage() == 'Malformed uri parameter passed: ' . $bad_uri) { - $this->pass(SafeMarkup::format('Throw exception on invalid uri %uri supplied.', array('%uri' => $bad_uri))); + $this->pass(SafeMarkup::format('Throw exception on invalid uri %uri supplied.', ['%uri' => $bad_uri])); } else { throw new \InvalidArgumentException($e); @@ -97,66 +93,68 @@ public function testInvalidStreamUriException() { */ public function testModuleStream() { // Generate a module stream wrapper instance. - /** @var \Drupal\Core\StreamWrapper\ModuleStream $instance */ - $instance = \Drupal::service('stream_wrapper_manager')->getViaScheme('module'); + $instance = $this->streamWrapperManager->getViaScheme('module'); - // dirname() - $data = $this->providerModuleStream('dirname'); + // Test dirname(). + $data = $this->moduleStreamTestCasesProvider('dirname'); $this->runTestOnInstanceMethod($instance, 'dirname', $data); - // realpath() - $data = $this->providerModuleStream('realpath'); + // Test realpath(). + $data = $this->moduleStreamTestCasesProvider('realpath'); $this->runTestOnInstanceMethod($instance, 'realpath', $data); - // getExternalUrl() - $data = $this->providerModuleStream('getExternalUrl'); + // Test getExternalUrl(). + $data = $this->moduleStreamTestCasesProvider('getExternalUrl'); $this->runTestOnInstanceMethod($instance, 'getExternalUrl', $data); } /** - * Provides test data for testModuleStream(). + * Provides test cases for testModuleStream(). + * + * @param string $method + * The method to be tested. + * + * @return array + * Associative array with test cases as values, keyed by uri. */ - protected function providerModuleStream($method) { - $uris = array( + protected function moduleStreamTestCasesProvider($method) { + $uris = [ 'module://system', 'module://system/css/system.admin.css', 'module://file_test/file_test.dummy.inc', 'module://file_test/src/file_test.dummy.inc', 'module://ckeditor/ckeditor.info.yml', 'module://foo_bar/foo.bar.js', - ); + ]; switch ($method) { case 'dirname': - return array_combine($uris, array( - array('module://system', 'Get the dirname of an installed module.'), - array('module://system/css', 'Get the dirname of a resource located in a subdirectory of an installed module.'), - array('module://file_test', 'Get the dirname of a resource in a module located in a subdirectory.'), - array('module://file_test/src', 'Get the dirname of a non-existent resource in a subdirectory of a module.'), - array(new \InvalidArgumentException(), 'Fail returning an uninstalled module\'s dirname.'), - array(new \InvalidArgumentException(), 'Fail returning a non-existent module\'s dirname.'), - )); - + return array_combine($uris, [ + 'module://system', + 'module://system/css', + 'module://file_test', + 'module://file_test/src', + [new \InvalidArgumentException(), 'Module ckeditor does not exist or is not installed'], + [new \InvalidArgumentException(), 'Module foo_bar does not exist or is not installed'], + ]); case 'realpath': - $base_path = DRUPAL_ROOT; - return array_combine($uris, array( - array($base_path . '/core/modules/system', 'Get the realpath of an installed module.'), - array($base_path . '/core/modules/system/css/system.admin.css', 'Get the realpath of a resource located in a subdirectory of an installed module.'), - array($base_path . '/core/modules/file/tests/file_test/file_test.dummy.inc', 'Get the realpath of a resource in a module located in a subdirectory.'), - array($base_path . '/core/modules/file/tests/file_test/src/file_test.dummy.inc', 'Get the realpath of a non-existent resource in a subdirectory of a module.'), - array(new \InvalidArgumentException(), 'Fail returning an uninstalled module\'s basepath.'), - array(new \InvalidArgumentException(), 'Fail returning a non-existent module\'s basepath.'), - )); - + return array_combine($uris, [ + DRUPAL_ROOT . '/core/modules/system', + DRUPAL_ROOT . '/core/modules/system/css/system.admin.css', + DRUPAL_ROOT . '/core/modules/file/tests/file_test/file_test.dummy.inc', + DRUPAL_ROOT . '/core/modules/file/tests/file_test/src/file_test.dummy.inc', + [new \InvalidArgumentException(), 'Module ckeditor does not exist or is not installed'], + [new \InvalidArgumentException(), 'Module foo_bar does not exist or is not installed'], + ]); case 'getExternalUrl': $base_url = \Drupal::request()->getUriForPath(base_path()); - return array_combine($uris, array( - array($base_url . 'core/modules/system', "Return the external url for the module directory path."), - array($base_url . 'core/modules/system/css/system.admin.css', "Return the external url of a resource located in a subdirectory."), - array($base_url . 'core/modules/file/tests/file_test/file_test.dummy.inc', "Return the external url of an include file located in a subdirectory."), - array($base_url . 'core/modules/file/tests/file_test/src/file_test.dummy.inc', "Return the external url even for a non-existent resource, as long as the module exists."), - array(new \InvalidArgumentException(), "Fail returning the external uri for resources in a disabled module."), - array(new \InvalidArgumentException(), "Fail returning the external uri for resources in a non-existent module."), - )); + return array_combine($uris, [ + $base_url . 'core/modules/system', + $base_url . 'core/modules/system/css/system.admin.css', + $base_url . 'core/modules/file/tests/file_test/file_test.dummy.inc', + $base_url . 'core/modules/file/tests/file_test/src/file_test.dummy.inc', + [new \InvalidArgumentException(), 'Module ckeditor does not exist or is not installed'], + [new \InvalidArgumentException(), 'Module foo_bar does not exist or is not installed'], + ]); } } @@ -165,67 +163,69 @@ protected function providerModuleStream($method) { */ public function testProfileStream() { // Generate a profile stream wrapper instance. - /** @var \Drupal\Core\StreamWrapper\ProfileStream $instance */ - $instance = \Drupal::service('stream_wrapper_manager')->getViaScheme('profile'); + $instance = $this->streamWrapperManager->getViaScheme('profile'); - // dirname() - $data = $this->providerProfileStream('dirname'); + // Test dirname(). + $data = $this->profileStreamTestCasesProvider('dirname'); $this->runTestOnInstanceMethod($instance, 'dirname', $data); - // realpath() - $data = $this->providerProfileStream('realpath'); + // Test realpath(). + $data = $this->profileStreamTestCasesProvider('realpath'); $this->runTestOnInstanceMethod($instance, 'realpath', $data); - // getExternalUrl() - $data = $this->providerProfileStream('getExternalUrl'); + // Test getExternalUrl(). + $data = $this->profileStreamTestCasesProvider('getExternalUrl'); $this->runTestOnInstanceMethod($instance, 'getExternalUrl', $data); } /** - * Provides test data for testProfileStream(). + * Provides test cases for testProfileStream(). + * + * @param string $method + * The method to be tested. + * + * @return array + * Associative array with test cases as values, keyed by uri. */ - protected function providerProfileStream($method) { - $uris = array( + protected function profileStreamTestCasesProvider($method) { + $uris = [ 'profile://minimal', 'profile://minimal/config/install/block.block.stark_login.yml', 'profile://minimal/config/install/node.type.article.yml', 'profile://foo_bar/', 'profile://current', - 'profile://current/standard.info.yml', - ); + 'profile://current/minimal.info.yml', + ]; switch ($method) { case 'dirname': - return array_combine($uris, array( - array('profile://minimal', "Get the dirname of an installed profile."), - 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', 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'))), - )); - + return array_combine($uris, [ + 'profile://minimal', + 'profile://minimal/config/install', + 'profile://minimal/config/install', + [new \InvalidArgumentException(), 'Profile foo_bar does not exist'], + 'profile://minimal', + 'profile://minimal', + ]); case 'realpath': - $base_path = DRUPAL_ROOT; - return array_combine($uris, array( - array($base_path . '/core/profiles/minimal', "Get the realpath of an installed profile."), - 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', 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'))), - )); - + return array_combine($uris, [ + DRUPAL_ROOT . '/core/profiles/minimal', + DRUPAL_ROOT . '/core/profiles/minimal/config/install/block.block.stark_login.yml', + DRUPAL_ROOT . '/core/profiles/minimal/config/install/node.type.article.yml', + [new \InvalidArgumentException(), 'Profile foo_bar does not exist'], + DRUPAL_ROOT . '/core/profiles/minimal', + DRUPAL_ROOT . '/core/profiles/minimal/minimal.info.yml', + ]); case 'getExternalUrl': $base_url = \Drupal::request()->getUriForPath(base_path()); - return array_combine($uris, array( - array($base_url . 'core/profiles/minimal', "Return the external url for the profile directory path."), - 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', 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'))), - )); + return array_combine($uris, [ + $base_url . 'core/profiles/minimal', + $base_url . 'core/profiles/minimal/config/install/block.block.stark_login.yml', + $base_url . 'core/profiles/minimal/config/install/node.type.article.yml', + [new \InvalidArgumentException(), 'Profile foo_bar does not exist'], + $base_url . 'core/profiles/minimal', + $base_url . 'core/profiles/minimal/minimal.info.yml', + ]); } } @@ -233,47 +233,56 @@ protected function providerProfileStream($method) { * Test the Theme stream wrapper functions. */ public function testThemeStream() { - // Generate a theme stream wrapper instance. - /** @var \Drupal\Core\Extension\ThemeHandler $theme_handler */ - $theme_handler = \Drupal::service('theme_handler'); + /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */ + $config_factory = $this->container->get('config.factory'); + /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */ + $theme_installer = $this->container->get('theme_installer'); + /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */ + $theme_handler = $this->container->get('theme_handler'); // Install Stark, Bartik and Seven themes. - $theme_handler->install(array('bartik', 'seven', 'stark')); + $theme_installer->install(['bartik', 'seven', 'stark']); // Set admin theme to Seven. - $system_theme = \Drupal::configFactory()->getEditable('system.theme'); - $this->assertNull($system_theme->get('admin'), 'No admin theme was set.'); + $system_theme = $config_factory->getEditable('system.theme'); + $this->assertNull($system_theme->get('admin')); $system_theme->set('admin', 'seven')->save(); - $this->assertEqual($system_theme->get('admin'), 'seven', SafeMarkup::format('Make %seven the admin theme.', array('%seven' => 'Seven'))); + $this->assertEqual($system_theme->get('admin'), 'seven'); // Set default theme to Bartik. $theme_handler->setDefault('bartik'); - $this->assertEqual($theme_handler->getDefault(), 'bartik', SafeMarkup::format('Make %bartik the default theme.', array('%bartik' => 'Bartik'))); + $this->assertEqual($theme_handler->getDefault(), 'bartik'); // Uninstall Stark theme. - $theme_handler->uninstall(array('stark')); + $theme_installer->uninstall(['stark']); - /** @var \Drupal\Core\StreamWrapper\ThemeStream $instance */ - $instance = \Drupal::service('stream_wrapper_manager')->getViaScheme('theme'); + // Generate a theme stream wrapper instance. + $instance = $this->streamWrapperManager->getViaScheme('theme'); - // dirname() - $data = $this->providerThemeStream('dirname'); + // Test dirname(). + $data = $this->themeStreamTestCasesProvider('dirname'); $this->runTestOnInstanceMethod($instance, 'dirname', $data); - // realpath() - $data = $this->providerThemeStream('realpath'); + // Test realpath(). + $data = $this->themeStreamTestCasesProvider('realpath'); $this->runTestOnInstanceMethod($instance, 'realpath', $data); - // getExternalUrl() - $data = $this->providerThemeStream('getExternalUrl'); + // Test getExternalUrl(). + $data = $this->themeStreamTestCasesProvider('getExternalUrl'); $this->runTestOnInstanceMethod($instance, 'getExternalUrl', $data); } /** - * Provides test data for testThemeStream() + * Provides test cases for testThemeStream(). + * + * @param string $method + * The method to be tested. + * + * @return array + * Associative array with test cases as values, keyed by uri. */ - protected function providerThemeStream($method) { - $uris = array( + protected function themeStreamTestCasesProvider($method) { + $uris = [ 'theme://seven', 'theme://seven/style.css', 'theme://bartik/color/preview.js', @@ -285,55 +294,52 @@ protected function providerThemeStream($method) { 'theme://admin', 'theme://admin/fake.info.yml', 'theme://stark/stark.info.yml', - ); + ]; switch ($method) { case 'dirname': - return array_combine($uris, array( - array('theme://seven', "Get the dirname of an installed theme."), - 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', 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."), - )); - + return array_combine($uris, [ + 'theme://seven', + 'theme://seven', + 'theme://bartik/color', + [new \InvalidArgumentException(), 'Theme fifteen does not exist or is not installed'], + 'theme://bartik', + 'theme://bartik', + 'theme://bartik', + 'theme://bartik', + 'theme://seven', + 'theme://seven', + [new \InvalidArgumentException(), 'Theme stark does not exist or is not installed'], + ]); case 'realpath': - $base_path = DRUPAL_ROOT; - return array_combine($uris, array( - array($base_path . '/core/themes/seven', "Get the realpath of an installed theme."), - 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', 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."), - )); - + return array_combine($uris, [ + DRUPAL_ROOT . '/core/themes/seven', + DRUPAL_ROOT . '/core/themes/seven/style.css', + DRUPAL_ROOT . '/core/themes/bartik/color/preview.js', + [new \InvalidArgumentException(), 'Theme fifteen does not exist or is not installed'], + DRUPAL_ROOT . '/core/themes/bartik', + DRUPAL_ROOT . '/core/themes/bartik/logo.png', + DRUPAL_ROOT . '/core/themes/bartik', + DRUPAL_ROOT . '/core/themes/bartik/bartik.info.yml', + DRUPAL_ROOT . '/core/themes/seven', + DRUPAL_ROOT . '/core/themes/seven/fake.info.yml', + [new \InvalidArgumentException(), 'Theme stark does not exist or is not installed'], + ]); case 'getExternalUrl': $base_url = \Drupal::request()->getUriForPath(base_path()); - return array_combine($uris, array( - array($base_url . 'core/themes/seven', "Lookup theme's external url for a partial URI."), - 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', 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."), - )); + return array_combine($uris, [ + $base_url . 'core/themes/seven', + $base_url . 'core/themes/seven/style.css', + $base_url . 'core/themes/bartik/color/preview.js', + [new \InvalidArgumentException(), 'Theme fifteen does not exist or is not installed'], + $base_url . 'core/themes/bartik', + $base_url . 'core/themes/bartik/logo.png', + $base_url . 'core/themes/bartik', + $base_url . 'core/themes/bartik/bartik.info.yml', + $base_url . 'core/themes/seven', + $base_url . 'core/themes/seven/fake.info.yml', + [new \InvalidArgumentException(), "Theme stark does not exist or is not installed"], + ]); } } @@ -341,7 +347,7 @@ protected function providerThemeStream($method) { /** * Helper method to run specific tests on each StreamWrapper method. * - * @param \Drupal\Core\StreamWrapper\SystemStream $instance + * @param \Drupal\Core\StreamWrapper\StreamWrapperInterface $instance * The stream wrapper instance to carry out the test on. * @param string $method * The SystemStream method to be tested. @@ -350,27 +356,40 @@ protected function providerThemeStream($method) { * - The expected result. * - The test result message. */ - private function runTestOnInstanceMethod($instance, $method, array $data) { + private function runTestOnInstanceMethod(StreamWrapperInterface $instance, $method, array $data) { foreach ($data as $uri => $info) { $instance->setUri($uri); - if ($info[0] instanceof \InvalidArgumentException) { + if (is_array($info)) { + $message = sprintf('Exception thrown: \InvalidArgumentException("%s").', $info[1]); try { $instance->$method(); - $this->fail($info[1]); + $this->fail($message); } catch (\InvalidArgumentException $e) { - $this->pass($info[1]); + $this->assertIdentical($e->getMessage(), $info[1], $message); } } else { if ($method == 'realpath') { - // realpath() returns strings with the OS-specific DIRECTORY_SEPARATOR, - // make sure we are testing for that. - $info[0] = str_replace('/', DIRECTORY_SEPARATOR, $info[0]); + // realpath() returns strings with OS-specific DIRECTORY_SEPARATOR. + $info = str_replace('/', DIRECTORY_SEPARATOR, $info); } - $this->assertEqual($instance->$method(), $info[0], $info[1]); + $this->assertEqual($instance->$method(), $info); } } } + /** + * {@inheritdoc} + */ + public function errorHandler($severity, $message, $file = NULL, $line = NULL) { + // When dealing with an unknown module/profile, drupal_get_filename() + // triggers an error. We want to mute this error because we catch this as + // exception. + // @see drupal_get_filename() + if ($severity != E_USER_WARNING || strpos($message, 'The following module is missing from the file system: ') !== 0) { + parent::errorHandler($severity, $message, $file, $line); + } + } + }