diff --git a/core/lib/Drupal/Core/StreamWrapper/ExtensionStreamBase.php b/core/lib/Drupal/Core/StreamWrapper/ExtensionStreamBase.php index f717c14..13cdf21 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ExtensionStreamBase.php +++ b/core/lib/Drupal/Core/StreamWrapper/ExtensionStreamBase.php @@ -89,16 +89,12 @@ public function dirname($uri = NULL) { if (!isset($uri)) { $uri = $this->uri; } - $target = $this->getTarget($uri); - $dirname = dirname($target); - - if ($dirname === '.' || $dirname === '\\') { - $dirname = ''; - } list($scheme) = explode('://', $uri, 2); + $dirname = dirname($this->getTarget($uri)); + $dirname = $dirname !== '.' ? rtrim("/$dirname", '/') : ''; - return rtrim($scheme . '://' . $this->getOwnerName() . '/' . $dirname, '/'); + return "$scheme://{$this->getOwnerName()}{$dirname}"; } /** diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php index ad4636c..f37aa25 100644 --- a/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php @@ -47,15 +47,7 @@ public function stream_open($uri, $mode, $options, &$opened_path) { } return FALSE; } - - $this->uri = $uri; - $path = $this->getLocalPath(); - $this->handle = ($options & STREAM_REPORT_ERRORS) ? fopen($path, $mode) : @fopen($path, $mode); - if ($this->handle !== FALSE && ($options & STREAM_USE_PATH)) { - $opened_path = $path; - } - - return (bool) $this->handle; + return parent::stream_open($uri, $mode, $options, $opened_path); } /** diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php index f49ec6b..87c2ce2 100644 --- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php @@ -117,12 +117,6 @@ protected function getLocalPath($uri = NULL) { } $directory = realpath($this->getDirectoryPath()); - // Windows accepts either backslash ('\') or slash (UNIX-style '/') as - // directory separator. We'll switch to slash, if the previous realpath() - // ran on Windows platform. - //$realpath = str_replace(DIRECTORY_SEPARATOR, '/', $realpath); - //$directory = str_replace(DIRECTORY_SEPARATOR, '/', $directory); - if (!$realpath || !$directory || strpos($realpath, $directory) !== 0) { return FALSE; } @@ -151,7 +145,7 @@ public function stream_open($uri, $mode, $options, &$opened_path) { $path = $this->getLocalPath(); $this->handle = ($options & STREAM_REPORT_ERRORS) ? fopen($path, $mode) : @fopen($path, $mode); - if ((bool) $this->handle && $options & STREAM_USE_PATH) { + if ((bool) $this->handle && ($options & STREAM_USE_PATH)) { $opened_path = $path; } diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStreamTrait.php b/core/lib/Drupal/Core/StreamWrapper/LocalStreamTrait.php index 19d3860..634a8db 100644 --- a/core/lib/Drupal/Core/StreamWrapper/LocalStreamTrait.php +++ b/core/lib/Drupal/Core/StreamWrapper/LocalStreamTrait.php @@ -30,8 +30,7 @@ public function dirname($uri = NULL) { } list($scheme) = explode('://', $uri, 2); - $target = $this->getTarget($uri); - $dirname = dirname($target); + $dirname = dirname($this->getTarget($uri)); return $dirname !== '.' ? "$scheme://$dirname" : "$scheme://"; } diff --git a/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php b/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php index 2569ee6..e016a42 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ProfileStream.php @@ -35,11 +35,4 @@ public function getDescription() { return $this->t('Local files stored under installed profile directory.'); } - /** - * {@inheritdoc} - */ - protected function getDirectoryPath() { - return drupal_get_path('profile', $this->getOwnerName()); - } - } diff --git a/core/modules/system/tests/src/Kernel/File/ExtensionStreamTest.php b/core/modules/system/tests/src/Kernel/File/ExtensionStreamTest.php index b369f1d..d694256 100644 --- a/core/modules/system/tests/src/Kernel/File/ExtensionStreamTest.php +++ b/core/modules/system/tests/src/Kernel/File/ExtensionStreamTest.php @@ -31,11 +31,20 @@ class ExtensionStreamTest extends KernelTestBase { protected $streamWrappers = []; /** + * The base url for the current request. + * + * @var string + */ + protected $baseUrl; + + /** * {@inheritdoc} */ public function setUp() { parent::setUp(); + $this->baseUrl = $this->container->get('request_stack')->getCurrentRequest()->getUriForPath(base_path()); + drupal_static_reset('file_get_stream_wrappers'); /** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */ $stream_wrapper_manager = $this->container->get('stream_wrapper_manager'); @@ -46,15 +55,15 @@ public function setUp() { /** @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() + + // Set 'minimal' as installed profile for the purposes of this test. $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() + ['install_profile' => 'minimal']); + $this->config('core.extension')->set('module.minimal', 0)->save(); + $this->container->get('module_handler')->addProfile('minimal', 'core/profiles/minimal'); /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */ $theme_installer = $this->container->get('theme_installer'); @@ -64,9 +73,33 @@ public function setUp() { /** * Test Invalid stream uri. + * + * @param string $uri + * The URI to test + * + * @dataProvider providerInvalidUri + */ + public function testInvalidStreamUriException($uri) { + $message = "\\InvalidArgumentException threw on invalid uri $uri."; + try { + $this->streamWrappers['module']->dirname($uri); + $this->fail($message); + } + catch (\InvalidArgumentException $e) { + if ($e->getMessage() == "Malformed uri parameter passed: $uri") { + $this->assertTrue(TRUE, $message); + } + else { + throw new \InvalidArgumentException($e); + } + } + } + + /** + * Provides test cases for testInvalidStreamUriException() */ - public function testInvalidStreamUriException() { - $bad_uris = [ + public function providerInvalidUri() { + return [ 'invalid/uri', 'invalid_uri', 'module/invalid/uri', @@ -78,139 +111,155 @@ public function testInvalidStreamUriException() { 'module//invalid_uri', 'module//invalid/uri', ]; - - foreach ($bad_uris as $bad_uri) { - try { - $this->streamWrappers['module']->dirname($bad_uri); - $this->fail(new FormattableMarkup('Invalid uri %uri not detected.', ['%uri' => $bad_uri])); - - } - catch (\InvalidArgumentException $e) { - if ($e->getMessage() == 'Malformed uri parameter passed: ' . $bad_uri) { - $this->assertTrue(TRUE, new FormattableMarkup('Throw exception on invalid uri %uri supplied.', ['%uri' => $bad_uri])); - } - else { - throw new \InvalidArgumentException($e); - } - } - } } /** * Test the extension stream wrapper methods. + * + * @param string $uri + * The uri to be tested, + * @param string|\InvalidArgumentException $dirname + * The expectation for dirname() method. + * @param string|\InvalidArgumentException $realpath + * The expectation for realpath() method. + * @param string|\InvalidArgumentException $getExternalUrl + * The expectation for getExternalUrl() method. + * + * @dataProvider providerStreamCases */ - public function testStreamWrapperMethods() { - foreach ($this->streamTestCasesProvider() as $uri => $expectation) { - foreach ($expectation as $method => $expected) { - list($scheme, ) = explode('://', $uri); - $this->streamWrappers[$scheme]->setUri($uri); - if ($expected instanceof \InvalidArgumentException) { - /** @var \InvalidArgumentException $expected */ - $message = sprintf('Exception thrown: \InvalidArgumentException("%s").', $expected->getMessage()); - try { - $this->streamWrappers[$scheme]->$method(); - $this->fail($message); - } - catch (\InvalidArgumentException $e) { - $this->assertSame($expected->getMessage(), $e->getMessage(), $message); - } + public function testStreamWrapperMethods($uri, $dirname, $realpath, $getExternalUrl) { + // Prefix realpath() expected value with Drupal root directory. + $realpath = is_string($realpath) ? DRUPAL_ROOT . $realpath : $realpath; + // Prefix getExternalUrl() expected value with base url. + $getExternalUrl = is_string($getExternalUrl) ? "{$this->baseUrl}$getExternalUrl" : $getExternalUrl; + $case = compact($dirname, $realpath, $getExternalUrl); + + foreach ($case as $method => $expected) { + list($scheme, ) = explode('://', $uri); + $this->streamWrappers[$scheme]->setUri($uri); + if ($expected instanceof \InvalidArgumentException) { + /** @var \InvalidArgumentException $expected */ + $message = sprintf('Exception thrown: \InvalidArgumentException("%s").', $expected->getMessage()); + try { + $this->streamWrappers[$scheme]->$method(); + $this->fail($message); } - elseif (is_string($expected)) { - $this->assertSame($expected, $this->streamWrappers[$scheme]->$method()); + catch (\InvalidArgumentException $e) { + $this->assertSame($expected->getMessage(), $e->getMessage(), $message); } } + elseif (is_string($expected)) { + $this->assertSame($expected, $this->streamWrappers[$scheme]->$method()); + } } } /** - * Provides test cases for testThemeStream(). + * Provides test cases for testStreamWrapperMethods(). * * @return array - * Associative array with test cases as values, keyed by uri. + * A list of test cases. Each case consists of the next items: + * - The uri to be tested. + * - The result or the exception when running dirname() method. + * - The result or the exception when running reaplpath() method. The value + * is prefixed later, in test, with the Drupal root directory. + * - The result or the exception when running getExternalUrl() method. The + * value is prefixed later, in test, with the base url. */ - protected function streamTestCasesProvider() { - $base_url = $this->container->get('request_stack')->getCurrentRequest()->getUriForPath(base_path()); + public function providerStreamCases() { return [ - // Cases for module:// stream wrapper. - 'module://system' => [ - 'dirname' => 'module://system', - 'realpath' => DRUPAL_ROOT . '/core/modules/system', - 'getExternalUrl' => $base_url . 'core/modules/system', + [ + 'module://system', + 'module://system', + '/core/modules/system', + 'core/modules/system', ], - 'module://system/css/system.admin.css' => [ - 'dirname' => 'module://system/css', - 'realpath' => DRUPAL_ROOT . '/core/modules/system/css/system.admin.css', - 'getExternalUrl' => $base_url . 'core/modules/system/css/system.admin.css', + [ + 'module://system/css/system.admin.css', + 'module://system/css', + '/core/modules/system/css/system.admin.css', + 'core/modules/system/css/system.admin.css', ], - 'module://file_test/file_test.dummy.inc' => [ - 'dirname' => 'module://file_test', - 'realpath' => DRUPAL_ROOT . '/core/modules/file/tests/file_test/file_test.dummy.inc', - 'getExternalUrl' => $base_url . 'core/modules/file/tests/file_test/file_test.dummy.inc', + [ + 'module://file_test/file_test.dummy.inc', + 'module://file_test', + '/core/modules/file/tests/file_test/file_test.dummy.inc', + 'core/modules/file/tests/file_test/file_test.dummy.inc', ], - 'module://file_test/src/file_test.dummy.inc' => [ - 'dirname' => 'module://file_test/src', - 'realpath' => DRUPAL_ROOT . '/core/modules/file/tests/file_test/src/file_test.dummy.inc', - 'getExternalUrl' => $base_url . 'core/modules/file/tests/file_test/src/file_test.dummy.inc', + [ + 'module://file_test/src/file_test.dummy.inc', + 'module://file_test/src', + '/core/modules/file/tests/file_test/src/file_test.dummy.inc', + 'core/modules/file/tests/file_test/src/file_test.dummy.inc', ], - 'module://ckeditor/ckeditor.info.yml' => [ - 'dirname' => new \InvalidArgumentException('Module ckeditor does not exist or is not installed'), - 'realpath' => new \InvalidArgumentException('Module ckeditor does not exist or is not installed'), - 'getExternalUrl' => new \InvalidArgumentException('Module ckeditor does not exist or is not installed'), + [ + 'module://ckeditor/ckeditor.info.yml', + new \InvalidArgumentException('Module ckeditor does not exist or is not installed'), + new \InvalidArgumentException('Module ckeditor does not exist or is not installed'), + new \InvalidArgumentException('Module ckeditor does not exist or is not installed'), ], - 'module://foo_bar/foo.bar.js' => [ - 'dirname' => new \InvalidArgumentException('Module foo_bar does not exist or is not installed'), - 'realpath' => new \InvalidArgumentException('Module foo_bar does not exist or is not installed'), - 'getExternalUrl' => new \InvalidArgumentException('Module foo_bar does not exist or is not installed'), + [ + 'module://foo_bar/foo.bar.js', + new \InvalidArgumentException('Module foo_bar does not exist or is not installed'), + new \InvalidArgumentException('Module foo_bar does not exist or is not installed'), + new \InvalidArgumentException('Module foo_bar does not exist or is not installed'), ], - // Cases for theme:// stream wrapper. - 'theme://seven' => [ - 'dirname' => 'theme://seven', - 'realpath' => DRUPAL_ROOT . '/core/themes/seven', - 'getExternalUrl' => $base_url . 'core/themes/seven', + [ + 'theme://seven', + 'theme://seven', + '/core/themes/seven', + 'core/themes/seven', ], - 'theme://seven/style.css' => [ - 'dirname' => 'theme://seven', - 'realpath' => DRUPAL_ROOT . '/core/themes/seven/style.css', - 'getExternalUrl' => $base_url . 'core/themes/seven/style.css', + [ + 'theme://seven/style.css', + 'theme://seven', + '/core/themes/seven/style.css', + 'core/themes/seven/style.css', ], - 'theme://bartik/color/preview.js' => [ - 'dirname' => 'theme://bartik/color', - 'realpath' => DRUPAL_ROOT . '/core/themes/bartik/color/preview.js', - 'getExternalUrl' => $base_url . 'core/themes/bartik/color/preview.js', + [ + 'theme://bartik/color/preview.js', + 'theme://bartik/color', + '/core/themes/bartik/color/preview.js', + 'core/themes/bartik/color/preview.js', ], - 'theme://fifteen/screenshot.png' => [ - 'dirname' => new \InvalidArgumentException('Theme fifteen does not exist or is not installed'), - 'realpath' => new \InvalidArgumentException('Theme fifteen does not exist or is not installed'), - 'getExternalUrl' => new \InvalidArgumentException('Theme fifteen does not exist or is not installed'), + [ + 'theme://fifteen/screenshot.png', + new \InvalidArgumentException('Theme fifteen does not exist or is not installed'), + new \InvalidArgumentException('Theme fifteen does not exist or is not installed'), + new \InvalidArgumentException('Theme fifteen does not exist or is not installed'), ], - 'theme://stark/stark.info.yml' => [ - 'dirname' => new \InvalidArgumentException('Theme stark does not exist or is not installed'), - 'realpath' => new \InvalidArgumentException('Theme stark does not exist or is not installed'), - 'getExternalUrl' => new \InvalidArgumentException('Theme stark does not exist or is not installed'), + [ + 'theme://stark/stark.info.yml', + new \InvalidArgumentException('Theme stark does not exist or is not installed'), + new \InvalidArgumentException('Theme stark does not exist or is not installed'), + new \InvalidArgumentException('Theme stark does not exist or is not installed'), ], - // Cases for profile:// stream wrapper. - 'profile://' => [ - 'dirname' => 'profile://', - 'realpath' => DRUPAL_ROOT . '/core/profiles/minimal', - 'getExternalUrl' => $base_url . 'core/profiles/minimal', + [ + 'profile://', + 'profile://', + '/core/profiles/minimal', + 'core/profiles/minimal', ], - 'profile://config/install/block.block.stark_login.yml' => [ - 'dirname' => 'profile://config/install', - 'realpath' => DRUPAL_ROOT . '/core/profiles/minimal/config/install/block.block.stark_login.yml', - 'getExternalUrl' => $base_url . 'core/profiles/minimal/config/install/block.block.stark_login.yml', + [ + 'profile://config/install/block.block.stark_login.yml', + 'profile://config/install', + '/core/profiles/minimal/config/install/block.block.stark_login.yml', + 'core/profiles/minimal/config/install/block.block.stark_login.yml', ], - 'profile://config/install/node.type.article.yml' => [ - 'dirname' => 'profile://config/install', - 'realpath' => DRUPAL_ROOT . '/core/profiles/minimal/config/install/node.type.article.yml', - 'getExternalUrl' => $base_url . 'core/profiles/minimal/config/install/node.type.article.yml', + [ + 'profile://config/install/node.type.article.yml', + 'profile://config/install', + '/core/profiles/minimal/config/install/node.type.article.yml', + 'core/profiles/minimal/config/install/node.type.article.yml', ], - 'profile://minimal.info.yml' => [ - 'dirname' => 'profile://', - 'realpath' => DRUPAL_ROOT . '/core/profiles/minimal/minimal.info.yml', - 'getExternalUrl' => $base_url . 'core/profiles/minimal/minimal.info.yml', + [ + 'profile://minimal.info.yml', + 'profile://', + '/core/profiles/minimal/minimal.info.yml', + 'core/profiles/minimal/minimal.info.yml', ], ]; } diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index 521fd34..1dcdefb 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -573,8 +573,4 @@ public static function getAllowedConfigurableLanguageCodes() { return array_keys(\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_CONFIGURABLE)); } - //public function getCacheTags() { - // return ['session'] + parent::getCacheContexts(); // TODO: Change the autogenerated stub - //} - } diff --git a/core/modules/user/src/UserStorage.php b/core/modules/user/src/UserStorage.php index 0dd35aa..d6a42f4 100644 --- a/core/modules/user/src/UserStorage.php +++ b/core/modules/user/src/UserStorage.php @@ -7,7 +7,6 @@ namespace Drupal\user; -use Drupal\Core\Cache\Cache; use Drupal\Core\Database\Connection; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Entity\ContentEntityInterface; @@ -17,7 +16,6 @@ use Drupal\Core\Password\PasswordInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\user\Entity\User; use Symfony\Component\DependencyInjection\ContainerInterface; /**