Completed
Push — master ( 4ad486...2231e0 )
by Paweł
19:28 queued 09:00
created

iAllowToSkipPaymentStepIfOnlyOnePaymentMethodIsAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\NotificationType;
16
use Sylius\Behat\Page\Admin\Channel\CreatePageInterface;
17
use Sylius\Behat\Page\Admin\Channel\IndexPageInterface;
18
use Sylius\Behat\Page\Admin\Channel\UpdatePageInterface;
19
use Sylius\Behat\Service\NotificationCheckerInterface;
20
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
21
use Sylius\Component\Core\Formatter\StringInflector;
22
use Sylius\Component\Core\Model\ChannelInterface;
23
use Webmozart\Assert\Assert;
24
25
/**
26
 * @author Łukasz Chruściel <[email protected]>
27
 */
28
final class ManagingChannelsContext implements Context
29
{
30
    /**
31
     * @var IndexPageInterface
32
     */
33
    private $indexPage;
34
35
    /**
36
     * @var CreatePageInterface
37
     */
38
    private $createPage;
39
40
    /**
41
     * @var UpdatePageInterface
42
     */
43
    private $updatePage;
44
45
    /**
46
     * @var CurrentPageResolverInterface
47
     */
48
    private $currentPageResolver;
49
50
    /**
51
     * @var NotificationCheckerInterface
52
     */
53
    private $notificationChecker;
54
55
    /**
56
     * @param IndexPageInterface $indexPage
57
     * @param CreatePageInterface $createPage
58
     * @param UpdatePageInterface $updatePage
59
     * @param CurrentPageResolverInterface $currentPageResolver
60
     * @param NotificationCheckerInterface $notificationChecker
61
     */
62
    public function __construct(
63
        IndexPageInterface $indexPage,
64
        CreatePageInterface $createPage,
65
        UpdatePageInterface $updatePage,
66
        CurrentPageResolverInterface $currentPageResolver,
67
        NotificationCheckerInterface $notificationChecker
68
    ) {
69
        $this->indexPage = $indexPage;
70
        $this->createPage = $createPage;
71
        $this->updatePage = $updatePage;
72
        $this->currentPageResolver = $currentPageResolver;
73
        $this->notificationChecker = $notificationChecker;
74
    }
75
76
    /**
77
     * @Given I want to create a new channel
78
     */
79
    public function iWantToCreateANewChannel()
80
    {
81
        $this->createPage->open();
82
    }
83
84
    /**
85
     * @When I specify its code as :code
86
     * @When I do not specify its code
87
     */
88
    public function iSpecifyItsCodeAs($code = null)
89
    {
90
        $this->createPage->specifyCode($code);
91
    }
92
93
    /**
94
     * @When I name it :name
95
     * @When I rename it to :name
96
     * @When I do not name it
97
     * @When I remove its name
98
     */
99
    public function iNameIt($name = null)
100
    {
101
        $this->createPage->nameIt($name);
102
    }
103
104
    /**
105
     * @When I choose :currency as the base currency
106
     * @When I do not choose base currency
107
     */
108
    public function iChooseAsABaseCurrency($currency = null)
109
    {
110
        $this->createPage->chooseBaseCurrency($currency);
111
    }
112
113
    /**
114
     * @When I choose :locale as a default locale
115
     * @When I do not choose default locale
116
     */
117
    public function iChooseAsADefaultLocale($locale = null)
118
    {
119
        $this->createPage->chooseDefaultLocale($locale);
120
    }
121
122
    /**
123
     * @When I allow to skip shipping step if only one shipping method is available
124
     */
125
    public function iAllowToSkipShippingStepIfOnlyOneShippingMethodIsAvailable()
126
    {
127
        $this->createPage->allowToSkipShippingStep();
128
    }
129
130
    /**
131
     * @When I allow to skip payment step if only one payment method is available
132
     */
133
    public function iAllowToSkipPaymentStepIfOnlyOnePaymentMethodIsAvailable()
134
    {
135
        $this->createPage->allowToSkipPaymentStep();
136
    }
137
138
    /**
139
     * @When I add it
140
     * @When I try to add it
141
     */
142
    public function iAddIt()
143
    {
144
        $this->createPage->create();
145
    }
146
147
    /**
148
     * @Then the channel :channelName should appear in the registry
149
     * @Then the channel :channelName should be in the registry
150
     */
151
    public function theChannelShouldAppearInTheRegistry($channelName)
152
    {
153
        $this->iWantToBrowseChannels();
154
155
        Assert::true($this->indexPage->isSingleResourceOnPage(['nameAndDescription' => $channelName]));
156
    }
157
158
    /**
159
     * @Then /^(this channel) should still be in the registry$/
160
     */
161
    public function thisChannelShouldAppearInTheRegistry(ChannelInterface $channel)
162
    {
163
        $this->theChannelShouldAppearInTheRegistry($channel->getName());
164
    }
165
166
    /**
167
     * @When I describe it as :description
168
     */
169
    public function iDescribeItAs($description)
170
    {
171
        $this->createPage->describeItAs($description);
172
    }
173
174
    /**
175
     * @When I set its hostname as :hostname
176
     */
177
    public function iSetItsHostnameAs($hostname)
178
    {
179
        $this->createPage->setHostname($hostname);
180
    }
181
182
    /**
183
     * @When I set its contact email as :contactEmail
184
     */
185
    public function iSetItsContactEmailAs($contactEmail)
186
    {
187
        $this->createPage->setContactEmail($contactEmail);
188
    }
189
190
    /**
191
     * @When I define its color as :color
192
     */
193
    public function iDefineItsColorAs($color)
194
    {
195
        $this->createPage->defineColor($color);
196
    }
197
198
    /**
199
     * @When I enable it
200
     */
201
    public function iEnableIt()
202
    {
203
        $this->updatePage->enable();
204
    }
205
206
    /**
207
     * @When I disable it
208
     */
209
    public function iDisableIt()
210
    {
211
        $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
212
213
        $currentPage->disable();
214
    }
215
216
    /**
217
     * @Then I should be notified that at least one channel has to be defined
218
     */
219
    public function iShouldBeNotifiedThatAtLeastOneChannelHasToBeDefinedIsRequired()
220
    {
221
        /** @var CreatePageInterface|UpdatePageInterface $currentPage */
222
        $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
223
224
        Assert::same($currentPage->getValidationMessage('enabled'), 'Must have at least one enabled entity');
225
    }
226
227
    /**
228
     * @Then channel with :element :value should not be added
229
     */
230
    public function channelWithShouldNotBeAdded($element, $value)
231
    {
232
        $this->iWantToBrowseChannels();
233
234
        Assert::false($this->indexPage->isSingleResourceOnPage([$element => $value]));
235
    }
236
237
    /**
238
     * @Then /^I should be notified that ([^"]+) is required$/
239
     */
240
    public function iShouldBeNotifiedThatIsRequired($element)
241
    {
242
        /** @var CreatePageInterface|UpdatePageInterface $currentPage */
243
        $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
244
245
        Assert::same(
246
            $currentPage->getValidationMessage(StringInflector::nameToCode($element)),
247
            sprintf('Please enter channel %s.', $element)
248
        );
249
    }
250
251
    /**
252
     * @Given I want to modify a channel :channel
253
     * @Given /^I want to modify (this channel)$/
254
     */
255
    public function iWantToModifyChannel(ChannelInterface $channel)
256
    {
257
        $this->updatePage->open(['id' => $channel->getId()]);
258
    }
259
260
    /**
261
     * @Then /^(this channel) name should be "([^"]+)"$/
262
     * @Then /^(this channel) should still be named "([^"]+)"$/
263
     */
264
    public function thisChannelNameShouldBe(ChannelInterface $channel, $channelName)
265
    {
266
        $this->iWantToBrowseChannels();
267
268
        Assert::true($this->indexPage->isSingleResourceOnPage([
269
            'code' => $channel->getCode(),
270
            'nameAndDescription' => $channelName,
271
        ]));
272
    }
273
274
    /**
275
     * @When I save my changes
276
     * @When I try to save my changes
277
     */
278
    public function iSaveMyChanges()
279
    {
280
        $this->updatePage->saveChanges();
281
    }
282
283
    /**
284
     * @Then I should be notified that channel with this code already exists
285
     */
286
    public function iShouldBeNotifiedThatChannelWithThisCodeAlreadyExists()
287
    {
288
        Assert::same($this->createPage->getValidationMessage('code'), 'Channel code has to be unique.');
289
    }
290
291
    /**
292
     * @Then there should still be only one channel with :element :value
293
     */
294
    public function thereShouldStillBeOnlyOneChannelWithCode($element, $value)
295
    {
296
        $this->iWantToBrowseChannels();
297
298
        Assert::true($this->indexPage->isSingleResourceOnPage([$element => $value]));
299
    }
300
301
    /**
302
     * @When /^I want to browse channels$/
303
     */
304
    public function iWantToBrowseChannels()
305
    {
306
        $this->indexPage->open();
307
    }
308
309
    /**
310
     * @Then I should see :numberOfChannels channels in the list
311
     */
312
    public function iShouldSeeChannelsInTheList($numberOfChannels)
313
    {
314
        Assert::same($this->indexPage->countItems(), (int) $numberOfChannels);
315
    }
316
317
    /**
318
     * @Then the code field should be disabled
319
     */
320
    public function theCodeFieldShouldBeDisabled()
321
    {
322
        Assert::true($this->updatePage->isCodeDisabled());
323
    }
324
325
    /**
326
     * @Then /^(this channel) should be disabled$/
327
     */
328
    public function thisChannelShouldBeDisabled(ChannelInterface $channel)
329
    {
330
        $this->assertChannelState($channel, false);
331
    }
332
333
    /**
334
     * @Then /^(this channel) should be enabled$/
335
     * @Then channel with name :channel should still be enabled
336
     */
337
    public function thisChannelShouldBeEnabled(ChannelInterface $channel)
338
    {
339
        $this->assertChannelState($channel, true);
340
    }
341
342
    /**
343
     * @When I delete channel :channel
344
     */
345
    public function iDeleteChannel(ChannelInterface $channel)
346
    {
347
        $this->indexPage->open();
348
        $this->indexPage->deleteResourceOnPage(['nameAndDescription' => $channel->getName()]);
349
    }
350
351
    /**
352
     * @Then the :channelName channel should no longer exist in the registry
353
     */
354
    public function thisChannelShouldNoLongerExistInTheRegistry($channelName)
355
    {
356
        Assert::false($this->indexPage->isSingleResourceOnPage(['nameAndDescription' => $channelName]));
357
    }
358
359
    /**
360
     * @Then I should be notified that it cannot be deleted
361
     */
362
    public function iShouldBeNotifiedThatItCannotBeDeleted()
363
    {
364
        $this->notificationChecker->checkNotification(
365
            'The channel cannot be deleted. At least one enabled channel is required.',
366
            NotificationType::failure()
367
        );
368
    }
369
370
    /**
371
     * @When I make it available in :locale
372
     */
373
    public function iMakeItAvailableIn($locale)
374
    {
375
        $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
376
377
        $currentPage->chooseLocale($locale);
378
    }
379
380
    /**
381
     * @Then the channel :channel should be available in :locale
382
     */
383
    public function theChannelShouldBeAvailableIn(ChannelInterface $channel, $locale)
384
    {
385
        $this->updatePage->open(['id' => $channel->getId()]);
386
387
        Assert::true($this->updatePage->isLocaleChosen($locale));
388
    }
389
390
    /**
391
     * @When I allow for paying in :currencyCode
392
     */
393
    public function iAllowToPayingForThisChannel($currencyCode)
394
    {
395
        $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
396
397
        $currentPage->chooseCurrency($currencyCode);
398
    }
399
400
    /**
401
     * @Then paying in :currencyCode should be possible for the :channel channel
402
     */
403
    public function payingInEuroShouldBePossibleForTheChannel($currencyCode, ChannelInterface $channel)
404
    {
405
        $this->updatePage->open(['id' => $channel->getId()]);
406
407
        Assert::true($this->updatePage->isCurrencyChosen($currencyCode));
408
    }
409
410
    /**
411
     * @When I select the :taxZone as default tax zone
412
     */
413
    public function iSelectDefaultTaxZone($taxZone)
414
    {
415
        $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
416
417
        $currentPage->chooseDefaultTaxZone($taxZone);
418
    }
419
420
    /**
421
     * @Given I remove its default tax zone
422
     */
423
    public function iRemoveItsDefaultTaxZone()
424
    {
425
        $this->updatePage->chooseDefaultTaxZone(null);
426
    }
427
428
    /**
429
     * @When I select the :taxCalculationStrategy as tax calculation strategy
430
     */
431
    public function iSelectTaxCalculationStrategy($taxCalculationStrategy)
432
    {
433
        $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
434
435
        $currentPage->chooseTaxCalculationStrategy($taxCalculationStrategy);
436
    }
437
438
    /**
439
     * @Then the default tax zone for the :channel channel should be :taxZone
440
     */
441
    public function theDefaultTaxZoneForTheChannelShouldBe(ChannelInterface $channel, $taxZone)
442
    {
443
        $this->updatePage->open(['id' => $channel->getId()]);
444
445
        Assert::true($this->updatePage->isDefaultTaxZoneChosen($taxZone));
446
    }
447
448
    /**
449
     * @Given channel :channel should not have default tax zone
450
     */
451
    public function channelShouldNotHaveDefaultTaxZone(ChannelInterface $channel)
452
    {
453
        $this->updatePage->open(['id' => $channel->getId()]);
454
455
        Assert::false($this->updatePage->isAnyDefaultTaxZoneChosen());
456
    }
457
458
    /**
459
     * @Then the tax calculation strategy for the :channel channel should be :taxCalculationStrategy
460
     */
461
    public function theTaxCalculationStrategyForTheChannelShouldBe(ChannelInterface $channel, $taxCalculationStrategy)
462
    {
463
        $this->updatePage->open(['id' => $channel->getId()]);
464
465
        Assert::true($this->updatePage->isTaxCalculationStrategyChosen($taxCalculationStrategy));
466
    }
467
468
    /**
469
     * @Then the base currency field should be disabled
470
     */
471
    public function theBaseCurrencyFieldShouldBeDisabled()
472
    {
473
        Assert::true($this->updatePage->isBaseCurrencyDisabled());
474
    }
475
476
    /**
477
     * @param ChannelInterface $channel
478
     * @param bool $state
479
     */
480
    private function assertChannelState(ChannelInterface $channel, $state)
481
    {
482
        $this->iWantToBrowseChannels();
483
484
        Assert::true($this->indexPage->isSingleResourceOnPage([
485
            'nameAndDescription' => $channel->getName(),
486
            'enabled' => $state,
487
        ]));
488
    }
489
}
490