More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / PageCache / NoSessionOpenTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\PageCache;
4
5 use Drupal\Core\PageCache\RequestPolicy\NoSessionOpen;
6 use Drupal\Core\PageCache\RequestPolicyInterface;
7 use Drupal\Tests\UnitTestCase;
8 use Symfony\Component\HttpFoundation\Request;
9
10 /**
11  * @coversDefaultClass \Drupal\Core\PageCache\RequestPolicy\NoSessionOpen
12  * @group PageCache
13  */
14 class NoSessionOpenTest extends UnitTestCase {
15
16   /**
17    * The session configuration.
18    *
19    * @var \Drupal\Core\Session\SessionConfigurationInterface|\PHPUnit_Framework_MockObject_MockObject
20    */
21   protected $sessionConfiguration;
22
23   /**
24    * The request policy under test.
25    *
26    * @var \Drupal\Core\PageCache\RequestPolicy\NoSessionOpen
27    */
28   protected $policy;
29
30   protected function setUp() {
31     $this->sessionConfiguration = $this->getMock('Drupal\Core\Session\SessionConfigurationInterface');
32     $this->policy = new NoSessionOpen($this->sessionConfiguration);
33   }
34
35   /**
36    * Asserts that caching is allowed unless there is a session cookie present.
37    *
38    * @covers ::check
39    */
40   public function testNoAllowUnlessSessionCookiePresent() {
41     $request_without_session = new Request();
42     $request_with_session = Request::create('/', 'GET', [], ['some-session-name' => 'some-session-id']);
43
44     $this->sessionConfiguration->expects($this->at(0))
45       ->method('hasSession')
46       ->with($request_without_session)
47       ->will($this->returnValue(FALSE));
48
49     $this->sessionConfiguration->expects($this->at(1))
50       ->method('hasSession')
51       ->with($request_with_session)
52       ->will($this->returnValue(TRUE));
53
54     $result = $this->policy->check($request_without_session);
55     $this->assertSame(RequestPolicyInterface::ALLOW, $result);
56
57     $result = $this->policy->check($request_with_session);
58     $this->assertSame(NULL, $result);
59   }
60
61 }