1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace spec\Sylius\Bundle\ChannelBundle\Context\FakeChannel; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Prophecy\Argument; |
16
|
|
|
use Sylius\Bundle\ChannelBundle\Context\FakeChannel\FakeChannelCodeProviderInterface; |
17
|
|
|
use Sylius\Bundle\ChannelBundle\Context\FakeChannel\FakeChannelPersister; |
18
|
|
|
use Symfony\Component\HttpFoundation\Cookie; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
use Symfony\Component\HttpFoundation\Response; |
21
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
22
|
|
|
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; |
23
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @mixin FakeChannelPersister |
27
|
|
|
* |
28
|
|
|
* @author Kamil Kokot <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class FakeChannelPersisterSpec extends ObjectBehavior |
31
|
|
|
{ |
32
|
|
|
function let(FakeChannelCodeProviderInterface $fakeHostnameProvider) |
33
|
|
|
{ |
34
|
|
|
$this->beConstructedWith($fakeHostnameProvider); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function it_is_initializable() |
38
|
|
|
{ |
39
|
|
|
$this->shouldHaveType('Sylius\Bundle\ChannelBundle\Context\FakeChannel\FakeChannelPersister'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function it_applies_only_to_master_requests(FilterResponseEvent $filterResponseEvent) |
43
|
|
|
{ |
44
|
|
|
$filterResponseEvent->getRequestType()->willReturn(HttpKernelInterface::SUB_REQUEST); |
45
|
|
|
|
46
|
|
|
$filterResponseEvent->getRequest()->shouldNotBeCalled(); |
47
|
|
|
$filterResponseEvent->getResponse()->shouldNotBeCalled(); |
48
|
|
|
|
49
|
|
|
$this->onKernelResponse($filterResponseEvent); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function it_applies_only_for_request_with_fake_channel_code( |
53
|
|
|
FakeChannelCodeProviderInterface $fakeHostnameProvider, |
54
|
|
|
FilterResponseEvent $filterResponseEvent, |
55
|
|
|
Request $request |
56
|
|
|
) { |
57
|
|
|
$filterResponseEvent->getRequestType()->willReturn(HttpKernelInterface::MASTER_REQUEST); |
58
|
|
|
$filterResponseEvent->getRequest()->willReturn($request); |
59
|
|
|
|
60
|
|
|
$fakeHostnameProvider->getCode($request)->willReturn(null); |
61
|
|
|
|
62
|
|
|
$filterResponseEvent->getResponse()->shouldNotBeCalled(); |
63
|
|
|
|
64
|
|
|
$this->onKernelResponse($filterResponseEvent); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function it_persists_fake_channel_codes_in_a_cookie( |
68
|
|
|
FakeChannelCodeProviderInterface $fakeHostnameProvider, |
69
|
|
|
FilterResponseEvent $filterResponseEvent, |
70
|
|
|
Request $request, |
71
|
|
|
Response $response, |
72
|
|
|
ResponseHeaderBag $responseHeaderBag |
73
|
|
|
) { |
74
|
|
|
$filterResponseEvent->getRequestType()->willReturn(HttpKernelInterface::MASTER_REQUEST); |
75
|
|
|
$filterResponseEvent->getRequest()->willReturn($request); |
76
|
|
|
|
77
|
|
|
$fakeHostnameProvider->getCode($request)->willReturn('fake_channel_code'); |
78
|
|
|
|
79
|
|
|
$filterResponseEvent->getResponse()->willReturn($response); |
80
|
|
|
|
81
|
|
|
$response->headers = $responseHeaderBag; |
82
|
|
|
$responseHeaderBag->setCookie(Argument::that(function (Cookie $cookie) { |
83
|
|
|
if ($cookie->getName() !== '_channel_code') { |
84
|
|
|
return false; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if ($cookie->getValue() !== 'fake_channel_code') { |
88
|
|
|
return false; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return true; |
92
|
|
|
}))->shouldBeCalled(); |
93
|
|
|
|
94
|
|
|
$this->onKernelResponse($filterResponseEvent); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|