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
|
|
|
namespace Sylius\Behat\Context\Ui\Admin; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface; |
16
|
|
|
use Sylius\Behat\Page\Admin\ProductAssociationType\CreatePageInterface; |
17
|
|
|
use Sylius\Behat\Page\Admin\ProductAssociationType\UpdatePageInterface; |
18
|
|
|
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; |
19
|
|
|
use Sylius\Component\Association\Model\AssociationTypeInterface; |
20
|
|
|
use Webmozart\Assert\Assert; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class ManagingProductAssociationTypesContext implements Context |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var CreatePageInterface |
29
|
|
|
*/ |
30
|
|
|
private $createPage; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var IndexPageInterface |
34
|
|
|
*/ |
35
|
|
|
private $indexPage; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var UpdatePageInterface |
39
|
|
|
*/ |
40
|
|
|
private $updatePage; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var CurrentPageResolverInterface |
44
|
|
|
*/ |
45
|
|
|
private $currentPageResolver; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param CreatePageInterface $createPage |
49
|
|
|
* @param IndexPageInterface $indexPage |
50
|
|
|
* @param UpdatePageInterface $updatePage |
51
|
|
|
* @param CurrentPageResolverInterface $currentPageResolver |
52
|
|
|
*/ |
53
|
|
|
public function __construct( |
54
|
|
|
CreatePageInterface $createPage, |
55
|
|
|
IndexPageInterface $indexPage, |
56
|
|
|
UpdatePageInterface $updatePage, |
57
|
|
|
CurrentPageResolverInterface $currentPageResolver |
58
|
|
|
) { |
59
|
|
|
$this->createPage = $createPage; |
60
|
|
|
$this->indexPage = $indexPage; |
61
|
|
|
$this->updatePage = $updatePage; |
62
|
|
|
$this->currentPageResolver = $currentPageResolver; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @When I want to browse product association types |
67
|
|
|
*/ |
68
|
|
|
public function iWantToBrowseProductAssociationTypes() |
69
|
|
|
{ |
70
|
|
|
$this->indexPage->open(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @When I want to create a new product association type |
75
|
|
|
*/ |
76
|
|
|
public function iWantToCreateANewProductAssociationType() |
77
|
|
|
{ |
78
|
|
|
$this->createPage->open(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @When I want to modify the :productAssociationType product association type |
83
|
|
|
*/ |
84
|
|
|
public function iWantToModifyAPaymentMethod(AssociationTypeInterface $productAssociationType) |
85
|
|
|
{ |
86
|
|
|
$this->updatePage->open(['id' => $productAssociationType->getId()]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @When I specify its name as :name |
91
|
|
|
* @When I do not name it |
92
|
|
|
*/ |
93
|
|
|
public function iSpecifyItsNameAs($name = null) |
94
|
|
|
{ |
95
|
|
|
$this->createPage->nameIt($name); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @When I rename it to :name |
100
|
|
|
* @When I remove its name |
101
|
|
|
*/ |
102
|
|
|
public function iRenameItTo($name = null) |
103
|
|
|
{ |
104
|
|
|
$this->updatePage->nameIt($name); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @When I specify its code as :code |
109
|
|
|
* @When I do not specify its code |
110
|
|
|
*/ |
111
|
|
|
public function iSpecifyItsCodeAs($code = null) |
112
|
|
|
{ |
113
|
|
|
$this->createPage->specifyCode($code); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @When I add it |
118
|
|
|
* @When I try to add it |
119
|
|
|
*/ |
120
|
|
|
public function iAddIt() |
121
|
|
|
{ |
122
|
|
|
$this->createPage->create(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @When I save my changes |
127
|
|
|
* @When I try to save my changes |
128
|
|
|
*/ |
129
|
|
|
public function iSaveMyChanges() |
130
|
|
|
{ |
131
|
|
|
$this->updatePage->saveChanges(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @When I delete the :productAssociationType product association type |
136
|
|
|
*/ |
137
|
|
|
public function iDeleteTheProductAssociationType(AssociationTypeInterface $productAssociationType) |
138
|
|
|
{ |
139
|
|
|
$this->iWantToBrowseProductAssociationTypes(); |
140
|
|
|
|
141
|
|
|
$this->indexPage->deleteResourceOnPage([ |
142
|
|
|
'code' => $productAssociationType->getCode(), |
143
|
|
|
'name' => $productAssociationType->getName(), |
144
|
|
|
]); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @Then I should see :amount product association types in the list |
149
|
|
|
*/ |
150
|
|
|
public function iShouldSeeCustomerGroupsInTheList($amount) |
151
|
|
|
{ |
152
|
|
|
Assert::same( |
153
|
|
|
(int) $amount, |
154
|
|
|
$this->indexPage->countItems(), |
155
|
|
|
sprintf('Amount of product association types should be equal %s, but is not.', $amount) |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @Then I should see the product association type :name in the list |
161
|
|
|
* |
162
|
|
|
*/ |
163
|
|
|
public function iShouldSeeTheProductAssociationTypeInTheList($name) |
164
|
|
|
{ |
165
|
|
|
$this->iWantToBrowseProductAssociationTypes(); |
166
|
|
|
|
167
|
|
|
Assert::true( |
168
|
|
|
$this->indexPage->isSingleResourceOnPage(['name' => $name]), |
169
|
|
|
sprintf('The product association type with a name %s should exist, but it does not.', $name) |
170
|
|
|
); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @Then the product association type :productAssociationType should appear in the store |
175
|
|
|
*/ |
176
|
|
|
public function theProductAssociationTypeShouldAppearInTheStore(AssociationTypeInterface $productAssociationType) |
177
|
|
|
{ |
178
|
|
|
$this->indexPage->open(); |
179
|
|
|
|
180
|
|
|
Assert::true( |
181
|
|
|
$this->indexPage->isSingleResourceOnPage(['name' => $productAssociationType->getName()]), |
182
|
|
|
sprintf( |
183
|
|
|
'Product association type with name %s should exist but it does not.', |
184
|
|
|
$productAssociationType->getName() |
185
|
|
|
) |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @Then /^(this product association type) name should be "([^"]+)"$/ |
191
|
|
|
* @Then /^(this product association type) should still be named "([^"]+)"$/ |
192
|
|
|
*/ |
193
|
|
|
public function thisProductAssociationTypeNameShouldBe( |
194
|
|
|
AssociationTypeInterface $productAssociationType, |
195
|
|
|
$productAssociationTypeName |
196
|
|
|
) { |
197
|
|
|
$this->iWantToBrowseProductAssociationTypes(); |
198
|
|
|
|
199
|
|
|
Assert::true( |
200
|
|
|
$this->indexPage->isSingleResourceOnPage( |
201
|
|
|
[ |
202
|
|
|
'code' => $productAssociationType->getCode(), |
203
|
|
|
'name' => $productAssociationTypeName, |
204
|
|
|
] |
205
|
|
|
), |
206
|
|
|
sprintf('Product association type name %s has not been assigned properly.', $productAssociationTypeName) |
207
|
|
|
); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @Then the code field should be disabled |
212
|
|
|
*/ |
213
|
|
|
public function theCodeFieldShouldBeDisabled() |
214
|
|
|
{ |
215
|
|
|
Assert::true( |
216
|
|
|
$this->updatePage->isCodeDisabled(), |
217
|
|
|
'Code field should be disabled' |
218
|
|
|
); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @Then /^(this product association type) should no longer exist in the registry$/ |
223
|
|
|
*/ |
224
|
|
|
public function thisProductAssociationTypeShouldNoLongerExistInTheRegistry( |
225
|
|
|
AssociationTypeInterface $productAssociationType |
226
|
|
|
) { |
227
|
|
|
Assert::false( |
228
|
|
|
$this->indexPage->isSingleResourceOnPage([ |
229
|
|
|
'code' => $productAssociationType->getCode(), |
230
|
|
|
'name' => $productAssociationType->getName()] |
231
|
|
|
), |
232
|
|
|
sprintf( |
233
|
|
|
'Product association type%s should no longer exist in the registry', |
234
|
|
|
$productAssociationType->getName() |
235
|
|
|
) |
236
|
|
|
); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @Then I should be notified that product association type with this code already exists |
241
|
|
|
*/ |
242
|
|
|
public function iShouldBeNotifiedThatProductAssociationTypeWithThisCodeAlreadyExists() |
243
|
|
|
{ |
244
|
|
|
Assert::same( |
245
|
|
|
$this->createPage->getValidationMessage('code'), |
246
|
|
|
'The association type with given code already exists.' |
247
|
|
|
); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @Then there should still be only one product association type with a :element :code |
252
|
|
|
*/ |
253
|
|
|
public function thereShouldStillBeOnlyOneProductAssociationTypeWith($element, $code) |
254
|
|
|
{ |
255
|
|
|
$this->iWantToBrowseProductAssociationTypes(); |
256
|
|
|
|
257
|
|
|
Assert::true( |
258
|
|
|
$this->indexPage->isSingleResourceOnPage([$element => $code]), |
259
|
|
|
sprintf('Association type with %s %s cannot be found.', $element, $code) |
260
|
|
|
); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @Then I should be notified that :element is required |
265
|
|
|
*/ |
266
|
|
|
public function iShouldBeNotifiedThatIsRequired($element) |
267
|
|
|
{ |
268
|
|
|
$this->assertFieldValidationMessage( |
269
|
|
|
$element, |
270
|
|
|
sprintf('Please enter association type %s.', $element) |
271
|
|
|
); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @Then the product association type with :element :value should not be added |
276
|
|
|
*/ |
277
|
|
|
public function theProductAssociationTypeWithElementValueShouldNotBeAdded($element, $value) |
278
|
|
|
{ |
279
|
|
|
$this->iWantToBrowseProductAssociationTypes(); |
280
|
|
|
|
281
|
|
|
Assert::false( |
282
|
|
|
$this->indexPage->isSingleResourceOnPage([$element => $value]), |
283
|
|
|
sprintf('Product association type with %s %s was created, but it should not.', $element, $value) |
284
|
|
|
); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param string $element |
289
|
|
|
* @param string $expectedMessage |
290
|
|
|
*/ |
291
|
|
|
private function assertFieldValidationMessage($element, $expectedMessage) |
292
|
|
|
{ |
293
|
|
|
/** @var CreatePageInterface|UpdatePageInterface $currentPage */ |
294
|
|
|
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
295
|
|
|
|
296
|
|
|
Assert::same($currentPage->getValidationMessage($element), $expectedMessage); |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|