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 Sylius\Behat\Context\Setup; |
15
|
|
|
|
16
|
|
|
use Behat\Behat\Context\Context; |
17
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
18
|
|
|
use Sylius\Behat\Service\SharedStorageInterface; |
19
|
|
|
use Sylius\Component\Addressing\Model\CountryInterface; |
20
|
|
|
use Sylius\Component\Addressing\Model\ZoneInterface; |
21
|
|
|
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; |
22
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
23
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
24
|
|
|
use Sylius\Component\Core\Model\ShopBillingData; |
25
|
|
|
use Sylius\Component\Core\Model\TaxonInterface; |
26
|
|
|
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface; |
27
|
|
|
|
28
|
|
|
final class ChannelContext implements Context |
29
|
|
|
{ |
30
|
|
|
/** @var SharedStorageInterface */ |
31
|
|
|
private $sharedStorage; |
32
|
|
|
|
33
|
|
|
/** @var DefaultChannelFactoryInterface */ |
34
|
|
|
private $unitedStatesChannelFactory; |
35
|
|
|
|
36
|
|
|
/** @var DefaultChannelFactoryInterface */ |
37
|
|
|
private $defaultChannelFactory; |
38
|
|
|
|
39
|
|
|
/** @var ChannelRepositoryInterface */ |
40
|
|
|
private $channelRepository; |
41
|
|
|
|
42
|
|
|
/** @var ObjectManager */ |
43
|
|
|
private $channelManager; |
44
|
|
|
|
45
|
|
|
public function __construct( |
46
|
|
|
SharedStorageInterface $sharedStorage, |
47
|
|
|
DefaultChannelFactoryInterface $unitedStatesChannelFactory, |
48
|
|
|
DefaultChannelFactoryInterface $defaultChannelFactory, |
49
|
|
|
ChannelRepositoryInterface $channelRepository, |
50
|
|
|
ObjectManager $channelManager |
51
|
|
|
) { |
52
|
|
|
$this->sharedStorage = $sharedStorage; |
53
|
|
|
$this->unitedStatesChannelFactory = $unitedStatesChannelFactory; |
54
|
|
|
$this->defaultChannelFactory = $defaultChannelFactory; |
55
|
|
|
$this->channelRepository = $channelRepository; |
56
|
|
|
$this->channelManager = $channelManager; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @Given :channel channel has account verification disabled |
61
|
|
|
*/ |
62
|
|
|
public function channelHasAccountVerificationDisabled(ChannelInterface $channel): void |
63
|
|
|
{ |
64
|
|
|
$channel->setAccountVerificationRequired(false); |
65
|
|
|
|
66
|
|
|
$this->channelManager->flush(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Given the store operates on a single channel in "United States" |
71
|
|
|
*/ |
72
|
|
|
public function storeOperatesOnASingleChannelInUnitedStates() |
73
|
|
|
{ |
74
|
|
|
$defaultData = $this->unitedStatesChannelFactory->create(); |
75
|
|
|
|
76
|
|
|
$this->sharedStorage->setClipboard($defaultData); |
77
|
|
|
$this->sharedStorage->set('channel', $defaultData['channel']); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @Given the store operates on a single channel in the "United States" named :channelIdentifier |
82
|
|
|
*/ |
83
|
|
|
public function storeOperatesOnASingleChannelInTheUnitedStatesNamed($channelIdentifier) |
84
|
|
|
{ |
85
|
|
|
$defaultData = $this->unitedStatesChannelFactory->create($channelIdentifier, $channelIdentifier); |
86
|
|
|
|
87
|
|
|
$this->sharedStorage->setClipboard($defaultData); |
88
|
|
|
$this->sharedStorage->set('channel', $defaultData['channel']); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @Given the store operates on a single channel |
93
|
|
|
* @Given the store operates on a single channel in :currencyCode currency |
94
|
|
|
*/ |
95
|
|
|
public function storeOperatesOnASingleChannel($currencyCode = null) |
96
|
|
|
{ |
97
|
|
|
$defaultData = $this->defaultChannelFactory->create(null, null, $currencyCode); |
98
|
|
|
|
99
|
|
|
$this->sharedStorage->setClipboard($defaultData); |
100
|
|
|
$this->sharedStorage->set('channel', $defaultData['channel']); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)"$/ |
105
|
|
|
* @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)" in "([^"]+)" currency$/ |
106
|
|
|
* @Given the store operates on a channel identified by :code code |
107
|
|
|
* @Given the store (also) operates on a channel named :channelName with hostname :hostname |
108
|
|
|
*/ |
109
|
|
|
public function theStoreOperatesOnAChannelNamed(string $channelName, string $currencyCode = null, string $hostname = null): void |
110
|
|
|
{ |
111
|
|
|
$channelCode = StringInflector::nameToLowercaseCode($channelName); |
112
|
|
|
$defaultData = $this->defaultChannelFactory->create($channelCode, $channelName, $currencyCode); |
113
|
|
|
|
114
|
|
|
$defaultData['channel']->setHostname($hostname); |
115
|
|
|
|
116
|
|
|
$this->sharedStorage->setClipboard($defaultData); |
117
|
|
|
$this->sharedStorage->set('channel', $defaultData['channel']); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @Given the channel :channel is enabled |
122
|
|
|
*/ |
123
|
|
|
public function theChannelIsEnabled(ChannelInterface $channel) |
124
|
|
|
{ |
125
|
|
|
$this->changeChannelState($channel, true); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @Given the channel :channel is disabled |
130
|
|
|
* @Given the channel :channel has been disabled |
131
|
|
|
*/ |
132
|
|
|
public function theChannelIsDisabled(ChannelInterface $channel) |
133
|
|
|
{ |
134
|
|
|
$this->changeChannelState($channel, false); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @Given channel :channel has been deleted |
139
|
|
|
*/ |
140
|
|
|
public function iChannelHasBeenDeleted(ChannelInterface $channel) |
141
|
|
|
{ |
142
|
|
|
$this->channelRepository->remove($channel); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @Given /^(its) default tax zone is (zone "([^"]+)")$/ |
147
|
|
|
*/ |
148
|
|
|
public function itsDefaultTaxRateIs(ChannelInterface $channel, ZoneInterface $defaultTaxZone) |
149
|
|
|
{ |
150
|
|
|
$channel->setDefaultTaxZone($defaultTaxZone); |
151
|
|
|
$this->channelManager->flush(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @Given /^(this channel) has contact email set as "([^"]+)"$/ |
156
|
|
|
* @Given /^(this channel) has no contact email set$/ |
157
|
|
|
*/ |
158
|
|
|
public function thisChannelHasContactEmailSetAs(ChannelInterface $channel, $contactEmail = null) |
159
|
|
|
{ |
160
|
|
|
$channel->setContactEmail($contactEmail); |
161
|
|
|
$this->channelManager->flush(); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @Given /^on (this channel) shipping step is skipped if only a single shipping method is available$/ |
166
|
|
|
*/ |
167
|
|
|
public function onThisChannelShippingStepIsSkippedIfOnlyASingleShippingMethodIsAvailable(ChannelInterface $channel) |
168
|
|
|
{ |
169
|
|
|
$channel->setSkippingShippingStepAllowed(true); |
170
|
|
|
|
171
|
|
|
$this->channelManager->flush(); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @Given /^on (this channel) payment step is skipped if only a single payment method is available$/ |
176
|
|
|
*/ |
177
|
|
|
public function onThisChannelPaymentStepIsSkippedIfOnlyASinglePaymentMethodIsAvailable( |
178
|
|
|
ChannelInterface $channel |
179
|
|
|
) { |
180
|
|
|
$channel->setSkippingPaymentStepAllowed(true); |
181
|
|
|
|
182
|
|
|
$this->channelManager->flush(); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @Given /^on (this channel) account verification is not required$/ |
187
|
|
|
*/ |
188
|
|
|
public function onThisChannelAccountVerificationIsNotRequired(ChannelInterface $channel) |
189
|
|
|
{ |
190
|
|
|
$channel->setAccountVerificationRequired(false); |
191
|
|
|
|
192
|
|
|
$this->channelManager->flush(); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @Given channel :channel billing data is :company, :street, :postcode :city, :country with :taxId tax ID |
197
|
|
|
*/ |
198
|
|
|
public function channelBillingDataIs( |
199
|
|
|
ChannelInterface $channel, |
200
|
|
|
string $company, |
201
|
|
|
string $street, |
202
|
|
|
string $postcode, |
203
|
|
|
string $city, |
204
|
|
|
CountryInterface $country, |
205
|
|
|
string $taxId |
206
|
|
|
): void { |
207
|
|
|
$shopBillingData = new ShopBillingData(); |
208
|
|
|
$shopBillingData->setCompany($company); |
209
|
|
|
$shopBillingData->setStreet($street); |
210
|
|
|
$shopBillingData->setPostcode($postcode); |
211
|
|
|
$shopBillingData->setCity($city); |
212
|
|
|
$shopBillingData->setCountryCode($country->getCode()); |
213
|
|
|
$shopBillingData->setTaxId($taxId); |
214
|
|
|
|
215
|
|
|
$channel->setShopBillingData($shopBillingData); |
216
|
|
|
|
217
|
|
|
$this->channelManager->flush(); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @Given channel :channel has menu taxon :taxon |
223
|
|
|
* @Given /^(this channel) has menu (taxon "[^"]+")$/ |
224
|
|
|
*/ |
225
|
|
|
public function channelHasMenuTaxon(ChannelInterface $channel, TaxonInterface $taxon): void |
226
|
|
|
{ |
227
|
|
|
$channel->setMenuTaxon($taxon); |
228
|
|
|
|
229
|
|
|
$this->channelManager->flush(); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @Given /^(this channel) operates in the ("[^"]+" country)$/ |
234
|
|
|
*/ |
235
|
|
|
public function channelOperatesInCountry(ChannelInterface $channel, CountryInterface $country): void |
236
|
|
|
{ |
237
|
|
|
$channel->addCountry($country); |
238
|
|
|
|
239
|
|
|
$this->channelManager->flush(); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @Given /^(this channel) does not define operating countries$/ |
244
|
|
|
*/ |
245
|
|
|
public function channelDoesNotDefineOperatingCountries(ChannelInterface $channel): void |
246
|
|
|
{ |
247
|
|
|
foreach ($channel->getCountries() as $country) { |
248
|
|
|
$channel->removeCountry($country); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
$this->channelManager->flush(); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @param bool $state |
256
|
|
|
*/ |
257
|
|
|
private function changeChannelState(ChannelInterface $channel, $state) |
258
|
|
|
{ |
259
|
|
|
$channel->setEnabled($state); |
260
|
|
|
$this->channelManager->flush(); |
261
|
|
|
$this->sharedStorage->set('channel', $channel); |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
|