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 Sylius\Behat\Page\Admin\Crud\IndexPageInterface; |
18
|
|
|
use Sylius\Behat\Page\Admin\ShippingCategory\CreatePageInterface; |
19
|
|
|
use Sylius\Behat\Page\Admin\ShippingCategory\UpdatePageInterface; |
20
|
|
|
use Sylius\Component\Shipping\Model\ShippingCategoryInterface; |
21
|
|
|
use Webmozart\Assert\Assert; |
22
|
|
|
|
23
|
|
|
class ManagingShippingCategoriesContext implements Context |
24
|
|
|
{ |
25
|
|
|
/** @var IndexPageInterface */ |
26
|
|
|
private $indexPage; |
27
|
|
|
|
28
|
|
|
/** @var CreatePageInterface */ |
29
|
|
|
private $createPage; |
30
|
|
|
|
31
|
|
|
/** @var UpdatePageInterface */ |
32
|
|
|
private $updatePage; |
33
|
|
|
|
34
|
|
|
public function __construct( |
35
|
|
|
IndexPageInterface $indexPage, |
36
|
|
|
CreatePageInterface $createPage, |
37
|
|
|
UpdatePageInterface $updatePage |
38
|
|
|
) { |
39
|
|
|
$this->indexPage = $indexPage; |
40
|
|
|
$this->createPage = $createPage; |
41
|
|
|
$this->updatePage = $updatePage; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @Given I want to create a new shipping category |
46
|
|
|
*/ |
47
|
|
|
public function iWantToCreateANewShippingCategory() |
48
|
|
|
{ |
49
|
|
|
$this->createPage->open(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @When /^I browse shipping categories$/ |
54
|
|
|
*/ |
55
|
|
|
public function iWantToBrowseShippingCategories() |
56
|
|
|
{ |
57
|
|
|
$this->indexPage->open(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @Then I should see a single shipping category in the list |
62
|
|
|
* @Then I should see :numberOfShippingCategories shipping categories in the list |
63
|
|
|
*/ |
64
|
|
|
public function iShouldSeeShippingCategoriesInTheList(int $numberOfShippingCategories = 1): void |
65
|
|
|
{ |
66
|
|
|
Assert::same($this->indexPage->countItems(), $numberOfShippingCategories); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @When I specify its description as :shippingCategoryDescription |
71
|
|
|
*/ |
72
|
|
|
public function iSpecifyItsDescriptionAs($shippingCategoryDescription) |
73
|
|
|
{ |
74
|
|
|
$this->createPage->specifyDescription($shippingCategoryDescription); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @When I add it |
79
|
|
|
* @When I try to add it |
80
|
|
|
*/ |
81
|
|
|
public function iAddIt() |
82
|
|
|
{ |
83
|
|
|
$this->createPage->create(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Then I should be notified that :element is required |
88
|
|
|
*/ |
89
|
|
|
public function iShouldBeNotifiedThatCodeIsRequired($element) |
90
|
|
|
{ |
91
|
|
|
Assert::same( |
92
|
|
|
$this->updatePage->getValidationMessage($element), |
93
|
|
|
sprintf('Please enter shipping category %s.', $element) |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @When I do not specify its code |
99
|
|
|
* @When I specify its code as :shippingCategoryCode |
100
|
|
|
*/ |
101
|
|
|
public function iSpecifyItsCodeAs($shippingCategoryCode = null) |
102
|
|
|
{ |
103
|
|
|
$this->createPage->specifyCode($shippingCategoryCode ?? ''); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @When I name it :shippingCategoryName |
108
|
|
|
* @When I do not specify its name |
109
|
|
|
*/ |
110
|
|
|
public function iNameIt($shippingCategoryName = null) |
111
|
|
|
{ |
112
|
|
|
$this->createPage->nameIt($shippingCategoryName ?? ''); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @Then I should see the shipping category :shippingCategoryName in the list |
117
|
|
|
*/ |
118
|
|
|
public function iShouldSeeTheShippingCategoryInTheList(string $shippingCategoryName): void |
119
|
|
|
{ |
120
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $shippingCategoryName])); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @Then /^the (shipping category "([^"]+)") should be in the registry$/ |
125
|
|
|
* @Then /^the (shipping category "([^"]+)") should appear in the registry$/ |
126
|
|
|
*/ |
127
|
|
|
public function theShippingCategoryShouldAppearInTheRegistry(ShippingCategoryInterface $shippingCategory) |
128
|
|
|
{ |
129
|
|
|
$this->iWantToBrowseShippingCategories(); |
130
|
|
|
|
131
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage(['code' => $shippingCategory->getCode()])); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @When I delete shipping category :shippingCategoryName |
136
|
|
|
*/ |
137
|
|
|
public function iDeleteShippingCategory($shippingCategoryName) |
138
|
|
|
{ |
139
|
|
|
$this->iWantToBrowseShippingCategories(); |
140
|
|
|
$this->indexPage->deleteResourceOnPage(['name' => $shippingCategoryName]); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @Then /^(this shipping category) should no longer exist in the registry$/ |
145
|
|
|
*/ |
146
|
|
|
public function thisShippingCategoryShouldNoLongerExistInTheRegistry(ShippingCategoryInterface $shippingCategory) |
147
|
|
|
{ |
148
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage(['code' => $shippingCategory->getCode()])); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @Then shipping category with name :shippingCategoryName should not be added |
153
|
|
|
*/ |
154
|
|
|
public function shippingCategoryWithNameShouldNotBeAdded($shippingCategoryName) |
155
|
|
|
{ |
156
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $shippingCategoryName])); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @When /^I modify a (shipping category "([^"]+)")$/ |
161
|
|
|
* @Given /^I want to modify a (shipping category "([^"]+)")$/ |
162
|
|
|
*/ |
163
|
|
|
public function iWantToModifyAShippingCategory(ShippingCategoryInterface $shippingCategory) |
164
|
|
|
{ |
165
|
|
|
$this->updatePage->open(['id' => $shippingCategory->getId()]); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @When I rename it to :name |
170
|
|
|
*/ |
171
|
|
|
public function iNameItIn($name) |
172
|
|
|
{ |
173
|
|
|
$this->createPage->nameIt($name ?? ''); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @When I save my changes |
178
|
|
|
*/ |
179
|
|
|
public function iSaveMyChanges() |
180
|
|
|
{ |
181
|
|
|
$this->updatePage->saveChanges(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @When I check (also) the :shippingCategoryName shipping category |
186
|
|
|
*/ |
187
|
|
|
public function iCheckTheShippingCategory(string $shippingCategoryName): void |
188
|
|
|
{ |
189
|
|
|
$this->indexPage->checkResourceOnPage(['name' => $shippingCategoryName]); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @When I delete them |
194
|
|
|
*/ |
195
|
|
|
public function iDeleteThem(): void |
196
|
|
|
{ |
197
|
|
|
$this->indexPage->bulkDelete(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @Then I should not be able to edit its code |
202
|
|
|
*/ |
203
|
|
|
public function iShouldNotBeAbleToEditItsCode(): void |
204
|
|
|
{ |
205
|
|
|
Assert::true($this->updatePage->isCodeDisabled()); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @Then this shipping category name should be :shippingCategoryName |
210
|
|
|
*/ |
211
|
|
|
public function thisShippingCategoryNameShouldBe($shippingCategoryName) |
212
|
|
|
{ |
213
|
|
|
Assert::true($this->updatePage->hasResourceValues(['name' => $shippingCategoryName])); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @Then I should be notified that shipping category with this code already exists |
218
|
|
|
*/ |
219
|
|
|
public function iShouldBeNotifiedThatShippingCategoryWithThisCodeAlreadyExists() |
220
|
|
|
{ |
221
|
|
|
Assert::same( |
222
|
|
|
$this->createPage->getValidationMessage('code'), |
223
|
|
|
'The shipping category with given code already exists.' |
224
|
|
|
); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @Then there should still be only one shipping category with code :code |
229
|
|
|
*/ |
230
|
|
|
public function thereShouldStillBeOnlyOneShippingCategoryWith($code) |
231
|
|
|
{ |
232
|
|
|
$this->iWantToBrowseShippingCategories(); |
233
|
|
|
|
234
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage(['code' => $code])); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|