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\Taxon\CreatePageInterface; |
16
|
|
|
use Sylius\Behat\Page\Admin\Taxon\UpdatePageInterface; |
17
|
|
|
use Sylius\Behat\Service\CurrentPageResolverInterface; |
18
|
|
|
use Sylius\Behat\Service\NotificationCheckerInterface; |
19
|
|
|
use Sylius\Component\Core\Model\TaxonInterface; |
20
|
|
|
use Webmozart\Assert\Assert; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class ManagingTaxonsContext implements Context |
26
|
|
|
{ |
27
|
|
|
const RESOURCE_NAME = 'taxon'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var CreatePageInterface |
31
|
|
|
*/ |
32
|
|
|
private $createPage; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var UpdatePageInterface |
36
|
|
|
*/ |
37
|
|
|
private $updatePage; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var CurrentPageResolverInterface |
41
|
|
|
*/ |
42
|
|
|
private $currentPageResolver; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var NotificationCheckerInterface |
46
|
|
|
*/ |
47
|
|
|
private $notificationChecker; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param CreatePageInterface $createPage |
51
|
|
|
* @param UpdatePageInterface $updatePage |
52
|
|
|
* @param CurrentPageResolverInterface $currentPageResolver |
53
|
|
|
* @param NotificationCheckerInterface $notificationChecker |
54
|
|
|
*/ |
55
|
|
|
public function __construct( |
56
|
|
|
CreatePageInterface $createPage, |
57
|
|
|
UpdatePageInterface $updatePage, |
58
|
|
|
CurrentPageResolverInterface $currentPageResolver, |
59
|
|
|
NotificationCheckerInterface $notificationChecker |
60
|
|
|
) { |
61
|
|
|
$this->createPage = $createPage; |
62
|
|
|
$this->updatePage = $updatePage; |
63
|
|
|
$this->currentPageResolver = $currentPageResolver; |
64
|
|
|
$this->notificationChecker = $notificationChecker; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @Given I want to create a new taxon |
69
|
|
|
* @Given I want to see all taxons in store |
70
|
|
|
*/ |
71
|
|
|
public function iWantToCreateANewTaxon() |
72
|
|
|
{ |
73
|
|
|
$this->createPage->open(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @Given /^I want to modify the ("[^"]+" taxon)$/ |
78
|
|
|
*/ |
79
|
|
|
public function iWantToModifyATaxon(TaxonInterface $taxon) |
80
|
|
|
{ |
81
|
|
|
$this->updatePage->open(['id' => $taxon->getId()]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @When I specify its code as :code |
86
|
|
|
*/ |
87
|
|
|
public function iSpecifyItsCodeAs($code) |
88
|
|
|
{ |
89
|
|
|
$this->createPage->specifyCode($code); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @When I name it :name in :language |
94
|
|
|
*/ |
95
|
|
|
public function iNameItIn($name, $language) |
96
|
|
|
{ |
97
|
|
|
$this->createPage->nameIt($name, $language); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @When I rename it to :name in :language |
102
|
|
|
*/ |
103
|
|
|
public function iRenameItIn($name, $language) |
104
|
|
|
{ |
105
|
|
|
$this->updatePage->nameIt($name, $language); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @When I change its description to :description in :language |
110
|
|
|
*/ |
111
|
|
|
public function iChangeItsDescriptionToIn($description, $language) |
112
|
|
|
{ |
113
|
|
|
$this->updatePage->describeItAs($description, $language); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @When I specify its permalink as :permalink in :language |
118
|
|
|
*/ |
119
|
|
|
public function iSpecifyItsPermalinkAs($permalink, $language) |
120
|
|
|
{ |
121
|
|
|
$this->createPage->specifyPermalink($permalink, $language); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @When I change its permalink to :permalink in :language |
126
|
|
|
*/ |
127
|
|
|
public function iChangeItsPermalinkToIn($permalink, $language) |
128
|
|
|
{ |
129
|
|
|
$this->updatePage->specifyPermalink($permalink, $language); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @When I describe it as :description in :language |
134
|
|
|
*/ |
135
|
|
|
public function iDescribeItAs($description, $language) |
136
|
|
|
{ |
137
|
|
|
$this->createPage->describeItAs($description, $language); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @Given /^I choose ("[^"]+" as a parent taxon)$/ |
142
|
|
|
*/ |
143
|
|
|
public function iChooseAsAParentTaxon(TaxonInterface $taxon) |
144
|
|
|
{ |
145
|
|
|
$this->createPage->chooseParent($taxon); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @Given /^I change its (parent taxon to "[^"]+")$/ |
150
|
|
|
*/ |
151
|
|
|
public function iChangeItsParentTaxonTo(TaxonInterface $taxon) |
152
|
|
|
{ |
153
|
|
|
$this->updatePage->chooseParent($taxon); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @When I do not specify its code |
158
|
|
|
*/ |
159
|
|
|
public function iDoNotSpecifyItsCode() |
160
|
|
|
{ |
161
|
|
|
// Intentionally left blank to fulfill context expectation |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @When I do not specify its name |
166
|
|
|
*/ |
167
|
|
|
public function iDoNotSpecifyItsName() |
168
|
|
|
{ |
169
|
|
|
// Intentionally left blank to fulfill context expectation |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @When I delete taxon named :name |
174
|
|
|
*/ |
175
|
|
|
public function iDeleteTaxonNamed($name) |
176
|
|
|
{ |
177
|
|
|
$this->createPage->open(); |
178
|
|
|
$this->createPage->deleteTaxonOnPageByName($name); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @When I add it |
183
|
|
|
* @When I try to add it |
184
|
|
|
*/ |
185
|
|
|
public function iAddIt() |
186
|
|
|
{ |
187
|
|
|
$this->createPage->create(); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @When I save my changes |
192
|
|
|
* @When I try to save my changes |
193
|
|
|
*/ |
194
|
|
|
public function iSaveMyChanges() |
195
|
|
|
{ |
196
|
|
|
$this->updatePage->saveChanges(); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @Then I should be notified that it has been successfully created |
201
|
|
|
*/ |
202
|
|
|
public function iShouldBeNotifiedItHasBeenSuccessfullyCreated() |
203
|
|
|
{ |
204
|
|
|
$this->notificationChecker->checkCreationNotification(self::RESOURCE_NAME); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @Then I should be notified that it has been successfully edited |
209
|
|
|
*/ |
210
|
|
|
public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited() |
211
|
|
|
{ |
212
|
|
|
$this->notificationChecker->checkEditionNotification(self::RESOURCE_NAME); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @Then I should be notified that it has been successfully deleted |
217
|
|
|
*/ |
218
|
|
|
public function iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted() |
219
|
|
|
{ |
220
|
|
|
$this->notificationChecker->checkDeletionNotification(self::RESOURCE_NAME); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @Then /^the ("[^"]+" taxon) should appear in the registry$/ |
225
|
|
|
*/ |
226
|
|
|
public function theTaxonShouldAppearInTheRegistry(TaxonInterface $taxon) |
227
|
|
|
{ |
228
|
|
|
$this->updatePage->open(['id' => $taxon->getId()]); |
229
|
|
|
Assert::true( |
230
|
|
|
$this->updatePage->hasResourceValues(['code' => $taxon->getCode()]), |
231
|
|
|
sprintf('Taxon %s should be in the registry.', $taxon->getName()) |
232
|
|
|
); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @Then this taxon :element should be :value |
237
|
|
|
*/ |
238
|
|
|
public function thisTaxonElementShouldBe($element, $value) |
239
|
|
|
{ |
240
|
|
|
Assert::true( |
241
|
|
|
$this->updatePage->hasResourceValues([$element => $value]), |
242
|
|
|
sprintf('Taxon with %s should have %s value.', $element, $value) |
243
|
|
|
); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @Then the code field should be disabled |
248
|
|
|
*/ |
249
|
|
|
public function theCodeFieldShouldBeDisabled() |
250
|
|
|
{ |
251
|
|
|
Assert::true( |
252
|
|
|
$this->updatePage->isCodeDisabled(), |
253
|
|
|
'Code field should be disabled but it is not.' |
254
|
|
|
); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @Then /^this taxon should (belongs to "[^"]+")$/ |
259
|
|
|
*/ |
260
|
|
|
public function thisTaxonShouldBelongsTo(TaxonInterface $taxon) |
261
|
|
|
{ |
262
|
|
|
Assert::true( |
263
|
|
|
$this->updatePage->hasResourceValues(['parent' => $taxon->getId()]), |
264
|
|
|
sprintf('Current taxon should have %s parent taxon.', $taxon->getName()) |
265
|
|
|
); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @Then I should be notified that taxon with this code already exists |
270
|
|
|
*/ |
271
|
|
|
public function iShouldBeNotifiedThatTaxonWithThisCodeAlreadyExists() |
272
|
|
|
{ |
273
|
|
|
$currentPage = $this->currentPageResolver->getCurrentPageWithForm($this->createPage, $this->updatePage); |
274
|
|
|
|
275
|
|
|
Assert::true( |
276
|
|
|
$currentPage->checkValidationMessageFor('code', 'Taxon with given code already exists.'), |
277
|
|
|
'Unique code violation message should appear on page, but it does not.' |
278
|
|
|
); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @Then I should be notified that :element is required |
283
|
|
|
*/ |
284
|
|
|
public function iShouldBeNotifiedThatIsRequired($element) |
285
|
|
|
{ |
286
|
|
|
$currentPage = $this->currentPageResolver->getCurrentPageWithForm($this->createPage, $this->updatePage); |
287
|
|
|
|
288
|
|
|
Assert::true( |
289
|
|
|
$currentPage->checkValidationMessageFor($element, sprintf('Please enter taxon %s.', $element)), |
290
|
|
|
sprintf('I should be notified that taxon %s should be required.', $element) |
291
|
|
|
); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @Then /^there should still be only one taxon with code "([^"]+)"$/ |
296
|
|
|
*/ |
297
|
|
|
public function thereShouldStillBeOnlyOneTaxonWithCode($code) |
298
|
|
|
{ |
299
|
|
|
Assert::true( |
300
|
|
|
$this->updatePage->hasResourceValues(['code' => $code]), |
301
|
|
|
sprintf('Taxon with code %s cannot be found.', $code) |
302
|
|
|
); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @Then /^Taxon named "([^"]+)" should not be added$/ |
307
|
|
|
* @Then the taxon named :name should no longer exist in the registry |
308
|
|
|
*/ |
309
|
|
|
public function taxonNamedShouldNotBeAdded($name) |
310
|
|
|
{ |
311
|
|
|
Assert::eq( |
312
|
|
|
0, |
313
|
|
|
$this->createPage->countTaxonsByName($name), |
314
|
|
|
sprintf('Taxon %s should not exist.', $name) |
315
|
|
|
); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @Then /^I should see (\d+) taxons on the list$/ |
320
|
|
|
*/ |
321
|
|
|
public function iShouldSeeTaxonsInTheList($number) |
322
|
|
|
{ |
323
|
|
|
$taxonsOnPage = $this->createPage->countTaxons(); |
324
|
|
|
|
325
|
|
|
Assert::eq( |
326
|
|
|
$number, |
327
|
|
|
$taxonsOnPage, |
328
|
|
|
sprintf('On list should be %d taxons but get %d.', $number, $taxonsOnPage) |
329
|
|
|
); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @Then I should see the taxon named :name in the list |
334
|
|
|
*/ |
335
|
|
|
public function iShouldSeeTheTaxonNamedInTheList($name) |
336
|
|
|
{ |
337
|
|
|
Assert::eq( |
338
|
|
|
1, |
339
|
|
|
$this->createPage->countTaxonsByName($name), |
340
|
|
|
sprintf('Taxon %s does not exist or multiple taxons with this name exist.', $name) |
341
|
|
|
); |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
|