diff --git a/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php b/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php index adf3d9f..a125290 100644 --- a/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php +++ b/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php @@ -70,7 +70,7 @@ public function save($name, $data) { // Write the file out to a temporary location. Prepend with a '.' to keep it // hidden from listings and web servers. - $temporary_path = drupal_tempnam($this->directory, '.'); + $temporary_path = $this->directory . '/.' . substr(str_shuffle(md5(time())),0, 10);; if (!$temporary_path || !@file_put_contents($temporary_path, $data)) { return FALSE; } @@ -103,7 +103,7 @@ public function save($name, $data) { // iteration. if ($i > 0) { $this->unlink($temporary_path); - $temporary_path = drupal_tempnam($this->directory, '.'); + $temporary_path = $this->directory . '/.' . substr(str_shuffle(md5(time())),0, 10); rename($full_path, $temporary_path); // Make sure to not loop infinitely on a hopelessly slow filesystem. if ($i > 10) { diff --git a/core/lib/Drupal/Core/File/FileSystem.php b/core/lib/Drupal/Core/File/FileSystem.php index aedfdf6..d6f94ea 100644 --- a/core/lib/Drupal/Core/File/FileSystem.php +++ b/core/lib/Drupal/Core/File/FileSystem.php @@ -301,7 +301,7 @@ public function validScheme($scheme) { if (!$scheme) { return FALSE; } - return class_exists($this->streamWrapperManager->getClass($scheme)); + return class_exists($this->streamWrapperManager->getClass($scheme)) || in_array($scheme, stream_get_wrappers()); } } diff --git a/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php b/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php index dfbb0f9..2a239b3 100644 --- a/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php +++ b/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php @@ -27,7 +27,6 @@ class CommentStringIdEntitiesTest extends KernelTestBase { 'user', 'field', 'field_ui', - 'entity', 'entity_test', 'system', // EMAIL_MAX_LENGTH constant. 'text', diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index 6232b30..e0bf4f2 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -336,6 +336,9 @@ public function containerBuild(ContainerBuilder $container) { ->addArgument(new Reference('module_handler')) ->addMethodCall('setContainer', array(new Reference('service_container'))); + $container->register('stream_wrapper.vfs', '\Drupal\Tests\VfsStreamWrapperWrapper') + ->addTag('stream_wrapper', ['scheme' => 'vfs']); + $request = Request::create('/'); $container->get('request_stack')->push($request); } diff --git a/core/modules/system/src/Tests/File/FileTestBase.php b/core/modules/system/src/Tests/File/FileTestBase.php index 5dcdbed..306b6b0 100644 --- a/core/modules/system/src/Tests/File/FileTestBase.php +++ b/core/modules/system/src/Tests/File/FileTestBase.php @@ -39,13 +39,13 @@ protected function setUp() { parent::setUp(); $this->installConfig(array('system')); - $this->registerStreamWrapper('private', 'Drupal\Core\StreamWrapper\PrivateStream'); + $this->registerStreamWrapper('stream_wrapper.private', 'private', 'Drupal\Core\StreamWrapper\PrivateStream'); // hook_stream_wrappers() of enabled $modules gets invoked already. Only // register a custom test stream wrapper if both a scheme and a class have // been provided. if (isset($this->scheme) && isset($this->classname)) { - $this->registerStreamWrapper($this->scheme, $this->classname); + $this->registerStreamWrapper('stream_wrapper.' . $this->scheme, $this->scheme, $this->classname); } } diff --git a/core/modules/views/src/Plugin/views/field/EntityOperations.php b/core/modules/views/src/Plugin/views/field/EntityOperations.php index 3b9128c..d7c8e5f 100644 --- a/core/modules/views/src/Plugin/views/field/EntityOperations.php +++ b/core/modules/views/src/Plugin/views/field/EntityOperations.php @@ -102,7 +102,7 @@ public function render(ResultRow $values) { if (!isset($operation['query'])) { $operation['query'] = array(); } - $operation['query'] += drupal_get_destination(); + $operation['query'] += $this->drupalGetDestination(); } } $build = array( @@ -113,6 +113,10 @@ public function render(ResultRow $values) { return $build; } + protected function drupalGetDestination() { + return drupal_get_destination(); + } + /** * {@inheritdoc} */ diff --git a/core/modules/views/src/Tests/Handler/AreaTextTest.php b/core/modules/views/src/Tests/Handler/AreaTextTest.php index 538fc5b..a695744 100644 --- a/core/modules/views/src/Tests/Handler/AreaTextTest.php +++ b/core/modules/views/src/Tests/Handler/AreaTextTest.php @@ -9,6 +9,7 @@ use Drupal\views\Tests\ViewUnitTestBase; use Drupal\views\Views; +use Psr\Log\LogLevel; /** * Tests the core views_handler_area_text handler. @@ -56,7 +57,7 @@ public function testAreaText() { $view->display_handler->handlers['header']['area']->options['content']['format'] = $this->randomString(); $build = $view->display_handler->handlers['header']['area']->render(); - $this->setExpectedLogMessage(WATCHDOG_ALERT, 'Missing text format: %s'); + $this->setExpectedLogMessage(LogLevel::ALERT, 'Missing text format: %s'); $this->assertEqual('', drupal_render($build), 'Nonexistent format should return empty markup.'); $view->display_handler->handlers['header']['area']->options['content']['format'] = filter_default_format(); diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php index c0b5594..ae4020c 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php @@ -11,6 +11,7 @@ use Drupal\Core\Session\AnonymousUserSession; use Drupal\views\Views; use Drupal\views\Tests\ViewUnitTestBase; +use Psr\Log\LogLevel; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -60,17 +61,17 @@ protected function setUp() { public function testPageResponses() { \Drupal::currentUser()->setAccount(new AnonymousUserSession()); $subrequest = Request::create('/test_page_display_403', 'GET'); - $this->setExpectedLogMessage(WATCHDOG_WARNING, 'test_page_display_403'); + $this->setExpectedLogMessage(LogLevel::WARNING, 'test_page_display_403'); $response = $this->container->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST); $this->assertEqual($response->getStatusCode(), 403); $subrequest = Request::create('/test_page_display_404', 'GET'); - $this->setExpectedLogMessage(WATCHDOG_WARNING, 'test_page_display_404'); + $this->setExpectedLogMessage(LogLevel::WARNING, 'test_page_display_404'); $response = $this->container->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST); $this->assertEqual($response->getStatusCode(), 404); $subrequest = Request::create('/test_page_display_200', 'GET'); - $this->setExpectedLogMessage(WATCHDOG_WARNING, 'test_page_display_200'); + $this->setExpectedLogMessage(LogLevel::WARNING, 'test_page_display_200'); $response = $this->container->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST); $this->assertEqual($response->getStatusCode(), 200); diff --git a/core/modules/views/src/Tests/Plugin/views/field/EntityOperationsUnitTest.php b/core/modules/views/src/Tests/Plugin/views/field/EntityOperationsUnitTest.php index 8b32482..febc410 100644 --- a/core/modules/views/src/Tests/Plugin/views/field/EntityOperationsUnitTest.php +++ b/core/modules/views/src/Tests/Plugin/views/field/EntityOperationsUnitTest.php @@ -5,7 +5,7 @@ * Contains \Drupal\views\Tests\Plugin\views\field\EntityOperationsUnitTest. */ -namespace Drupal\views\Tests\Plugin\views\field { +namespace Drupal\views\Tests\Plugin\views\field; use Drupal\Tests\UnitTestCase; use Drupal\views\Plugin\views\field\EntityOperations; @@ -44,7 +44,7 @@ public function setUp() { $plugin_definition = array( 'title' => $this->randomMachineName(), ); - $this->plugin = new EntityOperations($configuration, $plugin_id, $plugin_definition, $this->entityManager); + $this->plugin = new TestEntityOperations($configuration, $plugin_id, $plugin_definition, $this->entityManager); $view = $this->getMockBuilder('\Drupal\views\ViewExecutable') ->disableOriginalConstructor() ->getMock(); @@ -108,7 +108,7 @@ public function testRenderWithDestination() { '#type' => 'operations', '#links' => $operations ); - $expected_build['#links']['foo']['query'] = drupal_get_destination(); + $expected_build['#links']['foo']['query'] = ['destination' => 'foobar']; $build = $this->plugin->render($result); $this->assertSame($expected_build, $build); } @@ -155,16 +155,13 @@ public function testRenderWithoutDestination() { } } -} - -namespace { +class TestEntityOperations extends EntityOperations { -if (!function_exists('drupal_get_destination')) { - function drupal_get_destination() { - return array( - 'destination' => 'foobar', - ); + /** + * {@inheritdoc} + */ + protected function drupalGetDestination() { + return ['destination' => 'foobar']; } -} } diff --git a/core/modules/views/src/Views.php b/core/modules/views/src/Views.php index 525177f..99577b6 100644 --- a/core/modules/views/src/Views.php +++ b/core/modules/views/src/Views.php @@ -15,13 +15,6 @@ class Views { /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected static $translationManager; - - /** * A static cache for handler types data. * * @var array @@ -527,11 +520,7 @@ public static function getPluginTypes($type = NULL) { * See the t() documentation for details. */ protected static function t($string, array $args = array(), array $options = array()) { - if (empty(static::$translationManager)) { - static::$translationManager = \Drupal::service('string_translation'); - } - - return static::$translationManager->translate($string, $args, $options); + return \Drupal::service('string_translation')->translate($string, $args, $options); } } diff --git a/core/tests/Drupal/Tests/KernelTestBase.php b/core/tests/Drupal/Tests/KernelTestBase.php index 0c495f1..e292308 100644 --- a/core/tests/Drupal/Tests/KernelTestBase.php +++ b/core/tests/Drupal/Tests/KernelTestBase.php @@ -342,10 +342,17 @@ private function bootKernel() { // @todo Move StreamWrapper management into DrupalKernel. // @see https://drupal.org/node/2028109 $this->streamWrappers = []; - $this->registerStreamWrapper('public', 'Drupal\Core\StreamWrapper\PublicStream'); + $this->registerStreamWrapper('stream_wrapper.public', 'public', 'Drupal\Core\StreamWrapper\PublicStream'); // The temporary stream wrapper is able to operate both with and without // configuration. - $this->registerStreamWrapper('temporary', 'Drupal\Core\StreamWrapper\TemporaryStream'); + $this->registerStreamWrapper('stream_wrapper.temporary', 'temporary', 'Drupal\Core\StreamWrapper\TemporaryStream'); +// $this->registerStreamWrapper('stream_wrapper.vfs', 'vfs', 'Drupal\Tests\VfsStreamWrapperWrapper'); + + $settings = Settings::getAll(); + $settings['php_storage']['default'] = [ + 'class' => '\Drupal\Component\PhpStorage\FileStorage', + ]; + new Settings($settings); } /** @@ -825,6 +832,8 @@ protected function disableModules(array $modules) { /** * Registers a stream wrapper for this test. * + * @param $service_id + * The service ID. * @param string $scheme * The scheme to register. * @param string $class @@ -833,7 +842,8 @@ protected function disableModules(array $modules) { * The Drupal Stream Wrapper API type. Defaults to * StreamWrapperInterface::NORMAL. */ - protected function registerStreamWrapper($scheme, $class, $type = StreamWrapperInterface::NORMAL) { + protected function registerStreamWrapper($service_id, $scheme, $class, $type = StreamWrapperInterface::NORMAL) { + $this->container->get('stream_wrapper_manager')->addStreamWrapper($service_id, $class, $scheme); $this->container->get('stream_wrapper_manager')->registerWrapper($scheme, $class, $type); } diff --git a/core/tests/Drupal/Tests/VfsStreamWrapperWrapper.php b/core/tests/Drupal/Tests/VfsStreamWrapperWrapper.php index 549cdd5..cf0dda8 100644 --- a/core/tests/Drupal/Tests/VfsStreamWrapperWrapper.php +++ b/core/tests/Drupal/Tests/VfsStreamWrapperWrapper.php @@ -145,7 +145,7 @@ public function dirname($uri = NULL) { } public function getDirectoryPath() { - return ''; + return 'root'; } }