summaryrefslogtreecommitdiffstatshomepage
path: root/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
diff options
context:
space:
mode:
authorLee Rowlands <lee.rowlands@previousnext.com.au>2023-12-28 08:03:14 +1000
committerLee Rowlands <lee.rowlands@previousnext.com.au>2023-12-28 08:03:14 +1000
commitfbee2baaab8fb8f8be29462e4798b51e1fe758d4 (patch)
tree976ab6bc1996f933d735884dfc83298074745fb4 /core/tests/Drupal/KernelTests/KernelTestBaseTest.php
parentc980ece64ec31e8ae96a3c73d450472dff69b531 (diff)
downloaddrupal-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/tests/Drupal/KernelTests/KernelTestBaseTest.php')
-rw-r--r--core/tests/Drupal/KernelTests/KernelTestBaseTest.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
index 689cf8b953e0..be83c0a2672f 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
@@ -11,6 +11,7 @@ use Drupal\user\Entity\Role;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
use PHPUnit\Framework\SkippedTestError;
+use Symfony\Component\HttpFoundation\Request;
/**
* @coversDefaultClass \Drupal\KernelTests\KernelTestBase
@@ -236,6 +237,34 @@ class KernelTestBaseTest extends KernelTestBase {
}
/**
+ * Tests that a usable session is on the request.
+ *
+ * @covers ::bootKernel
+ */
+ public function testSessionOnRequest(): void {
+ /** @var \Symfony\Component\HttpFoundation\Session\Session $session */
+ $session = $this->container->get('request_stack')->getSession();
+
+ $session->set('some-val', 'do-not-cleanup');
+ $this->assertEquals('do-not-cleanup', $session->get('some-val'));
+
+ $session->set('some-other-val', 'do-cleanup');
+ $this->assertEquals('do-cleanup', $session->remove('some-other-val'));
+ }
+
+ /**
+ * Tests deprecation of modified request stack lacking a session.
+ *
+ * @covers ::tearDown
+ *
+ * @group legacy
+ */
+ public function testDeprecatedSessionMissing(): void {
+ $this->expectDeprecation('Pushing requests without a session onto the request_stack is deprecated in drupal:10.3.0 and an error will be thrown from drupal:11.0.0. See https://www.drupal.org/node/3337193');
+ $this->container->get('request_stack')->push(Request::create('/'));
+ }
+
+ /**
* Tests the assumption that local time is in 'Australia/Sydney'.
*/
public function testLocalTimeZone() {