|
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\Component\Attribute\AttributeType; |
|
13
|
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Prophecy\Argument; |
|
16
|
|
|
use Sylius\Component\Attribute\AttributeType\AttributeTypeInterface; |
|
17
|
|
|
use Sylius\Component\Attribute\Model\AttributeInterface; |
|
18
|
|
|
use Sylius\Component\Attribute\Model\AttributeValueInterface; |
|
19
|
|
|
use Symfony\Component\Validator\Constraints\Length; |
|
20
|
|
|
use Symfony\Component\Validator\ConstraintViolationInterface; |
|
21
|
|
|
use Symfony\Component\Validator\ConstraintViolationListInterface; |
|
22
|
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface; |
|
23
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
|
24
|
|
|
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @author Mateusz Zalewski <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class TextAttributeTypeSpec extends ObjectBehavior |
|
30
|
|
|
{ |
|
31
|
|
|
function it_is_initializable() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->shouldHaveType('Sylius\Component\Attribute\AttributeType\TextAttributeType'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_implements_attribute_type_interface() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->shouldImplement(AttributeTypeInterface::class); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function its_storage_type_is_text() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->getStorageType()->shouldReturn('text'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
function its_type_is_text() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->getType()->shouldReturn('text'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
function it_checks_if_attribute_value_is_valid( |
|
52
|
|
|
AttributeInterface $attribute, |
|
53
|
|
|
AttributeValueInterface $attributeValue, |
|
54
|
|
|
ConstraintViolationBuilderInterface $constraintViolationBuilder, |
|
55
|
|
|
ConstraintViolationInterface $constraintViolation, |
|
56
|
|
|
ConstraintViolationListInterface $constraintViolationList, |
|
57
|
|
|
ExecutionContextInterface $context, |
|
58
|
|
|
ValidatorInterface $validator |
|
59
|
|
|
) { |
|
60
|
|
|
$attributeValue->getAttribute()->willReturn($attribute); |
|
61
|
|
|
|
|
62
|
|
|
$attributeValue->getValue()->willReturn('X'); |
|
63
|
|
|
|
|
64
|
|
|
$context->getValidator()->willReturn($validator); |
|
65
|
|
|
$validator->validate('X', Argument::type(Length::class))->willReturn($constraintViolationList); |
|
66
|
|
|
|
|
67
|
|
|
$constraintViolationList->rewind()->shouldBeCalled(); |
|
68
|
|
|
$constraintViolationList->valid()->willReturn(true, false); |
|
69
|
|
|
$constraintViolationList->current()->willReturn($constraintViolation); |
|
70
|
|
|
$constraintViolationList->next()->shouldBeCalled(); |
|
71
|
|
|
|
|
72
|
|
|
$constraintViolation->getMessage()->willReturn('error message'); |
|
73
|
|
|
|
|
74
|
|
|
$context->buildViolation('error message')->willReturn($constraintViolationBuilder); |
|
75
|
|
|
$constraintViolationBuilder->atPath('value')->willReturn($constraintViolationBuilder); |
|
76
|
|
|
$constraintViolationBuilder->addViolation()->shouldBeCalled(); |
|
77
|
|
|
|
|
78
|
|
|
$this->validate($attributeValue, $context, array('min' => 2, 'max' => 255)); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|