Completed
Push — master ( b716f1...2f9340 )
by Kamil
18:43
created

CartContext::iRemoveProductFromTheCart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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 remove product :productName from the cart
59
     */
60
    public function iRemoveProductFromTheCart($productName)
61
    {
62
        $this->cartSummaryPage->open();
63
        $this->cartSummaryPage->removeProduct($productName);
64
    }
65
66
    /**
67
     * @Given I change :productName quantity to :quantity
68
     */
69
    public function iChangeQuantityTo($productName, $quantity)
70
    {
71
        $this->cartSummaryPage->open();
72
        $this->cartSummaryPage->changeQuantity($productName, $quantity);
73
    }
74
75
    /**
76
     * @When I add :quantity products :product to the cart
77
     */
78
    public function iAddProductsToTheCart(ProductInterface $product, $quantity)
79
    {
80
        $this->productShowPage->open(['product' => $product]);
81
        $this->productShowPage->addToCartWithQuantity($quantity);
82
    }
83
84
    /**
85
     * @Then my cart total should be :total
86
     */
87
    public function myCartTotalShouldBe($total)
88
    {
89
        $this->cartSummaryPage->open();
90
91
        expect($this->cartSummaryPage->getGrandTotal())->toBe($total);
92
    }
93
94
    /**
95
     * @Then my cart taxes should be :taxTotal
96
     */
97
    public function myCartTaxesShouldBe($taxTotal)
98
    {
99
        $this->cartSummaryPage->open();
100
101
        expect($this->cartSummaryPage->getTaxTotal())->toBe($taxTotal);
102
    }
103
104
    /**
105
     * @Then my cart shipping fee should be :shippingTotal
106
     */
107
    public function myCartShippingFeeShouldBe($shippingTotal)
108
    {
109
        $this->cartSummaryPage->open();
110
111
        expect($this->cartSummaryPage->getShippingTotal())->toBe($shippingTotal);
112
    }
113
}
114