NoSessionOpenTest.php in Drupal 9
File
core/tests/Drupal/Tests/Core/PageCache/NoSessionOpenTest.php
View source
<?php
namespace Drupal\Tests\Core\PageCache;
use Drupal\Core\PageCache\RequestPolicy\NoSessionOpen;
use Drupal\Core\PageCache\RequestPolicyInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
class NoSessionOpenTest extends UnitTestCase {
protected $sessionConfiguration;
protected $policy;
protected function setUp() : void {
$this->sessionConfiguration = $this
->createMock('Drupal\\Core\\Session\\SessionConfigurationInterface');
$this->policy = new NoSessionOpen($this->sessionConfiguration);
}
public function testNoAllowUnlessSessionCookiePresent() {
$request_without_session = new Request();
$request_with_session = Request::create('/', 'GET', [], [
'some-session-name' => 'some-session-id',
]);
$this->sessionConfiguration
->expects($this
->exactly(2))
->method('hasSession')
->willReturnMap([
[
$request_without_session,
FALSE,
],
[
$request_with_session,
TRUE,
],
]);
$result = $this->policy
->check($request_without_session);
$this
->assertSame(RequestPolicyInterface::ALLOW, $result);
$result = $this->policy
->check($request_with_session);
$this
->assertSame(NULL, $result);
}
}