X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FTests%2FCore%2FCache%2FContext%2FSessionCacheContextTest.php;h=a8cf6fb3dc4d7d63374cde935d5b22df62775dff;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=b621b2dacacfb8d44b662583d77d900fc2983d51;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php b/web/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php index b621b2dac..a8cf6fb3d 100644 --- a/web/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php +++ b/web/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\Core\Cache\Context; use Drupal\Core\Cache\Context\SessionCacheContext; +use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -10,7 +11,14 @@ use Symfony\Component\HttpFoundation\RequestStack; * @coversDefaultClass \Drupal\Core\Cache\Context\SessionCacheContext * @group Cache */ -class SessionCacheContextTest extends \PHPUnit_Framework_TestCase { +class SessionCacheContextTest extends UnitTestCase { + + /** + * The request. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; /** * The request stack. @@ -26,36 +34,30 @@ class SessionCacheContextTest extends \PHPUnit_Framework_TestCase { */ protected $session; - /** - * The session cache context. - * - * @var \Drupal\Core\Cache\Context\SessionCacheContext - */ - protected $cacheContext; - public function setUp() { - $request = new Request(); + $this->request = new Request(); $this->requestStack = new RequestStack(); - $this->requestStack->push($request); - - $this->session = $this->getMock('\Symfony\Component\HttpFoundation\Session\SessionInterface'); - $request->setSession($this->session); + $this->requestStack->push($this->request); - $this->cacheContext = new SessionCacheContext($this->requestStack); + $this->session = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Session\SessionInterface') + ->getMock(); } /** * @covers ::getContext */ public function testSameContextForSameSession() { + $this->request->setSession($this->session); + $cache_context = new SessionCacheContext($this->requestStack); + $session_id = 'aSebeZ52bbM6SvADurQP89SFnEpxY6j8'; $this->session->expects($this->exactly(2)) ->method('getId') ->will($this->returnValue($session_id)); - $context1 = $this->cacheContext->getContext(); - $context2 = $this->cacheContext->getContext(); + $context1 = $cache_context->getContext(); + $context2 = $cache_context->getContext(); $this->assertSame($context1, $context2); $this->assertSame(FALSE, strpos($context1, $session_id), 'Session ID not contained in cache context'); } @@ -64,6 +66,9 @@ class SessionCacheContextTest extends \PHPUnit_Framework_TestCase { * @covers ::getContext */ public function testDifferentContextForDifferentSession() { + $this->request->setSession($this->session); + $cache_context = new SessionCacheContext($this->requestStack); + $session1_id = 'pjH_8aSoofyCDQiuVYXJcbfyr-CPtkUY'; $this->session->expects($this->at(0)) ->method('getId') @@ -74,12 +79,21 @@ class SessionCacheContextTest extends \PHPUnit_Framework_TestCase { ->method('getId') ->will($this->returnValue($session2_id)); - $context1 = $this->cacheContext->getContext(); - $context2 = $this->cacheContext->getContext(); + $context1 = $cache_context->getContext(); + $context2 = $cache_context->getContext(); $this->assertNotEquals($context1, $context2); $this->assertSame(FALSE, strpos($context1, $session1_id), 'Session ID not contained in cache context'); $this->assertSame(FALSE, strpos($context2, $session2_id), 'Session ID not contained in cache context'); } + /** + * @covers ::getContext + */ + public function testContextWithoutSessionInRequest() { + $cache_context = new SessionCacheContext($this->requestStack); + + $this->assertSame('none', $cache_context->getContext()); + } + }