diff options
author | Lee Rowlands <lee.rowlands@previousnext.com.au> | 2023-12-28 08:03:14 +1000 |
---|---|---|
committer | Lee Rowlands <lee.rowlands@previousnext.com.au> | 2023-12-28 08:03:14 +1000 |
commit | fbee2baaab8fb8f8be29462e4798b51e1fe758d4 (patch) | |
tree | 976ab6bc1996f933d735884dfc83298074745fb4 /core/modules | |
parent | c980ece64ec31e8ae96a3c73d450472dff69b531 (diff) | |
download | drupal-fbee2baaab8fb8f8be29462e4798b51e1fe758d4.tar.gz drupal-fbee2baaab8fb8f8be29462e4798b51e1fe758d4.zip |
Issue #2484991 by znerol, voleger, andypost, dww, anmolgoyal74, markdorison, ankithashetty, larowlan, daffie, alexpott: Add the session to the request in KernelTestBase, BrowserTestBase, and drush
Diffstat (limited to 'core/modules')
15 files changed, 62 insertions, 10 deletions
diff --git a/core/modules/book/tests/src/Kernel/BookMultilingualTest.php b/core/modules/book/tests/src/Kernel/BookMultilingualTest.php index fbdfc3d8499a..7c2ead6bc72e 100644 --- a/core/modules/book/tests/src/Kernel/BookMultilingualTest.php +++ b/core/modules/book/tests/src/Kernel/BookMultilingualTest.php @@ -14,6 +14,8 @@ use Drupal\node\Entity\NodeType; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Routing\Route; /** @@ -271,7 +273,9 @@ class BookMultilingualTest extends KernelTestBase { * is used instead of the content language. */ protected function setCurrentLanguage(string $langcode): void { - \Drupal::requestStack()->push(Request::create("http://$langcode.book.test.domain/")); + $request = Request::create("http://$langcode.book.test.domain/"); + $request->setSession(new Session(new MockArraySessionStorage())); + \Drupal::requestStack()->push($request); $language_manager = $this->container->get('language_manager'); $language_manager->reset(); $current_user = \Drupal::currentUser(); diff --git a/core/modules/comment/tests/src/Kernel/CommentHostnameTest.php b/core/modules/comment/tests/src/Kernel/CommentHostnameTest.php index a056c086de7d..7099c6d93536 100644 --- a/core/modules/comment/tests/src/Kernel/CommentHostnameTest.php +++ b/core/modules/comment/tests/src/Kernel/CommentHostnameTest.php @@ -6,6 +6,8 @@ use Drupal\comment\Entity\Comment; use Drupal\comment\Entity\CommentType; use Drupal\KernelTests\KernelTestBase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; /** * Tests the hostname base field. @@ -29,6 +31,7 @@ class CommentHostnameTest extends KernelTestBase { public function testGetDefaultHostname() { // Create a fake request to be used for testing. $request = Request::create('/', 'GET', [], [], [], ['REMOTE_ADDR' => '203.0.113.1']); + $request->setSession(new Session(new MockArraySessionStorage())); /** @var \Symfony\Component\HttpFoundation\RequestStack $stack */ $stack = $this->container->get('request_stack'); $stack->push($request); diff --git a/core/modules/file/tests/src/Kernel/RequirementsTest.php b/core/modules/file/tests/src/Kernel/RequirementsTest.php index 4d472644dc4b..224616e089b8 100644 --- a/core/modules/file/tests/src/Kernel/RequirementsTest.php +++ b/core/modules/file/tests/src/Kernel/RequirementsTest.php @@ -7,6 +7,8 @@ namespace Drupal\Tests\file\Kernel; use Drupal\KernelTests\KernelTestBase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; /** * Tests the file requirements. @@ -69,6 +71,7 @@ class RequirementsTest extends KernelTestBase { */ private function setServerSoftware(?string $software): void { $request = new Request(); + $request->setSession(new Session(new MockArraySessionStorage())); if (is_string($software)) { $request->server->set('SERVER_SOFTWARE', $software); } diff --git a/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php b/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php index d13b923e3b72..d74a1def3940 100644 --- a/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php +++ b/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php @@ -10,6 +10,8 @@ use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\Tests\BrowserTestBase; use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Routing\Route; /** @@ -185,6 +187,7 @@ class LanguageNegotiationContentEntityTest extends BrowserTestBase { $request = Request::create($path); $request->attributes->set(RouteObjectInterface::ROUTE_NAME, $route_name); $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route($path)); + $request->setSession(new Session(new MockArraySessionStorage())); $this->container->get('request_stack')->push($request); } diff --git a/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php b/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php index 7a635e114076..46f518b2194a 100644 --- a/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php @@ -19,6 +19,8 @@ use Drupal\Core\Language\LanguageInterface; use Symfony\Component\HttpFoundation\Request; use Drupal\language\LanguageNegotiatorInterface; use Drupal\block\Entity\Block; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; /** * Tests the language UI for language switching. @@ -564,6 +566,7 @@ class LanguageUILanguageNegotiationTest extends BrowserTestBase { // Test HTTPS via current URL scheme. $request = Request::create('', 'GET', [], [], [], ['HTTPS' => 'on']); + $request->setSession(new Session(new MockArraySessionStorage())); $this->container->get('request_stack')->push($request); $italian_url = Url::fromRoute('system.admin', [], ['language' => $languages['it']])->toString(); $correct_link = 'https://' . $link; diff --git a/core/modules/language/tests/src/Kernel/EntityUrlLanguageTest.php b/core/modules/language/tests/src/Kernel/EntityUrlLanguageTest.php index 58ccffc612e7..44505aac764d 100644 --- a/core/modules/language/tests/src/Kernel/EntityUrlLanguageTest.php +++ b/core/modules/language/tests/src/Kernel/EntityUrlLanguageTest.php @@ -9,6 +9,8 @@ use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Routing\Route; /** @@ -132,6 +134,7 @@ class EntityUrlLanguageTest extends LanguageTestBase { $request = Request::create($path); $request->attributes->set(RouteObjectInterface::ROUTE_NAME, $route_name); $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route($path)); + $request->setSession(new Session(new MockArraySessionStorage())); $this->container->get('request_stack')->push($request); } diff --git a/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php b/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php index bc1288972936..fd37d6720ea4 100644 --- a/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php +++ b/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php @@ -12,6 +12,8 @@ use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\user\Entity\User; use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Routing\Route; /** @@ -62,6 +64,7 @@ class MenuLinkContentCacheabilityBubblingTest extends KernelTestBase { $request = Request::create('/'); $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<front>'); $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/')); + $request->setSession(new Session(new MockArraySessionStorage())); $request_stack->push($request); $request_context->fromRequest($request); diff --git a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php index 7c72ea90ed2d..3e10fe98bfca 100644 --- a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php +++ b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php @@ -16,6 +16,8 @@ use Drupal\views\Entity\View; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Views; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; /** * Tests the serializer style plugin. @@ -594,6 +596,7 @@ class StyleSerializerTest extends ViewTestBase { // We set up a request so it looks like a request in the live preview. $request = new Request(); $request->query->add([MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']); + $request->setSession(new Session(new MockArraySessionStorage())); /** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */ $request_stack = \Drupal::service('request_stack'); $request_stack->push($request); diff --git a/core/modules/syslog/tests/src/Kernel/SyslogTest.php b/core/modules/syslog/tests/src/Kernel/SyslogTest.php index 14137c73efae..987f6bef6ec6 100644 --- a/core/modules/syslog/tests/src/Kernel/SyslogTest.php +++ b/core/modules/syslog/tests/src/Kernel/SyslogTest.php @@ -4,6 +4,8 @@ namespace Drupal\Tests\syslog\Kernel; use Drupal\KernelTests\KernelTestBase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; /** * Test syslog logger functionality. @@ -30,6 +32,7 @@ class SyslogTest extends KernelTestBase { $request = Request::create('/page-not-found', 'GET', [], [], [], ['REMOTE_ADDR' => '1.2.3.4']); $request->headers->set('Referer', 'other-site'); + $request->setSession(new Session(new MockArraySessionStorage())); \Drupal::requestStack()->push($request); $user = $this->getMockBuilder('Drupal\Core\Session\AccountInterface')->getMock(); diff --git a/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php b/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php index 41aa5c3a8309..67129d429c7c 100644 --- a/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php +++ b/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php @@ -6,6 +6,8 @@ use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Core\Database\Query\PagerSelectExtender; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; /** * Tests the pager query select extender. @@ -141,6 +143,7 @@ class SelectPagerDefaultTest extends DatabaseTestBase { $request->query->replace([ 'page' => '3, 2, 1, 0', ]); + $request->setSession(new Session(new MockArraySessionStorage())); \Drupal::getContainer()->get('request_stack')->push($request); $connection = Database::getConnection(); diff --git a/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php index a335d9648a56..a09d42b40219 100644 --- a/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php +++ b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php @@ -11,6 +11,8 @@ use Drupal\Tests\Core\Menu\MenuLinkMock; use Drupal\user\Entity\User; use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -233,6 +235,7 @@ class SystemMenuBlockTest extends KernelTestBase { $request = new Request(); $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'example3'); $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, $route); + $request->setSession(new Session(new MockArraySessionStorage())); $this->container->get('request_stack')->push($request); // \Drupal\Core\Menu\MenuActiveTrail uses the cache collector pattern, which // includes static caching. Since this second scenario simulates a second @@ -300,6 +303,7 @@ class SystemMenuBlockTest extends KernelTestBase { $request = new Request(); $request->attributes->set(RouteObjectInterface::ROUTE_NAME, $active_route); $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, $route); + $request->setSession(new Session(new MockArraySessionStorage())); $this->container->get('request_stack')->push($request); $block_build = $block->build(); diff --git a/core/modules/system/tests/src/Kernel/Theme/TwigIncludeTest.php b/core/modules/system/tests/src/Kernel/Theme/TwigIncludeTest.php index 78298c5044d4..2abfc8f1708c 100644 --- a/core/modules/system/tests/src/Kernel/Theme/TwigIncludeTest.php +++ b/core/modules/system/tests/src/Kernel/Theme/TwigIncludeTest.php @@ -68,8 +68,10 @@ class TwigIncludeTest extends KernelTestBase { $twig_config = $this->container->getParameter('twig.config'); $twig_config['allowed_file_extensions'][] = 'sql'; $this->twigConfig = $twig_config; - $this->container->get('kernel')->shutdown(); - $this->container->get('kernel')->boot(); + // @todo This used to call shutdown() and boot(). rebuildContainer() is + // needed until we stop pushing the request twice and only popping it once. + // @see https://www.drupal.org/i/2613044 + $this->container->get('kernel')->rebuildContainer(); /** @var \Drupal\Core\Template\Loader\FilesystemLoader $loader */ $loader = \Drupal::service('twig.loader.filesystem'); $source = $loader->getSourceContext('@__main__\/core/tests/fixtures/files/sql-2.sql'); @@ -80,8 +82,10 @@ class TwigIncludeTest extends KernelTestBase { $this->assertSame(['css', 'html', 'js', 'svg', 'twig', 'sql'], \Drupal::getContainer()->getParameter('twig.config')['allowed_file_extensions']); unset($twig_config['allowed_file_extensions']); $this->twigConfig = $twig_config; - $this->container->get('kernel')->shutdown(); - $this->container->get('kernel')->boot(); + // @todo This used to call shutdown() and boot(). rebuildContainer() is + // needed until we stop pushing the request twice and only popping it once. + // @see https://www.drupal.org/i/2613044 + $this->container->get('kernel')->rebuildContainer(); $this->assertArrayNotHasKey('allowed_file_extensions', \Drupal::getContainer()->getParameter('twig.config')); /** @var \Drupal\Core\Template\Loader\FilesystemLoader $loader */ $loader = \Drupal::service('twig.loader.filesystem'); @@ -108,8 +112,10 @@ class TwigIncludeTest extends KernelTestBase { // Allow files with no extension. $twig_config['allowed_file_extensions'] = ['twig', '']; $this->twigConfig = $twig_config; - $this->container->get('kernel')->shutdown(); - $this->container->get('kernel')->boot(); + // @todo This used to call shutdown() and boot(). rebuildContainer() is + // needed until we stop pushing the request twice and only popping it once. + // @see https://www.drupal.org/i/2613044 + $this->container->get('kernel')->rebuildContainer(); /** @var \Drupal\Core\Template\Loader\FilesystemLoader $loader */ $loader = \Drupal::service('twig.loader.filesystem'); $source = $loader->getSourceContext('@__main__\/' . $this->siteDirectory . '/test_file'); diff --git a/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php b/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php index 516e3bd40c38..802190359b4c 100644 --- a/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php +++ b/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php @@ -7,6 +7,8 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Xss; use Drupal\Core\Render\BubbleableMetadata; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; /** * Tests token replacement. @@ -137,6 +139,7 @@ class TokenReplaceKernelTest extends TokenReplaceKernelTestBase { 'SERVER_NAME' => 'http://localhost', ]; $request = Request::create('/subdir/', 'GET', [], [], [], $server); + $request->setSession(new Session(new MockArraySessionStorage())); $request->server->add($server); $request_stack->push($request); $bubbleable_metadata = new BubbleableMetadata(); diff --git a/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php b/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php index 897290b28778..d41a6dea939c 100644 --- a/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php +++ b/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php @@ -6,6 +6,8 @@ use Drupal\Core\Cache\Cache; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; trait AssertViewsCacheTagsTrait { @@ -43,6 +45,7 @@ trait AssertViewsCacheTagsTrait { $request_stack = \Drupal::service('request_stack'); $request = Request::createFromGlobals(); $request->server->set('REQUEST_TIME', REQUEST_TIME); + $request->setSession(new Session(new MockArraySessionStorage())); $view->setRequest($request); $request_stack->push($request); $renderer->renderRoot($build); @@ -123,6 +126,7 @@ trait AssertViewsCacheTagsTrait { $request_stack = \Drupal::service('request_stack'); $request = new Request(); $request->server->set('REQUEST_TIME', REQUEST_TIME); + $request->setSession(new Session(new MockArraySessionStorage())); $request_stack->push($request); $renderer->renderRoot($build); diff --git a/core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php b/core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php index e3bbdfa56813..87a1afea8002 100644 --- a/core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php @@ -15,6 +15,8 @@ use Prophecy\Argument; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; /** * Tests the core views_handler_area_display_link handler. @@ -148,8 +150,7 @@ class AreaDisplayLinkTest extends ViewsKernelTestBase { // Assert some special request parameters are filtered from the display // links. - $request_stack = new RequestStack(); - $request_stack->push(Request::create('page_1', 'GET', [ + $request = Request::create('page_1', 'GET', [ 'name' => 'John', 'sort_by' => 'created', 'sort_order' => 'ASC', @@ -166,7 +167,10 @@ class AreaDisplayLinkTest extends ViewsKernelTestBase { AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER => 1, FormBuilderInterface::AJAX_FORM_REQUEST => 1, MainContentViewSubscriber::WRAPPER_FORMAT => 1, - ])); + ]); + $request->setSession(new Session(new MockArraySessionStorage())); + $request_stack = new RequestStack(); + $request_stack->push($request); $this->container->set('request_stack', $request_stack); $view->destroy(); $view->setDisplay('page_1'); |