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