Completed
Push — master ( 094334...0b6e60 )
by Kamil
17:47
created

iAddProductToTheCartSelectingVariant()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Behat\Page\Cart\CartSummaryPage;
16
use Sylius\Behat\Page\Product\ProductShowPage;
17
use Sylius\Component\Core\Model\ProductInterface;
18
19
/**
20
 * @author Mateusz Zalewski <[email protected]>
21
 */
22
final class CartContext implements Context
23
{
24
    /**
25
     * @var CartSummaryPage
26
     */
27
    private $cartSummaryPage;
28
29
    /**
30
     * @var ProductShowPage
31
     */
32
    private $productShowPage;
33
34
    /**
35
     * @param CartSummaryPage $cartSummaryPage
36
     * @param ProductShowPage $productShowPage
37
     */
38
    public function __construct(
39
        CartSummaryPage $cartSummaryPage,
40
        ProductShowPage $productShowPage
41
    ) {
42
        $this->cartSummaryPage = $cartSummaryPage;
43
        $this->productShowPage = $productShowPage;
44
    }
45
46
    /**
47
     * @Given I added product :product to the cart
48
     * @When I add product :product to the cart
49
     * @When I have product :product in the cart
50
     */
51
    public function iAddProductToTheCart(ProductInterface $product)
52
    {
53
        $this->productShowPage->open(['product' => $product]);
54
        $this->productShowPage->addToCart();
55
    }
56
57
    /**
58
     * @Given I added :variant variant of product :product to the cart
59
     * @When I add :variant variant of product :product to the cart
60
     * @When I have :variant variant of product :product in the cart
61
     */
62
    public function iAddProductToTheCartSelectingVariant($variant, ProductInterface $product)
63
    {
64
        $this->productShowPage->open(['product' => $product]);
65
        $this->productShowPage->addToCartWithVariant($variant);
66
    }
67
68
    /**
69
     * @Given I remove product :productName from the cart
70
     */
71
    public function iRemoveProductFromTheCart($productName)
72
    {
73
        $this->cartSummaryPage->open();
74
        $this->cartSummaryPage->removeProduct($productName);
75
    }
76
77
    /**
78
     * @Given I change :productName quantity to :quantity
79
     */
80
    public function iChangeQuantityTo($productName, $quantity)
81
    {
82
        $this->cartSummaryPage->open();
83
        $this->cartSummaryPage->changeQuantity($productName, $quantity);
84
    }
85
86
    /**
87
     * @When I add :quantity products :product to the cart
88
     */
89
    public function iAddProductsToTheCart(ProductInterface $product, $quantity)
90
    {
91
        $this->productShowPage->open(['product' => $product]);
92
        $this->productShowPage->addToCartWithQuantity($quantity);
93
    }
94
95
    /**
96
     * @Then my cart total should be :total
97
     */
98
    public function myCartTotalShouldBe($total)
99
    {
100
        $this->cartSummaryPage->open();
101
102
        expect($this->cartSummaryPage->getGrandTotal())->toBe($total);
103
    }
104
105
    /**
106
     * @Then my cart taxes should be :taxTotal
107
     */
108
    public function myCartTaxesShouldBe($taxTotal)
109
    {
110
        $this->cartSummaryPage->open();
111
112
        expect($this->cartSummaryPage->getTaxTotal())->toBe($taxTotal);
113
    }
114
115
    /**
116
     * @Then my cart shipping fee should be :shippingTotal
117
     */
118
    public function myCartShippingFeeShouldBe($shippingTotal)
119
    {
120
        $this->cartSummaryPage->open();
121
122
        expect($this->cartSummaryPage->getShippingTotal())->toBe($shippingTotal);
123
    }
124
}
125