|
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\Variation\Model; |
|
13
|
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Sylius\Component\Variation\Model\OptionInterface; |
|
16
|
|
|
use Sylius\Component\Variation\Model\OptionValueInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class OptionValueSpec extends ObjectBehavior |
|
22
|
|
|
{ |
|
23
|
|
|
public function let() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->setCurrentLocale('en_US'); |
|
26
|
|
|
$this->setFallbackLocale('en_US'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
function it_is_initializable() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->shouldHaveType('Sylius\Component\Variation\Model\OptionValue'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function it_is_a_Sylius_product_option_value() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->shouldImplement(OptionValueInterface::class); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_should_not_have_id_by_default() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->getId()->shouldReturn(null); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_has_mutable_code() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->setCode('OV1'); |
|
47
|
|
|
$this->getCode()->shouldReturn('OV1'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function it_should_not_belong_to_an_option_by_default() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->getOption()->shouldReturn(null); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
function it_should_allow_assigning_itself_to_an_option(OptionInterface $option) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->setOption($option); |
|
58
|
|
|
$this->getOption()->shouldReturn($option); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
function it_should_allow_detaching_itself_from_an_option(OptionInterface $option) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->setOption($option); |
|
64
|
|
|
$this->getOption()->shouldReturn($option); |
|
65
|
|
|
|
|
66
|
|
|
$this->setOption(null); |
|
67
|
|
|
$this->getOption()->shouldReturn(null); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
function it_should_not_have_value_by_default() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->getValue()->shouldReturn(null); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
function its_value_should_be_mutable() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->setValue('XXL'); |
|
78
|
|
|
$this->getValue()->shouldReturn('XXL'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
function it_returns_its_value_when_converted_to_string() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->setValue('S'); |
|
84
|
|
|
$this->__toString()->shouldReturn('S'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
function it_throws_exception_when_trying_to_get_name_without_option_being_assigned() |
|
88
|
|
|
{ |
|
89
|
|
|
$this |
|
90
|
|
|
->shouldThrow(\BadMethodCallException::class) |
|
91
|
|
|
->duringGetName() |
|
92
|
|
|
; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
function it_returns_its_option_name(OptionInterface $option) |
|
96
|
|
|
{ |
|
97
|
|
|
$option->getName()->willReturn('T-Shirt size'); |
|
98
|
|
|
$this->setOption($option); |
|
99
|
|
|
|
|
100
|
|
|
$this->getName()->shouldReturn('T-Shirt size'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
function it_throws_exception_when_trying_to_get_presentation_without_option_being_assigned() |
|
104
|
|
|
{ |
|
105
|
|
|
$this |
|
106
|
|
|
->shouldThrow(\BadMethodCallException::class) |
|
107
|
|
|
->duringGetPresentation() |
|
108
|
|
|
; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
function it_returns_its_option_presentation(OptionInterface $option) |
|
112
|
|
|
{ |
|
113
|
|
|
$option->getPresentation()->willReturn('Size'); |
|
114
|
|
|
$this->setOption($option); |
|
115
|
|
|
|
|
116
|
|
|
$this->getPresentation()->shouldReturn('Size'); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|