Completed
Push — master ( bcb54c...8151ca )
by Kamil
05:51 queued 19s
created

iShouldNotSeeShippingTotal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Context\Ui\Shop\Checkout;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\NotificationType;
18
use Sylius\Behat\Page\Shop\Checkout\CompletePageInterface;
19
use Sylius\Behat\Service\NotificationCheckerInterface;
20
use Sylius\Behat\Service\SharedStorageInterface;
21
use Sylius\Component\Core\Formatter\StringInflector;
22
use Sylius\Component\Core\Model\PaymentMethodInterface;
23
use Sylius\Component\Core\Model\ProductInterface;
24
use Sylius\Component\Core\Model\PromotionInterface;
25
use Sylius\Component\Core\Model\ShippingMethodInterface;
26
use Webmozart\Assert\Assert;
27
28
final class CheckoutCompleteContext implements Context
29
{
30
    /** @var SharedStorageInterface */
31
    private $sharedStorage;
32
33
    /** @var CompletePageInterface */
34
    private $completePage;
35
36
    /** @var NotificationCheckerInterface */
37
    private $notificationChecker;
38
39
    public function __construct(
40
        SharedStorageInterface $sharedStorage,
41
        CompletePageInterface $completePage,
42
        NotificationCheckerInterface $notificationChecker
43
    ) {
44
        $this->sharedStorage = $sharedStorage;
45
        $this->completePage = $completePage;
46
        $this->notificationChecker = $notificationChecker;
47
    }
48
49
    /**
50
     * @When I try to open checkout complete page
51
     * @When I want to complete checkout
52
     */
53
    public function iTryToOpenCheckoutCompletePage()
54
    {
55
        $this->completePage->tryToOpen();
56
    }
57
58
    /**
59
     * @When I decide to change the payment method
60
     */
61
    public function iGoToThePaymentStep()
62
    {
63
        $this->completePage->changePaymentMethod();
64
    }
65
66
    /**
67
     * @When /^I provide additional note like "([^"]+)"$/
68
     */
69
    public function iProvideAdditionalNotesLike($notes)
70
    {
71
        $this->sharedStorage->set('additional_note', $notes);
72
        $this->completePage->addNotes($notes);
73
    }
74
75
    /**
76
     * @When I return to the checkout summary step
77
     */
78
    public function iReturnToTheCheckoutSummaryStep()
79
    {
80
        $this->completePage->open();
81
    }
82
83
    /**
84
     * @Given I have confirmed order
85
     * @When I confirm my order
86
     */
87
    public function iConfirmMyOrder()
88
    {
89
        $this->completePage->confirmOrder();
90
    }
91
92
    /**
93
     * @Then I should be on the checkout complete step
94
     * @Then I should be on the checkout summary step
95
     */
96
    public function iShouldBeOnTheCheckoutCompleteStep()
97
    {
98
        $this->completePage->verify();
99
    }
100
101
    /**
102
     * @Then my order's shipping address should be to :fullName
103
     */
104
    public function iShouldSeeThisShippingAddressAsShippingAddress($fullName)
105
    {
106
        $address = $this->sharedStorage->get('shipping_address_' . StringInflector::nameToLowercaseCode($fullName));
107
108
        Assert::true($this->completePage->hasShippingAddress($address));
109
    }
110
111
    /**
112
     * @Then my order's billing address should be to :fullName
113
     */
114
    public function iShouldSeeThisBillingAddressAsBillingAddress($fullName)
115
    {
116
        $address = $this->sharedStorage->get('billing_address_' . StringInflector::nameToLowercaseCode($fullName));
117
118
        Assert::true($this->completePage->hasBillingAddress($address));
119
    }
120
121
    /**
122
     * @Then address to :fullName should be used for both shipping and billing of my order
123
     */
124
    public function iShouldSeeThisShippingAddressAsShippingAndBillingAddress($fullName)
125
    {
126
        $this->iShouldSeeThisShippingAddressAsShippingAddress($fullName);
127
        $this->iShouldSeeThisBillingAddressAsBillingAddress($fullName);
128
    }
129
130
    /**
131
     * @Then I should have :quantity :productName products in the cart
132
     */
133
    public function iShouldHaveProductsInTheCart($quantity, $productName)
134
    {
135
        Assert::true($this->completePage->hasItemWithProductAndQuantity($productName, $quantity));
136
    }
137
138
    /**
139
     * @Then my order shipping should be :price
140
     */
141
    public function myOrderShippingShouldBe(string $price): void
142
    {
143
        Assert::contains($this->completePage->getShippingTotal(), $price);
144
    }
145
146
    /**
147
     * @Then I should not see shipping total
148
     */
149
    public function iShouldNotSeeShippingTotal(): void
150
    {
151
        Assert::false($this->completePage->hasShippingTotal());
152
    }
153
154
    /**
155
     * @Then /^the ("[^"]+" product) should have unit price discounted by ("\$\d+")$/
156
     */
157
    public function theShouldHaveUnitPriceDiscountedFor(ProductInterface $product, $amount)
158
    {
159
        Assert::true($this->completePage->hasProductDiscountedUnitPriceBy($product, $amount));
160
    }
161
162
    /**
163
     * @Then /^my order total should be ("(?:\£|\$)\d+(?:\.\d+)?")$/
164
     */
165
    public function myOrderTotalShouldBe($total)
166
    {
167
        Assert::true($this->completePage->hasOrderTotal($total));
168
    }
169
170
    /**
171
     * @Then my order promotion total should be :promotionTotal
172
     */
173
    public function myOrderPromotionTotalShouldBe($promotionTotal)
174
    {
175
        Assert::true($this->completePage->hasPromotionTotal($promotionTotal));
176
    }
177
178
    /**
179
     * @Then :promotionName should be applied to my order
180
     */
181
    public function shouldBeAppliedToMyOrder($promotionName)
182
    {
183
        Assert::true($this->completePage->hasOrderPromotion($promotionName));
184
    }
185
186
    /**
187
     * @Then :promotionName should be applied to my order shipping
188
     */
189
    public function shouldBeAppliedToMyOrderShipping($promotionName)
190
    {
191
        Assert::true($this->completePage->hasShippingPromotion($promotionName));
192
    }
193
194
    /**
195
     * @Given my tax total should be :taxTotal
196
     */
197
    public function myTaxTotalShouldBe(string $taxTotal): void
198
    {
199
        Assert::same($this->completePage->getTaxTotal(), $taxTotal);
200
    }
201
202
    /**
203
     * @Then my order's shipping method should be :shippingMethod
204
     */
205
    public function myOrdersShippingMethodShouldBe(ShippingMethodInterface $shippingMethod)
206
    {
207
        Assert::true($this->completePage->hasShippingMethod($shippingMethod));
208
    }
209
210
    /**
211
     * @Then my order's payment method should be :paymentMethod
212
     */
213
    public function myOrdersPaymentMethodShouldBe(PaymentMethodInterface $paymentMethod)
214
    {
215
        Assert::same($this->completePage->getPaymentMethodName(), $paymentMethod->getName());
216
    }
217
218
    /**
219
     * @Then the :product product should have unit price :price
220
     */
221
    public function theProductShouldHaveUnitPrice(ProductInterface $product, $price)
222
    {
223
        Assert::true($this->completePage->hasProductUnitPrice($product, $price));
224
    }
225
226
    /**
227
     * @Then /^I should be notified that (this product) does not have sufficient stock$/
228
     */
229
    public function iShouldBeNotifiedThatThisProductDoesNotHaveSufficientStock(ProductInterface $product)
230
    {
231
        Assert::true($this->completePage->hasProductOutOfStockValidationMessage($product));
232
    }
233
234
    /**
235
     * @Then /^I should not be notified that (this product) does not have sufficient stock$/
236
     */
237
    public function iShouldNotBeNotifiedThatThisProductDoesNotHaveSufficientStock(ProductInterface $product)
238
    {
239
        Assert::false($this->completePage->hasProductOutOfStockValidationMessage($product));
240
    }
241
242
    /**
243
     * @Then my order's locale should be :locale
244
     */
245
    public function myOrderLocaleShouldBe($locale)
246
    {
247
        Assert::true($this->completePage->hasLocale($locale));
248
    }
249
250
    /**
251
     * @Then I should see :provinceName in the shipping address
252
     */
253
    public function iShouldSeeInTheShippingAddress($provinceName)
254
    {
255
        Assert::true($this->completePage->hasShippingProvinceName($provinceName));
256
    }
257
258
    /**
259
     * @Then I should see :provinceName in the billing address
260
     */
261
    public function iShouldSeeInTheBillingAddress($provinceName)
262
    {
263
        Assert::true($this->completePage->hasBillingProvinceName($provinceName));
264
    }
265
266
    /**
267
     * @Then I should not see any information about payment method
268
     */
269
    public function iShouldNotSeeAnyInformationAboutPaymentMethod()
270
    {
271
        Assert::false($this->completePage->hasPaymentMethod());
272
    }
273
274
    /**
275
     * @Then I should not be able to confirm order because products does not fit :shippingMethod requirements
276
     */
277
    public function iShouldNotBeAbleToConfirmOrderBecauseDoesNotBelongsToShippingCategory(ShippingMethodInterface $shippingMethod)
278
    {
279
        $this->completePage->confirmOrder();
280
281
        Assert::same(
282
            $this->completePage->getValidationErrors(),
283
            sprintf(
284
                'Product does not fit requirements for %s shipping method. Please reselect your shipping method.',
285
                $shippingMethod->getName()
286
            )
287
        );
288
    }
289
290
    /**
291
     * @Then /^I should be informed that (this promotion) is no longer applied$/
292
     */
293
    public function iShouldBeInformedThatMyPromotionIsNoLongerApplied(PromotionInterface $promotion)
294
    {
295
        $this->notificationChecker->checkNotification(
296
            sprintf('You are no longer eligible for this promotion %s.', $promotion->getName()),
297
            NotificationType::failure()
298
        );
299
    }
300
301
    /**
302
     * @Then /^I should be informed that (this payment method) has been disabled$/
303
     */
304
    public function iShouldBeInformedThatThisPaymentMethodHasBeenDisabled(PaymentMethodInterface $paymentMethod)
305
    {
306
        Assert::same(
307
            $this->completePage->getValidationErrors(),
308
            sprintf(
309
                'This payment method %s has been disabled. Please reselect your payment method.',
310
                $paymentMethod->getName()
311
            )
312
        );
313
    }
314
315
    /**
316
     * @Then /^I should be informed that (this product) has been disabled$/
317
     */
318
    public function iShouldBeInformedThatThisProductHasBeenDisabled(ProductInterface $product)
319
    {
320
        Assert::same(
321
            $this->completePage->getValidationErrors(),
322
            sprintf(
323
                'This product %s has been disabled.',
324
                $product->getName()
325
            )
326
        );
327
    }
328
329
    /**
330
     * @Then I should be informed that order total has been changed
331
     */
332
    public function iShouldBeInformedThatOrderTotalHasBeenChanged()
333
    {
334
        $this->notificationChecker->checkNotification(
335
            'Your order total has been changed, check your order information and confirm it again.',
336
            NotificationType::failure()
337
        );
338
    }
339
340
    /**
341
     * @Then /^(this promotion) should give "([^"]+)" discount on shipping$/
342
     */
343
    public function thisPromotionShouldGiveDiscountOnShipping(PromotionInterface $promotion, string $discount): void
344
    {
345
        Assert::true($this->completePage->hasShippingPromotionWithDiscount($promotion->getName(), $discount));
346
    }
347
}
348