-
Notifications
You must be signed in to change notification settings - Fork 325
/
PublicHandlerTest.php
131 lines (111 loc) · 3.97 KB
/
PublicHandlerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Sulu\Component\HttpCache\Tests\Unit\Handler;
use Sulu\Component\Content\Compat\Structure\PageBridge;
use Sulu\Component\Content\Compat\StructureInterface;
use Sulu\Component\HttpCache\CacheLifetimeResolverInterface;
use Sulu\Component\HttpCache\Handler\PublicHandler;
use Sulu\Component\HttpCache\HandlerInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Response;
class PublicHandlerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var HandlerInterface
*/
private $handler;
/**
* @var StructureInterface
*/
private $structure;
/**
* @var int
*/
private $maxAge = 10;
/**
* @var int
*/
private $sharedMaxAge = 10;
/**
* @var Response
*/
private $response;
/**
* @var CacheLifetimeResolverInterface
*/
private $cacheLifetimeResolver;
/**
* @var mixed
*/
private $parameterBag;
public function setUp()
{
$this->structure = $this->prophesize(PageBridge::class);
$this->parameterBag = $this->prophesize(ParameterBag::class);
$this->response = $this->prophesize(Response::class);
$this->cacheLifetimeResolver = $this->prophesize(CacheLifetimeResolverInterface::class);
$this->response->headers = $this->parameterBag;
$this->handler = new PublicHandler(
$this->cacheLifetimeResolver->reveal(),
$this->maxAge,
$this->sharedMaxAge,
true
);
}
public function testUpdateResponse()
{
$this->response->setPublic()->shouldBeCalled();
$this->response->setMaxAge($this->maxAge)->shouldBeCalled();
$this->response->setSharedMaxAge($this->sharedMaxAge)->shouldBeCalled();
$this->structure->getCacheLifeTime()
->willReturn(['type' => CacheLifetimeResolverInterface::TYPE_SECONDS, 'value' => 10]);
$this->cacheLifetimeResolver->resolve(CacheLifetimeResolverInterface::TYPE_SECONDS, 10)->willReturn(10);
$this->response->getAge()->willReturn(50);
$this->handler->updateResponse(
$this->response->reveal(),
$this->structure->reveal()
);
}
public function testSharedMaxAgeZeroResponse()
{
$this->response->setPublic()->shouldBeCalled();
$this->response->setMaxAge($this->maxAge)->shouldBeCalled();
// setSharedMaxAge should not be called else symfony cache will not work on s-max-age 0
$this->response->setSharedMaxAge(0)->shouldNotBeCalled();
$this->structure->getCacheLifeTime()
->willReturn(['type' => CacheLifetimeResolverInterface::TYPE_SECONDS, 'value' => 10]);
$this->cacheLifetimeResolver->resolve(CacheLifetimeResolverInterface::TYPE_SECONDS, 10)->willReturn(10);
$this->response->getAge()->willReturn(50);
$handler = new PublicHandler(
$this->cacheLifetimeResolver->reveal(),
$this->maxAge,
0,
true
);
$handler->updateResponse(
$this->response->reveal(),
$this->structure->reveal()
);
}
public function testDisableCache()
{
// disable cache
$this->structure->getCacheLifeTime()
->willReturn(['type' => CacheLifetimeResolverInterface::TYPE_SECONDS, 'value' => 0]);
$this->cacheLifetimeResolver->resolve(CacheLifetimeResolverInterface::TYPE_SECONDS, 0)->willReturn(0);
$this->response->setPublic()->shouldNotBeCalled();
$this->response->setMaxAge($this->maxAge)->shouldNotBeCalled();
$this->response->setSharedMaxAge($this->sharedMaxAge)->shouldNotBeCalled();
$this->handler->updateResponse(
$this->response->reveal(),
$this->structure->reveal()
);
}
}