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\Ui\Admin; |
15
|
|
|
|
16
|
|
|
use Behat\Behat\Context\Context; |
17
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
18
|
|
|
use Sylius\Behat\Page\Admin\Country\CreatePageInterface; |
19
|
|
|
use Sylius\Behat\Page\Admin\Country\IndexPageInterface; |
20
|
|
|
use Sylius\Behat\Page\Admin\Country\UpdatePageInterface; |
21
|
|
|
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; |
22
|
|
|
use Sylius\Component\Addressing\Model\CountryInterface; |
23
|
|
|
use Webmozart\Assert\Assert; |
24
|
|
|
|
25
|
|
|
final class ManagingCountriesContext implements Context |
26
|
|
|
{ |
27
|
|
|
/** @var IndexPageInterface */ |
28
|
|
|
private $indexPage; |
29
|
|
|
|
30
|
|
|
/** @var CreatePageInterface */ |
31
|
|
|
private $createPage; |
32
|
|
|
|
33
|
|
|
/** @var UpdatePageInterface */ |
34
|
|
|
private $updatePage; |
35
|
|
|
|
36
|
|
|
/** @var CurrentPageResolverInterface */ |
37
|
|
|
private $currentPageResolver; |
38
|
|
|
|
39
|
|
|
public function __construct( |
40
|
|
|
IndexPageInterface $indexPage, |
41
|
|
|
CreatePageInterface $createPage, |
42
|
|
|
UpdatePageInterface $updatePage, |
43
|
|
|
CurrentPageResolverInterface $currentPageResolver |
44
|
|
|
) { |
45
|
|
|
$this->indexPage = $indexPage; |
46
|
|
|
$this->createPage = $createPage; |
47
|
|
|
$this->updatePage = $updatePage; |
48
|
|
|
$this->currentPageResolver = $currentPageResolver; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @When I want to add a new country |
53
|
|
|
*/ |
54
|
|
|
public function iWantToAddNewCountry() |
55
|
|
|
{ |
56
|
|
|
$this->createPage->open(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @When /^I want to edit (this country)$/ |
61
|
|
|
*/ |
62
|
|
|
public function iWantToEditThisCountry(CountryInterface $country) |
63
|
|
|
{ |
64
|
|
|
$this->updatePage->open(['id' => $country->getId()]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @When I choose :countryName |
69
|
|
|
*/ |
70
|
|
|
public function iChoose($countryName) |
71
|
|
|
{ |
72
|
|
|
$this->createPage->chooseName($countryName); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @When I add the :provinceName province with :provinceCode code |
77
|
|
|
* @When I add the :provinceName province with :provinceCode code and :provinceAbbreviation abbreviation |
78
|
|
|
*/ |
79
|
|
|
public function iAddProvinceWithCode($provinceName, $provinceCode, $provinceAbbreviation = null) |
80
|
|
|
{ |
81
|
|
|
/** @var CreatePageInterface|UpdatePageInterface $currentPage */ |
82
|
|
|
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
83
|
|
|
|
84
|
|
|
$currentPage->addProvince($provinceName, $provinceCode, $provinceAbbreviation); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @When I add it |
89
|
|
|
*/ |
90
|
|
|
public function iAddIt() |
91
|
|
|
{ |
92
|
|
|
$this->createPage->create(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @When I enable it |
97
|
|
|
*/ |
98
|
|
|
public function iEnableIt() |
99
|
|
|
{ |
100
|
|
|
$this->updatePage->enable(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @When I disable it |
105
|
|
|
*/ |
106
|
|
|
public function iDisableIt() |
107
|
|
|
{ |
108
|
|
|
$this->updatePage->disable(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @When I save my changes |
113
|
|
|
* @When I try to save changes |
114
|
|
|
*/ |
115
|
|
|
public function iSaveMyChanges() |
116
|
|
|
{ |
117
|
|
|
$this->updatePage->saveChanges(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @Then /^the (country "([^"]+)") should appear in the store$/ |
122
|
|
|
*/ |
123
|
|
|
public function countryShouldAppearInTheStore(CountryInterface $country) |
124
|
|
|
{ |
125
|
|
|
$this->indexPage->open(); |
126
|
|
|
|
127
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage(['code' => $country->getCode()])); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @Then /^(this country) should be enabled$/ |
132
|
|
|
*/ |
133
|
|
|
public function thisCountryShouldBeEnabled(CountryInterface $country) |
134
|
|
|
{ |
135
|
|
|
$this->indexPage->open(); |
136
|
|
|
|
137
|
|
|
Assert::true($this->indexPage->isCountryEnabled($country)); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @Then /^(this country) should be disabled$/ |
142
|
|
|
*/ |
143
|
|
|
public function thisCountryShouldBeDisabled(CountryInterface $country) |
144
|
|
|
{ |
145
|
|
|
$this->indexPage->open(); |
146
|
|
|
|
147
|
|
|
Assert::true($this->indexPage->isCountryDisabled($country)); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @Then I should not be able to choose :name |
152
|
|
|
*/ |
153
|
|
|
public function iShouldNotBeAbleToChoose($name) |
154
|
|
|
{ |
155
|
|
|
try { |
156
|
|
|
$this->createPage->chooseName($name); |
157
|
|
|
} catch (ElementNotFoundException $exception) { |
|
|
|
|
158
|
|
|
return; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
throw new \DomainException('Choose name should throw an exception!'); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @Then I should not be able to edit its code |
166
|
|
|
*/ |
167
|
|
|
public function theCodeFieldShouldBeDisabled() |
168
|
|
|
{ |
169
|
|
|
Assert::true($this->updatePage->isCodeFieldDisabled()); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @Then /^(this country) should have the "([^"]*)" province$/ |
174
|
|
|
* @Then /^the (country "[^"]*") should have the "([^"]*)" province$/ |
175
|
|
|
*/ |
176
|
|
|
public function countryShouldHaveProvince(CountryInterface $country, $provinceName) |
177
|
|
|
{ |
178
|
|
|
$this->iWantToEditThisCountry($country); |
179
|
|
|
|
180
|
|
|
Assert::true($this->updatePage->isThereProvince($provinceName)); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @Then /^(this country) should not have the "([^"]*)" province$/ |
185
|
|
|
*/ |
186
|
|
|
public function thisCountryShouldNotHaveTheProvince(CountryInterface $country, $provinceName) |
187
|
|
|
{ |
188
|
|
|
$this->iWantToEditThisCountry($country); |
189
|
|
|
|
190
|
|
|
Assert::false($this->updatePage->isThereProvince($provinceName)); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @Then /^the province should still be named "([^"]*)" in (this country)$/ |
195
|
|
|
*/ |
196
|
|
|
public function thisProvinceShouldStillBeNamed($provinceName, CountryInterface $country) |
197
|
|
|
{ |
198
|
|
|
$this->updatePage->open(['id' => $country->getId()]); |
199
|
|
|
|
200
|
|
|
Assert::true($this->updatePage->isThereProvince($provinceName)); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @Then /^province with name "([^"]*)" should not be added in (this country)$/ |
205
|
|
|
*/ |
206
|
|
|
public function provinceWithNameShouldNotBeAdded($provinceName, CountryInterface $country) |
207
|
|
|
{ |
208
|
|
|
$this->updatePage->open(['id' => $country->getId()]); |
209
|
|
|
|
210
|
|
|
Assert::false($this->updatePage->isThereProvince($provinceName)); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @Then /^province with code "([^"]*)" should not be added in (this country)$/ |
215
|
|
|
*/ |
216
|
|
|
public function provinceWithCodeShouldNotBeAdded($provinceCode, CountryInterface $country) |
217
|
|
|
{ |
218
|
|
|
$this->updatePage->open(['id' => $country->getId()]); |
219
|
|
|
|
220
|
|
|
Assert::false($this->updatePage->isThereProvinceWithCode($provinceCode)); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @When /^I delete the "([^"]*)" province of this country$/ |
225
|
|
|
*/ |
226
|
|
|
public function iDeleteTheProvinceOfCountry($provinceName) |
227
|
|
|
{ |
228
|
|
|
$this->updatePage->removeProvince($provinceName); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @When /^I want to create a new province in (country "([^"]*)")$/ |
233
|
|
|
*/ |
234
|
|
|
public function iWantToCreateANewProvinceInCountry(CountryInterface $country) |
235
|
|
|
{ |
236
|
|
|
$this->updatePage->open(['id' => $country->getId()]); |
237
|
|
|
|
238
|
|
|
$this->updatePage->clickAddProvinceButton(); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @When I name the province :provinceName |
243
|
|
|
* @When I do not name the province |
244
|
|
|
*/ |
245
|
|
|
public function iNameTheProvince($provinceName = null) |
246
|
|
|
{ |
247
|
|
|
$this->updatePage->nameProvince($provinceName ?? ''); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @When I do not specify the province code |
252
|
|
|
* @When I specify the province code as :provinceCode |
253
|
|
|
*/ |
254
|
|
|
public function iSpecifyTheProvinceCode($provinceCode = null) |
255
|
|
|
{ |
256
|
|
|
$this->updatePage->specifyProvinceCode($provinceCode ?? ''); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @Then I should be notified that :element is required |
261
|
|
|
*/ |
262
|
|
|
public function iShouldBeNotifiedThatElementIsRequired($element) |
263
|
|
|
{ |
264
|
|
|
Assert::same($this->updatePage->getValidationMessage($element), sprintf('Please enter province %s.', $element)); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @When I remove :provinceName province name |
269
|
|
|
*/ |
270
|
|
|
public function iRemoveProvinceName(string $provinceName): void |
271
|
|
|
{ |
272
|
|
|
$this->updatePage->removeProvinceName($provinceName); |
273
|
|
|
$this->iSaveMyChanges(); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @Then I should be notified that province code must be unique |
278
|
|
|
*/ |
279
|
|
|
public function iShouldBeNotifiedThatProvinceCodeMustBeUnique(): void |
280
|
|
|
{ |
281
|
|
|
Assert::same($this->updatePage->getValidationMessage('code'), 'Province code must be unique.'); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @Then I should be notified that name of the province is required |
286
|
|
|
*/ |
287
|
|
|
public function iShouldBeNotifiedThatNameOfTheProvinceIsRequired(): void |
288
|
|
|
{ |
289
|
|
|
Assert::same($this->updatePage->getValidationMessage('name'), 'Please enter province name.'); |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.