|
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\CoreBundle\Form\EventSubscriber; |
|
13
|
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Prophecy\Argument; |
|
16
|
|
|
use Sylius\Bundle\CoreBundle\Form\EventSubscriber\AddBaseCurrencySubscriber; |
|
17
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
18
|
|
|
use Sylius\Component\Resource\Exception\UnexpectedTypeException; |
|
19
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
20
|
|
|
use Symfony\Component\Form\FormEvent; |
|
21
|
|
|
use Symfony\Component\Form\FormEvents; |
|
22
|
|
|
use Symfony\Component\Form\FormInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Anna Walasek <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class AddBaseCurrencySubscriberSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
function it_is_initializable() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->shouldHaveType(AddBaseCurrencySubscriber::class); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function it_implements_event_subscriber_interface() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->shouldImplement(EventSubscriberInterface::class); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_subscribes_to_event() |
|
40
|
|
|
{ |
|
41
|
|
|
$this::getSubscribedEvents()->shouldReturn([FormEvents::PRE_SET_DATA => 'preSetData']); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_sets_base_currency_as_disabled_when_channel_is_not_new( |
|
45
|
|
|
FormEvent $event, |
|
46
|
|
|
ChannelInterface $channel, |
|
47
|
|
|
FormInterface $form |
|
48
|
|
|
) { |
|
49
|
|
|
$event->getData()->willReturn($channel); |
|
50
|
|
|
$event->getForm()->willReturn($form); |
|
51
|
|
|
|
|
52
|
|
|
$channel->getId()->willReturn(2); |
|
53
|
|
|
|
|
54
|
|
|
$form |
|
55
|
|
|
->add('baseCurrency', Argument::type('string'), Argument::withEntry('disabled', true)) |
|
56
|
|
|
->shouldBeCalled() |
|
57
|
|
|
; |
|
58
|
|
|
|
|
59
|
|
|
$this->preSetData($event); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
function it_does_not_set_base_currency_as_enabled_when_channel_is_new( |
|
63
|
|
|
FormEvent $event, |
|
64
|
|
|
ChannelInterface $channel, |
|
65
|
|
|
FormInterface $form |
|
66
|
|
|
) { |
|
67
|
|
|
$event->getData()->willReturn($channel); |
|
68
|
|
|
$event->getForm()->willReturn($form); |
|
69
|
|
|
|
|
70
|
|
|
$channel->getId()->willReturn(null); |
|
71
|
|
|
|
|
72
|
|
|
$form |
|
73
|
|
|
->add('baseCurrency', Argument::type('string'), Argument::withEntry('disabled', false)) |
|
74
|
|
|
->shouldBeCalled() |
|
75
|
|
|
; |
|
76
|
|
|
|
|
77
|
|
|
$this->preSetData($event); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
function it_throws_unexpected_type_exception_when_resource_does_not_implements_channel_interface( |
|
81
|
|
|
FormEvent $event, |
|
82
|
|
|
$resource |
|
83
|
|
|
) { |
|
84
|
|
|
$event->getData()->willReturn($resource); |
|
85
|
|
|
$this->shouldThrow(UnexpectedTypeException::class)->during('preSetData', [$event]); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|