diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php index 4419419..fbec988 100644 --- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php @@ -50,7 +50,7 @@ * @return string * String specifying the path. */ - abstract function getDirectoryPath(); + protected abstract function getDirectoryPath(); /** * Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::setUri(). diff --git a/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php b/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php index b56f183..a3df6e3 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ModuleStream.php @@ -15,27 +15,24 @@ class ModuleStream extends SystemStream { /** * {@inheritdoc} */ - public function getOwnerName($uri = NULL) { - $name = parent::getOwnerName($uri); + protected function getOwnerName() { + $name = parent::getOwnerName(); if (\Drupal::moduleHandler()->moduleExists($name)) { return $name; } else { - // The module does not exist or is not enabled. - throw new \InvalidArgumentException(sprintf('Module %s does not exist or is not enabled', $name)); + // The module does not exist or is not installed. + throw new \InvalidArgumentException(sprintf('Module %s does not exist or is not installed', $name)); } } /** * Gets the module's directory path. * - * @param string $uri - * Optional URI. - * * @return string * String specifying the path. */ - public function getDirectoryPath($uri = NULL) { - return drupal_get_path('module', $this->getOwnerName($uri)); + protected function getDirectoryPath() { + return drupal_get_path('module', $this->getOwnerName()); } } diff --git a/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php b/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php index 0e1fd62..eff73ed 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php @@ -15,8 +15,8 @@ class ProfileStream extends SystemStream { /** * {@inheritdoc} */ - public function getOwnerName($uri = NULL) { - $name = parent::getOwnerName($uri); + protected function getOwnerName() { + $name = parent::getOwnerName(); if ($name == 'current') { $name = drupal_get_profile(); } @@ -33,13 +33,10 @@ public function getOwnerName($uri = NULL) { /** * Gets the profile's directory path. * - * @param string $uri - * Optional URI. - * * @return string * String specifying the path. */ - public function getDirectoryPath($uri = NULL) { - return drupal_get_path('profile', $this->getOwnerName($uri)); + protected function getDirectoryPath() { + return drupal_get_path('profile', $this->getOwnerName()); } } diff --git a/core/lib/Drupal/Core/StreamWrapper/SystemStream.php b/core/lib/Drupal/Core/StreamWrapper/SystemStream.php index 019cf88..c337400 100644 --- a/core/lib/Drupal/Core/StreamWrapper/SystemStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/SystemStream.php @@ -20,23 +20,16 @@ /** * Get the module, theme, or profile name of the current URI. * - * @param string $uri - * Optional URI. - * * @return string * The extension name. * * @throws \InvalidArgumentException */ - public function getOwnerName($uri = NULL) { - if (!isset($uri)) { - $uri = $this->uri; - } - - $uri_parts = explode('://', $uri, 2); + protected function getOwnerName() { + $uri_parts = explode('://', $this->uri, 2); if (count($uri_parts) === 1) { // The delimiter ('://') was not found in $uri, malformed $uri passed. - throw new \InvalidArgumentException(sprintf('Malformed uri parameter passed: %s', $uri)); + throw new \InvalidArgumentException(sprintf('Malformed uri parameter passed: %s', $this->uri)); } // Remove the trailing filename from the path. @@ -47,14 +40,8 @@ public function getOwnerName($uri = NULL) { /** * {@inheritdoc} */ - public function getTarget($uri = NULL) { - $target = strstr(parent::getTarget($uri), '/') ?: ''; - if (file_exists($this->getDirectoryPath($uri) . $target)) { - return trim($target, '/'); - } - else { - throw new \InvalidArgumentException(sprintf('File %s does not exist', $uri)); - } + protected function getTarget($uri = NULL) { + return rtrim(strstr(parent::getTarget($uri), '/') ?: '', '/'); } /** @@ -73,18 +60,30 @@ public function getTarget($uri = NULL) { * * @throws \InvalidArgumentException */ - public function getExternalUrl($uri = NULL) { - $dir = $this->getDirectoryPath($uri); + public function getExternalUrl() { + $dir = $this->getDirectoryPath(); if (empty($dir)) { - throw new \InvalidArgumentException(sprintf('Extension directory for %s does not exist.', $uri)); + throw new \InvalidArgumentException(sprintf('Extension directory for %s does not exist.', $this->uri)); } + return \Drupal::request()->getUriForPath(base_path() . $dir . $this->getTarget()); + } - // Find the path following the owner name. - if ($path = strstr(parent::getTarget($uri), '/')) { - // Clean the path. - $path = rtrim(UrlHelper::encodePath(str_replace('\\', '/', $path)), '/'); + /** + * {@inheritdoc} + */ + public function dirname($uri = NULL) { + if (!isset($uri)) { + $uri = $this->uri; + } + list($scheme) = explode('://', $uri, 2); + $target = $this->getTarget($uri); + $dirname = dirname($target); + + if ($dirname == '.') { + $dirname = ''; } - return \Drupal::request()->getUriForPath('/' . $dir . $path); + return rtrim($scheme . '://' . $this->getOwnerName() . $dirname, '/'); } + } diff --git a/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php b/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php index b7aa3ab..c6c4c48 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ThemeStream.php @@ -15,40 +15,37 @@ class ThemeStream extends SystemStream { /** * {@inheritdoc} */ - public function getOwnerName($uri = NULL) { - $name = parent::getOwnerName($uri); + protected function getOwnerName() { + $name = parent::getOwnerName(); switch ($name) { case 'current': $name = $this->getActiveTheme(); break; case 'default': - $name = \Drupal::config('system.theme')->get('default'); + $name = $this->themeHandler()->getDefault(); break; case 'admin': - $name = \Drupal::config('system.theme')->get('admin'); + $name = \Drupal::config('system.theme')->get('admin'); break; } - // Return name only for enabled themes. - if (array_key_exists($name, \Drupal::service('theme_handler')->listInfo())) { + // Return name only for installed themes. + if ($this->themeHandler()->themeExists($name)) { return $name; } else { - // The theme does not exist or is disabled. - throw new \InvalidArgumentException(sprintf('Theme %s does not exist or is disabled', $name)); + // The theme does not exist or is not installed. + throw new \InvalidArgumentException(sprintf('Theme %s does not exist or is not installed', $name)); } } /** * Gets the theme's directory path. * - * @param string $uri - * Optional URI. - * * @return string * String specifying the path. */ - public function getDirectoryPath($uri = NULL) { - return drupal_get_path('theme', $this->getOwnerName($uri)); + protected function getDirectoryPath() { + return drupal_get_path('theme', $this->getOwnerName()); } /** @@ -57,4 +54,13 @@ public function getDirectoryPath($uri = NULL) { protected function getActiveTheme() { return \Drupal::service('theme.negotiator')->determineActiveTheme(\Drupal::service('current_route_match')); } + + /** + * Wraps the theme handler service. + * + * @return \Drupal\Core\Extension\ThemeHandler + */ + protected function themeHandler() { + return \Drupal::service('theme_handler'); + } } diff --git a/core/modules/block/tests/modules/block_test/block_test.module b/core/modules/block/tests/modules/block_test/block_test.module index a573faa..d4bf97f 100644 --- a/core/modules/block/tests/modules/block_test/block_test.module +++ b/core/modules/block/tests/modules/block_test/block_test.module @@ -8,14 +8,6 @@ use Drupal\Core\Block\BlockPluginInterface; /** - * Implements hook_system_theme_info(). - */ -function block_test_system_theme_info() { - $themes['block_test_theme'] = "module://block_test/themes/block_test_theme/block_test_theme.info.yml"; - return $themes; -} - -/** * Implements hook_block_alter(). */ function block_test_block_alter(&$block_info) { diff --git a/core/modules/breakpoint/tests/breakpoint_theme_test.module b/core/modules/breakpoint/tests/breakpoint_theme_test.module deleted file mode 100644 index 57e8888..0000000 --- a/core/modules/breakpoint/tests/breakpoint_theme_test.module +++ /dev/null @@ -1,13 +0,0 @@ -moduleFiles)) { $this->moduleFiles = \Drupal::state()->get('system.module.files') ?: array(); $this->themeFiles = \Drupal::state()->get('system.theme.files') ?: array(); - $this->themeData = \Drupal::state()->get('system.theme.data') ?: array(); } } @@ -175,7 +173,6 @@ protected function setUp() { if ($this->container->get('keyvalue') instanceof KeyValueMemoryFactory) { $this->container->get('state')->set('system.module.files', $this->moduleFiles); $this->container->get('state')->set('system.theme.files', $this->themeFiles); - $this->container->get('state')->set('system.theme.data', $this->themeData); } // Create a minimal core.extension configuration object so that the list of diff --git a/core/modules/system/src/Tests/File/SystemStreamTest.php b/core/modules/system/src/Tests/File/SystemStreamTest.php index 75d4be9..b43b836 100644 --- a/core/modules/system/src/Tests/File/SystemStreamTest.php +++ b/core/modules/system/src/Tests/File/SystemStreamTest.php @@ -19,7 +19,7 @@ class SystemStreamTest extends KernelTestBase { /** - * Modules to enable. + * Modules to install for this test. * * @var array */ @@ -43,20 +43,13 @@ public function setUp() { parent::setUp(); drupal_static_reset('file_get_stream_wrappers'); - // Add default profile for the purposes of this test + // Add default profile for the purposes of this test. new Settings(Settings::getAll() + array( 'install_profile' => 'standard' )); } /** - * {@inheritdoc} - */ - public function tearDown() { - parent::tearDown(); - } - - /** * Test Invalid stream uri. */ public function testInvalidStreamUriException() { @@ -78,11 +71,16 @@ public function testInvalidStreamUriException() { foreach ($bad_uris as $bad_uri) { try { - $instance->getOwnerName($bad_uri); + $instance->dirname($bad_uri); $this->fail(String::format('Invalid uri %uri not detected.', array('%uri' => $bad_uri))); } catch (\InvalidArgumentException $e) { - $this->pass(String::format('Throw exception on invalid uri %uri supplied.', array('%uri' => $bad_uri))); + if ($e->getMessage() == 'Malformed uri parameter passed: ' . $bad_uri) { + $this->pass(String::format('Throw exception on invalid uri %uri supplied.', array('%uri' => $bad_uri))); + } + else { + throw new \InvalidArgumentException($e); + } } } } @@ -95,17 +93,13 @@ public function testModuleStream() { /** @var \Drupal\Core\StreamWrapper\ModuleStream $instance */ $instance = file_stream_wrapper_get_instance_by_scheme('module'); - // getOwnerName() - $data = $this->providerModuleStream('getOwnerName'); - $this->runTestOnInstanceMethod($instance, 'getOwnerName', $data); - - // getTarget() - $data = $this->providerModuleStream('getTarget'); - $this->runTestOnInstanceMethod($instance, 'getTarget', $data); + // dirname() + $data = $this->providerModuleStream('dirname'); + $this->runTestOnInstanceMethod($instance, 'dirname', $data); - // getDirectoryPath() - $data = $this->providerModuleStream('getDirectoryPath'); - $this->runTestOnInstanceMethod($instance, 'getDirectoryPath', $data); + // realpath() + $data = $this->providerModuleStream('realpath'); + $this->runTestOnInstanceMethod($instance, 'realpath', $data); // getExternalUrl() $data = $this->providerModuleStream('getExternalUrl'); @@ -120,51 +114,41 @@ protected function providerModuleStream($method) { 'module://system', 'module://system/css/system.admin.css', 'module://file_test/file_test.dummy.inc', - 'module://file_test/includes/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 'getOwnerName': + case 'dirname': return array_combine($uris, array( - array('system', 'Extract module name from a partial URI.'), - array('system', 'Extract module name for a resource located in a subdirectory.'), - array('file_test', 'Extract module name for a module located in a subdirectory.'), - array('file_test', 'Extract module name even for a non-existing resource, as long as the module exists.'), - array(new \InvalidArgumentException(), 'Fail returning a disabled module\'s name.'), - array(new \InvalidArgumentException(), 'Fail returning a non-existing module\'s name.'), + 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.'), )); - case 'getTarget': + case 'realpath': + $base_path = DRUPAL_ROOT; return array_combine($uris, array( - array('', 'Return empty target from a partial URI.'), - array('css/system.admin.css', 'Extract target for a resource located in a subdirectory.'), - array('file_test.dummy.inc', 'Extract target for a module in a non-standard location.'), - array(new \InvalidArgumentException(), 'Fail extracting a target for a non-existing resource.'), - array(new \InvalidArgumentException(), 'Fail extracting a target within a disabled module.'), - array(new \InvalidArgumentException(), 'Fail extracting a target within a non-existing module.'), - )); - - case 'getDirectoryPath': - return array_combine($uris, array( - array('core/modules/system', "Lookup module's directory path for a partial URI."), - array('core/modules/system', "Lookup module's directory path for a resource located in a subdirectory."), - array('core/modules/file/tests/file_test', "Lookup module's directory path for a module located in a subdirectory."), - array('core/modules/file/tests/file_test', "Lookup module's directory path even for a non-existing resource, as long as the module exists."), - array(new \InvalidArgumentException(), "Fail lookup of a disabled module's directory path"), - array(new \InvalidArgumentException(), "Fail lookup of a non-existing module's directory path."), + 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.'), )); case 'getExternalUrl': - $base_url = \Drupal::request()->getUri(); + $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/includes/file_test.dummy.inc', "Return the external url even for a non-existing resource, as long as the module exists."), + 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-existing module."), + array(new \InvalidArgumentException(), "Fail returning the external uri for resources in a non-existent module."), )); } } @@ -177,17 +161,13 @@ public function testProfileStream() { /** @var \Drupal\Core\StreamWrapper\ProfileStream $instance */ $instance = file_stream_wrapper_get_instance_by_scheme('profile'); - // getOwnerName() - $data = $this->providerProfileStream('getOwnerName'); - $this->runTestOnInstanceMethod($instance, 'getOwnerName', $data); - - // getTarget() - $data = $this->providerProfileStream('getTarget'); - $this->runTestOnInstanceMethod($instance, 'getTarget', $data); + // dirname() + $data = $this->providerProfileStream('dirname'); + $this->runTestOnInstanceMethod($instance, 'dirname', $data); - // getDirectoryPath() - $data = $this->providerProfileStream('getDirectoryPath'); - $this->runTestOnInstanceMethod($instance, 'getDirectoryPath', $data); + // realpath() + $data = $this->providerProfileStream('realpath'); + $this->runTestOnInstanceMethod($instance, 'realpath', $data); // getExternalUrl() $data = $this->providerProfileStream('getExternalUrl'); @@ -208,42 +188,33 @@ protected function providerProfileStream($method) { ); switch ($method) { - case 'getOwnerName': - return array_combine($uris, array( - array('minimal', "Extract profile's name from a partial URI."), - array('minimal', "Extract profile's name for a resource located in a subdirectory."), - array('minimal', "Extract profile's name even for a non-existing resource, as long as the profile exists."), - array(new \InvalidArgumentException(), "Fail returning a non-existing profile's name."), - array('standard', String::format('Lookup real name of %current for a partial URI.', array('%current' => 'profile://current'))), - array('standard', String::format('Lookup real name of %current for a resource.', array('%current' => 'profile://current'))), - )); - - case 'getTarget': + case 'dirname': return array_combine($uris, array( - array('', 'Return empty target for a partial URI giving only the profile.'), - array('config/install/block.block.stark_login.yml', 'Extract target for a resource located in a subdirectory.'), - array(new \InvalidArgumentException(), 'Fail returning a target for a non-existing resource.'), - array(new \InvalidArgumentException(), 'Fail returning a target within a non-existing profile.'), - array('', String::format('Return empty target for a partial URI giving only %current.', array('%current' => 'profile://current'))), - array('standard.info.yml', String::format("Extract target from a resource within %current.", array('%current' => 'profile://current'))), + 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', 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'))), )); - case 'getDirectoryPath': + case 'realpath': + $base_path = DRUPAL_ROOT; return array_combine($uris, array( - array('core/profiles/minimal', "Lookup profile's directory path for a partial URI."), - array('core/profiles/minimal', "Lookup profile's directory path for a resource located in a subdirectory."), - array('core/profiles/minimal', "Lookup profile's directory path even for a non-existing resource, as long as the profile exists."), - array(new \InvalidArgumentException(), "Fail returning a non-existing profile's directory path."), - array('core/profiles/standard', String::format('Lookup real directory path of %current for a partial URI.', array('%current' => 'profile://current'))), - array('core/profiles/standard', String::format('Lookup real directory path of %current for a resource.', array('%current' => 'profile://current'))), + 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', 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'))), )); case 'getExternalUrl': - $base_url = \Drupal::request()->getUri(); + $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-existing 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'))), @@ -259,8 +230,8 @@ public function testThemeStream() { /** @var \Drupal\Core\Extension\ThemeHandler $theme_handler */ $theme_handler = \Drupal::service('theme_handler'); - // Enable Stark, Bartik and Seven themes. - $theme_handler->enable(array('bartik', 'seven', 'stark')); + // Install Stark, Bartik and Seven themes. + $theme_handler->install(array('bartik', 'seven', 'stark')); // Set admin theme to Seven. $system_theme = \Drupal::config('system.theme'); @@ -272,23 +243,19 @@ public function testThemeStream() { $theme_handler->setDefault('bartik'); $this->assertEqual($theme_handler->getDefault(), 'bartik', String::format('Make %bartik the default theme.', array('%bartik' => 'Bartik'))); - // Disable Stark theme. - $theme_handler->disable(array('stark')); + // Uninstall Stark theme. + $theme_handler->uninstall(array('stark')); /** @var \Drupal\Core\StreamWrapper\ThemeStream $instance */ $instance = file_stream_wrapper_get_instance_by_scheme('theme'); - // getOwnerName() - $data = $this->providerThemeStream('getOwnerName'); - $this->runTestOnInstanceMethod($instance, 'getOwnerName', $data); + // dirname() + $data = $this->providerThemeStream('dirname'); + $this->runTestOnInstanceMethod($instance, 'dirname', $data); - // getTarget() - $data = $this->providerThemeStream('getTarget'); - $this->runTestOnInstanceMethod($instance, 'getTarget', $data); - - // getDirectoryPath() - $data = $this->providerThemeStream('getDirectoryPath'); - $this->runTestOnInstanceMethod($instance, 'getDirectoryPath', $data); + // realpath() + $data = $this->providerThemeStream('realpath'); + $this->runTestOnInstanceMethod($instance, 'realpath', $data); // getExternalUrl() $data = $this->providerThemeStream('getExternalUrl'); @@ -314,58 +281,44 @@ protected function providerThemeStream($method) { ); switch ($method) { - case 'getOwnerName': + case 'dirname': return array_combine($uris, array( - array('seven', "Extract theme's name from a partial URI."), - array('seven', "Extract theme's name from a full URI."), - array('bartik', "Extract theme's name from a full URI with subdirectory."), - array(new \InvalidArgumentException(), "Fail returning a non-existing theme's name."), - array('bartik', String::format('Lookup real name of %current for a partial URI.', array('%current' => 'theme://current'))), - array('bartik', String::format('Lookup real name of %current for a resource.', array('%current' => 'theme://current'))), - array('bartik', String::format('Lookup real name of %default for a partial URI.', array('%default' => 'theme://default'))), - array('bartik', String::format('Lookup real name of %default for a resource.', array('%default' => 'theme://default'))), - array('seven', String::format('Lookup real name of %admin for a partial URI.', array('%admin' => 'theme://admin'))), - array('seven', String::format('Lookup real name of %admin even for a non-existing resource.', array('%admin' => 'theme://admin'))), - array(new \InvalidArgumentException(), "Fail returning a disabled theme's name."), + 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', 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(new \InvalidArgumentException(), "Fail returning the dirname for an uninstalled theme."), )); - case 'getTarget': + case 'realpath': + $base_path = DRUPAL_ROOT; return array_combine($uris, array( - array('', 'Return empty target for a partial URI giving only the theme.'), - array(new \InvalidArgumentException(), 'Fail returning a target for a non-existent resource.'), - array('color/preview.js', 'Extract target for a resource located in a subdirectory.'), - array(new \InvalidArgumentException(), 'Fail returning a target within a non-existing theme.'), - array('', String::format('Return empty target for a partial URI giving only %current.', array('%current' => 'theme://current'))), - array('logo.png', String::format("Extract target from a resource within %current.", array('%current' => 'theme://current'))), - array('', String::format('Return empty target for a partial URI giving only %default.', array('%default' => 'theme://default'))), - array('bartik.info.yml', String::format("Extract target from a resource located in a subdirectory of %default.", array('%default' => 'theme://default'))), - array('', String::format('Return empty target for a partial URI giving only %admin.', array('%admin' => 'theme://admin'))), - array(new \InvalidArgumentException(), String::format("Fail returning target for a non-existing resource within %admin.", array('%admin' => 'theme://admin'))), - array(new \InvalidArgumentException(), "Fail returning a target for a disabled theme."), - )); - - case 'getDirectoryPath': - return array_combine($uris, array( - array('core/themes/seven', "Lookup theme's directory path for a partial URI."), - array('core/themes/seven', "Lookup theme's directory path for a resource located in a subdirectory."), - array('core/themes/bartik', "Lookup theme's directory path for a resource."), - array(new \InvalidArgumentException(), "Fail returning a non-existing theme's directory path."), - array('core/themes/bartik', String::format('Lookup real directory path of %current for a partial URI.', array('%current' => 'theme://current'))), - array('core/themes/bartik', String::format('Lookup real directory path of %current for a resource.', array('%current' => 'theme://current'))), - array('core/themes/bartik', String::format('Lookup real directory path of %default for a partial URI.', array('%default' => 'theme://default'))), - array('core/themes/bartik', String::format('Lookup real directory path of %default for a resource.', array('%default' => 'theme://default'))), - array('core/themes/seven', String::format('Lookup real directory path of %admin for a partial URI.', array('%admin' => 'theme://admin'))), - array('core/themes/seven', String::format('Lookup real directory path of %admin for a resource.', array('%admin' => 'theme://admin'))), - array(new \InvalidArgumentException(), "Fail returning a disabled theme's directory path."), + 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', 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(new \InvalidArgumentException(), "Fail returning the realpath for an uninstalled theme."), )); case 'getExternalUrl': - $base_url = \Drupal::request()->getUri(); + $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-existing theme's external url."), + 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'))), @@ -392,22 +345,18 @@ protected function providerThemeStream($method) { */ private function runTestOnInstanceMethod($instance, $method, array $data) { foreach ($data as $uri => $info) { - if ($info[0] instanceof \Exception) { + $instance->setUri($uri); + if ($info[0] instanceof \InvalidArgumentException) { try { - $instance->$method($uri); + $instance->$method(); $this->fail($info[1]); } - catch (\Exception $e) { - if (get_class($e) == get_class($info[0])) { - $this->pass($info[1]); - } + catch (\InvalidArgumentException $e) { + $this->pass($info[1]); } } else { - if (!$this->assertEqual($instance->$method($uri), $info[0], $info[1])) { - debug($instance->$method($uri), get_class($instance) . "::$method('$uri')"); - debug($info[0], 'expected'); - } + $this->assertEqual($instance->$method(), $info[0], $info[1]); } } } diff --git a/core/modules/system/tests/modules/ajax_test/ajax_test.module b/core/modules/system/tests/modules/ajax_test/ajax_test.module index 2799a89..6127b2e 100644 --- a/core/modules/system/tests/modules/ajax_test/ajax_test.module +++ b/core/modules/system/tests/modules/ajax_test/ajax_test.module @@ -13,14 +13,6 @@ use Drupal\Core\Ajax\HtmlCommand; /** - * Implements hook_system_theme_info(). - */ -function ajax_test_system_theme_info() { - $themes['test_theme'] = "module://system/tests/themes/test_theme/test_theme.info.yml"; - return $themes; -} - -/** * Menu callback: Returns an element suitable for use by * \Drupal\Core\Ajax\AjaxResponse::ajaxRender(). * diff --git a/core/modules/system/tests/modules/theme_test/theme_test.module b/core/modules/system/tests/modules/theme_test/theme_test.module index c9a103d..dd71fb7 100644 --- a/core/modules/system/tests/modules/theme_test/theme_test.module +++ b/core/modules/system/tests/modules/theme_test/theme_test.module @@ -51,21 +51,13 @@ function theme_test_theme($existing, $type, $theme, $path) { $items['theme_test_function_template_override'] = array( 'variables' => array(), ); + $info['test_theme_not_existing_function'] = array( + 'function' => 'test_theme_not_existing_function', + ); return $items; } /** - * Implements hook_system_theme_info(). - */ -function theme_test_system_theme_info() { - $themes['test_theme'] = "module://system/tests/themes/test_theme/test_theme.info.yml"; - $themes['test_basetheme'] = "module://system/tests/themes/test_basetheme/test_basetheme.info.yml"; - $themes['test_subtheme'] = "module://system/tests/themes/test_subtheme/test_subtheme.info.yml"; - $themes['test_theme_phptemplate'] = "module://system/tests/themes/test_theme_phptemplate/test_theme_phptemplate.info.yml"; - return $themes; -} - -/** * Implements hook_preprocess_HOOK() for HTML document templates. */ function theme_test_preprocess_html(&$variables) { diff --git a/core/modules/update/tests/modules/update_test/update_test.module b/core/modules/update/tests/modules/update_test/update_test.module index b2cabcb..93c97f4 100644 --- a/core/modules/update/tests/modules/update_test/update_test.module +++ b/core/modules/update/tests/modules/update_test/update_test.module @@ -10,15 +10,6 @@ */ /** - * Implements hook_system_theme_info(). - */ -function update_test_system_theme_info() { - $themes['update_test_basetheme'] = "module://update/tests/themes/update_test_basetheme/update_test_basetheme.info.yml"; - $themes['update_test_subtheme'] = "module://update/tests/themes/update_test_subtheme/update_test_subtheme.info.yml"; - return $themes; -} - -/** * Implements hook_system_info_alter(). * * Checks the 'update_test.settings:system_info' configuration and sees if we