/
TaxonSpec.php
212 lines (167 loc) · 5.42 KB
/
TaxonSpec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace spec\Sylius\Component\Taxonomy\Model;
use Doctrine\Common\Collections\Collection;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Taxonomy\Model\TaxonInterface;
final class TaxonSpec extends ObjectBehavior
{
public function let()
{
$this->setCurrentLocale('en_US');
$this->setFallbackLocale('en_US');
}
function it_implements_taxon_interface(): void
{
$this->shouldImplement(TaxonInterface::class);
}
function it_has_no_id_by_default(): void
{
$this->getId()->shouldReturn(null);
}
function its_code_is_mutable(): void
{
$this->setCode('TX2');
$this->getCode()->shouldReturn('TX2');
}
function it_has_no_parent_by_default(): void
{
$this->getParent()->shouldReturn(null);
}
function its_parent_is_mutable(TaxonInterface $taxon): void
{
$this->setParent($taxon);
$this->getParent()->shouldReturn($taxon);
}
function it_is_root_by_default(): void
{
$this->shouldBeRoot();
}
function it_is_not_root_when_has_parent(TaxonInterface $taxon): void
{
$this->setParent($taxon);
$this->shouldNotBeRoot();
}
function it_is_root_when_has_no_parent(TaxonInterface $taxon): void
{
$this->shouldBeRoot();
$this->setParent($taxon);
$this->shouldNotBeRoot();
$this->setParent(null);
$this->shouldBeRoot();
}
function it_returns_a_list_of_ancestors(
TaxonInterface $categoryTaxon,
TaxonInterface $tshirtsTaxon
): void {
$tshirtsTaxon->getParent()->willReturn($categoryTaxon);
$tshirtsTaxon->addChild($this)->shouldBeCalled();
$this->setParent($tshirtsTaxon);
$this->getAncestors()->shouldIterateAs([$tshirtsTaxon->getWrappedObject(), $categoryTaxon->getWrappedObject()]);
}
function it_returns_a_list_with_single_ancestor(TaxonInterface $parentTaxon): void
{
$parentTaxon->getParent()->willReturn(null);
$parentTaxon->addChild($this)->shouldBeCalled();
$this->setParent($parentTaxon);
$this->getAncestors()->shouldIterateAs([$parentTaxon->getWrappedObject()]);
}
function it_returns_an_empty_list_of_ancestors_if_called_on_root_taxon(): void
{
$this->getAncestors()->shouldIterateAs([]);
}
function it_is_unnamed_by_default(): void
{
$this->getName()->shouldReturn(null);
}
function its_name_is_mutable(): void
{
$this->setName('Brand');
$this->getName()->shouldReturn('Brand');
}
function it_returns_name_when_converted_to_string(): void
{
$this->setName('T-Shirt material');
$this->__toString()->shouldReturn('T-Shirt material');
}
function its_fullname_is_null_if_unnamed(): void
{
$this->getFullname()->shouldReturn(null);
}
function its_fullname_equal_name_if_no_parent(): void
{
$this->setName('Category');
$this->getFullname()->shouldReturn('Category');
}
function its_fullname_prepends_with_parents_fullname(TaxonInterface $root): void
{
$root->getFullname()->willReturn('Category');
$this->setName('T-shirts');
$root->addChild($this)->shouldBeCalled();
$this->setParent($root);
$this->getFullname()->shouldReturn('Category / T-shirts');
$this->getFullname(' -- ')->shouldReturn('Category -- T-shirts');
}
function it_has_no_description_by_default(): void
{
$this->getDescription()->shouldReturn(null);
}
function its_description_is_mutable(): void
{
$this->setDescription('This is a list of brands.');
$this->getDescription()->shouldReturn('This is a list of brands.');
}
function it_has_no_slug_by_default(): void
{
$this->getSlug()->shouldReturn(null);
}
function its_slug_is_mutable(): void
{
$this->setSlug('t-shirts');
$this->getSlug()->shouldReturn('t-shirts');
}
function it_initializes_child_taxon_collection_by_default(): void
{
$this->getChildren()->shouldHaveType(Collection::class);
}
function it_allows_to_check_if_given_taxon_is_its_child(TaxonInterface $taxon): void
{
$this->hasChild($taxon)->shouldReturn(false);
}
function it_allows_to_add_child_taxons(TaxonInterface $taxon): void
{
$taxon->getParent()->willReturn(null);
$taxon->setParent($this)->shouldBeCalled();
$this->addChild($taxon);
}
function it_allows_to_remove_child_taxons(TaxonInterface $taxon): void
{
$taxon->getParent()->willReturn(null);
$taxon->setParent($this)->shouldBeCalled();
$this->addChild($taxon);
$taxon->setParent(null)->shouldBeCalled();
$this->removeChild($taxon);
}
function it_has_position(): void
{
$this->setPosition(0);
$this->getPosition()->shouldReturn(0);
}
function it_has_not_children_by_default(): void
{
$this->hasChildren()->shouldReturn(false);
}
function it_has_children_when_you_have_added_child(TaxonInterface $taxon): void
{
$this->addChild($taxon);
$this->hasChildren()->shouldReturn(true);
}
}