|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\eZ\Publish\Core\MVC\Symfony\Cache\Http\ResponseConfigurator; |
|
4
|
|
|
|
|
5
|
|
|
use eZ\Publish\Core\MVC\Symfony\Cache\Http\ResponseConfigurator\ConfigurableResponseCacheConfigurator; |
|
6
|
|
|
use PhpSpec\ObjectBehavior; |
|
7
|
|
|
use Prophecy\Argument; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
|
11
|
|
|
|
|
12
|
|
|
class ConfigurableResponseCacheConfiguratorSpec extends ObjectBehavior |
|
13
|
|
|
{ |
|
14
|
|
|
function let(Response $response, ResponseHeaderBag $headers) |
|
15
|
|
|
{ |
|
16
|
|
|
$response->headers = $headers; |
|
17
|
|
|
$this->beConstructedWith(true, true, 30); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
function it_is_initializable() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->shouldHaveType(ConfigurableResponseCacheConfigurator::class); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
function it_sets_cache_control_to_public_if_viewcache_is_enabled(Response $response) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->beConstructedWith(true, false, 0); |
|
28
|
|
|
$this->enableCache($response); |
|
29
|
|
|
|
|
30
|
|
|
$response->setPublic()->shouldHaveBeenCalled(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function it_does_not_set_cache_control_if_viewcache_is_disabled(Response $response) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->beConstructedWith(false, false, 0); |
|
36
|
|
|
$this->enableCache($response); |
|
37
|
|
|
|
|
38
|
|
|
$response->setPublic()->shouldNotHaveBeenCalled(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function it_does_not_set_shared_maxage_if_ttl_cache_is_disabled(Response $response) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->beConstructedWith(true, false, 30); |
|
44
|
|
|
$this->setSharedMaxAge($response); |
|
45
|
|
|
|
|
46
|
|
|
$response->setSharedMaxAge(30)->shouldNotHaveBeenCalled(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
View Code Duplication |
function it_does_not_set_shared_maxage_if_it_is_already_set_in_the_response(Response $response, ResponseHeaderBag $headers) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->beConstructedWith(true, true, 30); |
|
52
|
|
|
$headers->hasCacheControlDirective('s-maxage')->willReturn(true); |
|
53
|
|
|
|
|
54
|
|
|
$this->setSharedMaxAge($response); |
|
55
|
|
|
|
|
56
|
|
|
$response->setSharedMaxAge($response, 30)->shouldNotHaveBeenCalled(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
View Code Duplication |
function it_sets_shared_maxage(Response $response, ResponseHeaderBag $headers) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->beConstructedWith(true, true, 30); |
|
62
|
|
|
$headers->hasCacheControlDirective('s-maxage')->willReturn(false); |
|
63
|
|
|
|
|
64
|
|
|
$this->setSharedMaxAge($response); |
|
65
|
|
|
|
|
66
|
|
|
$response->setSharedMaxAge(30)->shouldHaveBeenCalled(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
View Code Duplication |
function it_does_not_add_tags_if_viewcache_is_disabled(Response $response, ResponseHeaderBag $headers) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->beConstructedWith(false, false, 0); |
|
72
|
|
|
$this->addTags($response, ['foo-1', 'bar-2']); |
|
73
|
|
|
|
|
74
|
|
|
$headers->set('xkey', ['foo-1', 'bar-2'])->shouldNotHaveBeenCalled(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
function it_adds_tags_to_the_xkey_header(Response $response, ResponseHeaderBag $headers) |
|
78
|
|
|
{ |
|
79
|
|
|
$this->beConstructedWith(false, false, 0); |
|
80
|
|
|
$this->addTags($response, ['foo-1', 'bar-2']); |
|
81
|
|
|
|
|
82
|
|
|
$headers->set('xkey', ['foo-1', 'bar-2'])->shouldNotHaveBeenCalled(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|