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\Taxonomy\Model; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\Collection; |
15
|
|
|
use PhpSpec\ObjectBehavior; |
16
|
|
|
use Sylius\Component\Taxonomy\Model\Taxon; |
17
|
|
|
use Sylius\Component\Taxonomy\Model\TaxonInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
21
|
|
|
* @author Gonzalo Vilaseca <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
final class TaxonSpec extends ObjectBehavior |
24
|
|
|
{ |
25
|
|
|
public function let() |
26
|
|
|
{ |
27
|
|
|
$this->setCurrentLocale('en_US'); |
28
|
|
|
$this->setFallbackLocale('en_US'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function it_is_initializable() |
32
|
|
|
{ |
33
|
|
|
$this->shouldHaveType(Taxon::class); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_implements_taxon_interface() |
37
|
|
|
{ |
38
|
|
|
$this->shouldImplement(TaxonInterface::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_has_no_id_by_default() |
42
|
|
|
{ |
43
|
|
|
$this->getId()->shouldReturn(null); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function its_code_is_mutable() |
47
|
|
|
{ |
48
|
|
|
$this->setCode('TX2'); |
49
|
|
|
$this->getCode()->shouldReturn('TX2'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function it_has_no_parent_by_default() |
53
|
|
|
{ |
54
|
|
|
$this->getParent()->shouldReturn(null); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
function its_parent_is_mutable(TaxonInterface $taxon) |
58
|
|
|
{ |
59
|
|
|
$this->setParent($taxon); |
60
|
|
|
$this->getParent()->shouldReturn($taxon); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
function it_returns_an_array_of_all_parent_taxons( |
64
|
|
|
TaxonInterface $categoryTaxon, |
65
|
|
|
TaxonInterface $tshirtsTaxon |
66
|
|
|
) { |
67
|
|
|
$tshirtsTaxon->getParent()->willReturn($categoryTaxon); |
68
|
|
|
|
69
|
|
|
$tshirtsTaxon->addChild($this)->shouldBeCalled(); |
70
|
|
|
$this->setParent($tshirtsTaxon); |
71
|
|
|
|
72
|
|
|
$this->getParents()->shouldReturn([$tshirtsTaxon, $categoryTaxon]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
function it_returns_an_array_of_with_a_single_parent_taxon(TaxonInterface $parentTaxon) |
76
|
|
|
{ |
77
|
|
|
$parentTaxon->getParent()->willReturn(null); |
78
|
|
|
$parentTaxon->addChild($this)->shouldBeCalled(); |
79
|
|
|
$this->setParent($parentTaxon); |
80
|
|
|
|
81
|
|
|
$this->getParents()->shouldReturn([$parentTaxon]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
function it_returns_empty_array_for_root_taxon() |
85
|
|
|
{ |
86
|
|
|
$this->getParents()->shouldReturn([]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
function it_is_root_by_default() |
90
|
|
|
{ |
91
|
|
|
$this->shouldBeRoot(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
function it_is_not_root_when_has_parent(TaxonInterface $taxon) |
95
|
|
|
{ |
96
|
|
|
$this->setParent($taxon); |
97
|
|
|
$this->shouldNotBeRoot(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
function it_is_root_when_has_no_parent(TaxonInterface $taxon) |
101
|
|
|
{ |
102
|
|
|
$this->shouldBeRoot(); |
103
|
|
|
|
104
|
|
|
$this->setParent($taxon); |
105
|
|
|
$this->shouldNotBeRoot(); |
106
|
|
|
$this->setParent(null); |
107
|
|
|
|
108
|
|
|
$this->shouldBeRoot(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
function it_is_unnamed_by_default() |
112
|
|
|
{ |
113
|
|
|
$this->getName()->shouldReturn(null); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
function its_name_is_mutable() |
117
|
|
|
{ |
118
|
|
|
$this->setName('Brand'); |
119
|
|
|
$this->getName()->shouldReturn('Brand'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
function it_returns_name_when_converted_to_string() |
123
|
|
|
{ |
124
|
|
|
$this->setName('T-Shirt material'); |
125
|
|
|
$this->__toString()->shouldReturn('T-Shirt material'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
function it_has_no_description_by_default() |
129
|
|
|
{ |
130
|
|
|
$this->getDescription()->shouldReturn(null); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
function its_description_is_mutable() |
134
|
|
|
{ |
135
|
|
|
$this->setDescription('This is a list of brands.'); |
136
|
|
|
$this->getDescription()->shouldReturn('This is a list of brands.'); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
function it_has_no_slug_by_default() |
140
|
|
|
{ |
141
|
|
|
$this->getSlug()->shouldReturn(null); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
function its_slug_is_mutable() |
145
|
|
|
{ |
146
|
|
|
$this->setSlug('t-shirts'); |
147
|
|
|
$this->getSlug()->shouldReturn('t-shirts'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
function it_initializes_child_taxon_collection_by_default() |
151
|
|
|
{ |
152
|
|
|
$this->getChildren()->shouldHaveType(Collection::class); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
function it_allows_to_check_if_given_taxon_is_its_child(TaxonInterface $taxon) |
156
|
|
|
{ |
157
|
|
|
$this->hasChild($taxon)->shouldReturn(false); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
function it_allows_to_add_child_taxons(TaxonInterface $taxon) |
161
|
|
|
{ |
162
|
|
|
$taxon->getParent()->willReturn(null); |
163
|
|
|
$taxon->setParent($this)->shouldBeCalled(); |
164
|
|
|
|
165
|
|
|
$this->addChild($taxon); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
function it_allows_to_remove_child_taxons(TaxonInterface $taxon) |
169
|
|
|
{ |
170
|
|
|
$taxon->getParent()->willReturn(null); |
171
|
|
|
$taxon->setParent($this)->shouldBeCalled(); |
172
|
|
|
|
173
|
|
|
$this->addChild($taxon); |
174
|
|
|
|
175
|
|
|
$taxon->setParent(null)->shouldBeCalled(); |
176
|
|
|
|
177
|
|
|
$this->removeChild($taxon); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
function it_has_position() |
181
|
|
|
{ |
182
|
|
|
$this->setPosition(0); |
183
|
|
|
$this->getPosition()->shouldReturn(0); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
function it_has_not_children_by_default() |
187
|
|
|
{ |
188
|
|
|
$this->hasChildren()->shouldReturn(false); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
function it_has_children_when_you_have_added_child(TaxonInterface $taxon) |
192
|
|
|
{ |
193
|
|
|
$this->addChild($taxon); |
194
|
|
|
|
195
|
|
|
$this->hasChildren()->shouldReturn(true); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|