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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\CoreBundle\Validator\Constraints; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Bundle\CoreBundle\Validator\Constraints\ChannelDefaultLocaleEnabled; |
18
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
19
|
|
|
use Sylius\Component\Locale\Model\LocaleInterface; |
20
|
|
|
use Symfony\Component\Validator\Constraint; |
21
|
|
|
use Symfony\Component\Validator\ConstraintValidator; |
22
|
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface; |
23
|
|
|
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface; |
24
|
|
|
|
25
|
|
|
final class ChannelDefaultLocaleEnabledValidatorSpec extends ObjectBehavior |
26
|
|
|
{ |
27
|
|
|
function let(ExecutionContextInterface $executionContext): void |
28
|
|
|
{ |
29
|
|
|
$this->initialize($executionContext); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
function it_is_a_constraint_validator(): void |
33
|
|
|
{ |
34
|
|
|
$this->shouldHaveType(ConstraintValidator::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function it_validates_only_a_channel(\stdClass $object): void |
38
|
|
|
{ |
39
|
|
|
$constraint = new ChannelDefaultLocaleEnabled(); |
40
|
|
|
|
41
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('validate', [$object, $constraint]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_is_a_channel_default_locale_enabled_validator(ChannelInterface $channel, Constraint $constraint): void |
45
|
|
|
{ |
46
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('validate', [$channel, $constraint]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function it_adds_violation_if_default_locale_is_not_enabled_for_a_given_channel( |
50
|
|
|
ExecutionContextInterface $executionContext, |
51
|
|
|
ConstraintViolationBuilderInterface $constraintViolationBuilder, |
52
|
|
|
ChannelInterface $channel, |
53
|
|
|
LocaleInterface $locale |
54
|
|
|
): void { |
55
|
|
|
$constraint = new ChannelDefaultLocaleEnabled(); |
56
|
|
|
|
57
|
|
|
$channel->getDefaultLocale()->willReturn($locale); |
58
|
|
|
$channel->hasLocale($locale)->willReturn(false); |
59
|
|
|
|
60
|
|
|
$executionContext->buildViolation($constraint->message)->willReturn($constraintViolationBuilder); |
61
|
|
|
$constraintViolationBuilder->atPath('defaultLocale')->willReturn($constraintViolationBuilder); |
62
|
|
|
$constraintViolationBuilder->addViolation()->shouldBeCalled(); |
63
|
|
|
|
64
|
|
|
$this->validate($channel, $constraint); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function it_does_nothing_if_default_locale_is_enabled_for_a_given_channel( |
68
|
|
|
ExecutionContextInterface $executionContext, |
69
|
|
|
ChannelInterface $channel, |
70
|
|
|
LocaleInterface $locale |
71
|
|
|
): void { |
72
|
|
|
$constraint = new ChannelDefaultLocaleEnabled(); |
73
|
|
|
|
74
|
|
|
$channel->getDefaultLocale()->willReturn($locale); |
75
|
|
|
$channel->hasLocale($locale)->willReturn(true); |
76
|
|
|
|
77
|
|
|
$executionContext->buildViolation($constraint->message)->shouldNotBeCalled(); |
78
|
|
|
|
79
|
|
|
$this->validate($channel, $constraint); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|