1 | <?php |
||
28 | final class ManagingZonesContext implements Context |
||
29 | { |
||
30 | /** @var CreatePageInterface */ |
||
31 | private $createPage; |
||
32 | |||
33 | /** @var IndexPageInterface */ |
||
34 | private $indexPage; |
||
35 | |||
36 | /** @var UpdatePageInterface */ |
||
37 | private $updatePage; |
||
38 | |||
39 | /** @var CurrentPageResolverInterface */ |
||
40 | private $currentPageResolver; |
||
41 | |||
42 | /** @var NotificationCheckerInterface */ |
||
43 | private $notificationChecker; |
||
44 | |||
45 | public function __construct( |
||
46 | CreatePageInterface $createPage, |
||
47 | IndexPageInterface $indexPage, |
||
48 | UpdatePageInterface $updatePage, |
||
49 | CurrentPageResolverInterface $currentPageResolver, |
||
50 | NotificationCheckerInterface $notificationChecker |
||
51 | ) { |
||
52 | $this->createPage = $createPage; |
||
53 | $this->indexPage = $indexPage; |
||
54 | $this->updatePage = $updatePage; |
||
55 | $this->currentPageResolver = $currentPageResolver; |
||
56 | $this->notificationChecker = $notificationChecker; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @When I want to create a new zone consisting of :memberType |
||
61 | */ |
||
62 | public function iWantToCreateANewZoneWithMembers($memberType) |
||
63 | { |
||
64 | $this->createPage->open(['type' => $memberType]); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @When I browse zones |
||
69 | * @When I want to see all zones in store |
||
70 | */ |
||
71 | public function iWantToSeeAllZonesInStore() |
||
72 | { |
||
73 | $this->indexPage->open(); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @When /^I want to modify the (zone named "[^"]+")$/ |
||
78 | */ |
||
79 | public function iWantToModifyAZoneNamed(ZoneInterface $zone) |
||
80 | { |
||
81 | $this->updatePage->open(['id' => $zone->getId()]); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @When /^I delete (zone named "([^"]*)")$/ |
||
86 | */ |
||
87 | public function iDeleteZoneNamed(ZoneInterface $zone) |
||
88 | { |
||
89 | $this->indexPage->open(); |
||
90 | $this->indexPage->deleteResourceOnPage(['name' => $zone->getName(), 'code' => $zone->getCode()]); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @When /^I remove (the "([^"]*)" (?:country|province|zone) member)$/ |
||
95 | */ |
||
96 | public function iRemoveTheMember(ZoneMemberInterface $zoneMember) |
||
97 | { |
||
98 | $this->updatePage->removeMember($zoneMember); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @When I rename it to :name |
||
103 | */ |
||
104 | public function iRenameItTo($name) |
||
105 | { |
||
106 | $this->updatePage->nameIt($name ?? ''); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @When I name it :name |
||
111 | */ |
||
112 | public function iNameIt($name) |
||
113 | { |
||
114 | $this->createPage->nameIt($name ?? ''); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @When I specify its code as :code |
||
119 | */ |
||
120 | public function iSpecifyItsCodeAs($code) |
||
121 | { |
||
122 | $this->createPage->specifyCode($code ?? ''); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * @When I do not specify its code |
||
127 | */ |
||
128 | public function iDoNotSpecifyItsCode() |
||
129 | { |
||
130 | // Intentionally left blank to fulfill context expectation |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @When I do not specify its name |
||
135 | */ |
||
136 | public function iDoNotSpecifyItsName() |
||
137 | { |
||
138 | // Intentionally left blank to fulfill context expectation |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * @When I do not add a country member |
||
143 | */ |
||
144 | public function iDoNotAddACountryMember() |
||
145 | { |
||
146 | // Intentionally left blank to fulfill context expectation |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * @When /^I add a(?: country| province| zone) "([^"]+)"$/ |
||
151 | */ |
||
152 | public function iAddAZoneMember($name) |
||
153 | { |
||
154 | $this->createPage->addMember(); |
||
155 | $this->createPage->chooseMember($name); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @When I select its scope as :scope |
||
160 | */ |
||
161 | public function iSelectItsScopeAs($scope) |
||
162 | { |
||
163 | $this->createPage->selectScope($scope); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @When I add it |
||
168 | * @When I try to add it |
||
169 | */ |
||
170 | public function iAddIt() |
||
171 | { |
||
172 | $this->createPage->create(); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @When I save my changes |
||
177 | */ |
||
178 | public function iSaveMyChanges() |
||
179 | { |
||
180 | $this->updatePage->saveChanges(); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * @When I check (also) the :zoneName zone |
||
185 | */ |
||
186 | public function iCheckTheZone(string $zoneName): void |
||
187 | { |
||
188 | $this->indexPage->checkResourceOnPage(['name' => $zoneName]); |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @When I delete them |
||
193 | */ |
||
194 | public function iDeleteThem(): void |
||
195 | { |
||
196 | $this->indexPage->bulkDelete(); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @Then /^the (zone named "[^"]+") with (the "[^"]+" (?:country|province|zone) member) should appear in the registry$/ |
||
201 | */ |
||
202 | public function theZoneWithTheCountryShouldAppearInTheRegistry(ZoneInterface $zone, ZoneMemberInterface $zoneMember) |
||
206 | |||
207 | /** |
||
208 | * @Given its scope should be :scope |
||
209 | */ |
||
210 | public function itsScopeShouldBe($scope) |
||
214 | |||
215 | /** |
||
216 | * @Then /^(this zone) should have only (the "([^"]*)" (?:country|province|zone) member)$/ |
||
217 | */ |
||
218 | public function thisZoneShouldHaveOnlyTheProvinceMember(ZoneInterface $zone, ZoneMemberInterface $zoneMember) |
||
224 | |||
225 | /** |
||
226 | * @Then /^(this zone) name should be "([^"]*)"/ |
||
227 | */ |
||
228 | public function thisZoneNameShouldBe(ZoneInterface $zone, $name) |
||
232 | |||
233 | /** |
||
234 | * @Then I should not be able to edit its code |
||
235 | */ |
||
236 | public function iShouldNotBeAbleToEditItsCode(): void |
||
237 | { |
||
238 | Assert::true($this->updatePage->isCodeDisabled()); |
||
239 | } |
||
240 | |||
241 | /** |
||
242 | * @Then /^I should be notified that zone with this code already exists$/ |
||
243 | */ |
||
244 | public function iShouldBeNotifiedThatZoneWithThisCodeAlreadyExists() |
||
251 | |||
252 | /** |
||
253 | * @Then /^there should still be only one zone with code "([^"]*)"$/ |
||
254 | */ |
||
255 | public function thereShouldStillBeOnlyOneZoneWithCode($code) |
||
261 | |||
262 | /** |
||
263 | * @Then I should be notified that :element is required |
||
264 | */ |
||
265 | public function iShouldBeNotifiedThatIsRequired($element) |
||
272 | |||
273 | /** |
||
274 | * @Then zone with :element :value should not be added |
||
275 | */ |
||
276 | public function zoneWithNameShouldNotBeAdded($element, $value) |
||
282 | |||
283 | /** |
||
284 | * @Then /^I should be notified that at least one zone member is required$/ |
||
285 | */ |
||
286 | public function iShouldBeNotifiedThatAtLeastOneZoneMemberIsRequired() |
||
290 | |||
291 | /** |
||
292 | * @Then I should not be able to edit its type |
||
293 | */ |
||
294 | public function iShouldNotBeAbleToEditItsType(): void |
||
295 | { |
||
296 | Assert::true($this->createPage->isTypeFieldDisabled()); |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * @Then it should be of :type type |
||
301 | */ |
||
302 | public function itShouldBeOfType($type) |
||
306 | |||
307 | /** |
||
308 | * @Then the zone named :zoneName should no longer exist in the registry |
||
309 | */ |
||
310 | public function thisZoneShouldNoLongerExistInTheRegistry($zoneName) |
||
314 | |||
315 | /** |
||
316 | * @Then I should see a single zone in the list |
||
317 | * @Then I should see :amount zones in the list |
||
318 | */ |
||
319 | public function iShouldSeeZonesInTheList(int $amount = 1): void |
||
320 | { |
||
321 | Assert::same($this->indexPage->countItems(), $amount); |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * @Then /^I should(?:| still) see the (zone named "([^"]+)") in the list$/ |
||
326 | */ |
||
327 | public function iShouldSeeTheZoneNamedInTheList(ZoneInterface $zone) |
||
328 | { |
||
329 | Assert::true($this->indexPage->isSingleResourceOnPage(['code' => $zone->getCode(), 'name' => $zone->getName()])); |
||
330 | } |
||
331 | |||
332 | /** |
||
333 | * @Then I should be notified that this zone cannot be deleted |
||
334 | */ |
||
335 | public function iShouldBeNotifiedThatThisZoneCannotBeDeleted() |
||
336 | { |
||
339 | |||
340 | /** |
||
341 | * @throws \InvalidArgumentException |
||
342 | */ |
||
343 | private function assertZoneAndItsMember(ZoneInterface $zone, ZoneMemberInterface $zoneMember) |
||
355 | |||
356 | /** |
||
357 | * @Then /^I can not add a(?: country| province| zone) "([^"]+)"$/ |
||
358 | */ |
||
359 | public function iCanNotAddAZoneMember($name) |
||
369 | } |
||
370 |