Completed
Push — checkout-context-cleanup ( 1e6a42...9f1562 )
by Kamil
18:50
created

iShouldSeeShippingMethod()   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 1
1
<?php
2
3
namespace Sylius\Behat\Context\Ui\Shop\Checkout;
4
5
use Behat\Behat\Context\Context;
6
use Sylius\Behat\Page\Shop\Checkout\CompletePageInterface;
7
use Sylius\Behat\Page\Shop\Checkout\SelectPaymentPageInterface;
8
use Sylius\Behat\Page\Shop\Checkout\SelectShippingPageInterface;
9
use Webmozart\Assert\Assert;
10
11
/**
12
 * @author Kamil Kokot <[email protected]>
13
 */
14
final class CheckoutShippingContext implements Context
15
{
16
    /**
17
     * @var SelectShippingPageInterface
18
     */
19
    private $selectShippingPage;
20
21
    /**
22
     * @var SelectPaymentPageInterface
23
     */
24
    private $selectPaymentPage;
25
26
    /**
27
     * @var CompletePageInterface
28
     */
29
    private $completePage;
30
31
    /**
32
     * @param SelectShippingPageInterface $selectShippingPage
33
     * @param SelectPaymentPageInterface $selectPaymentPage
34
     * @param CompletePageInterface $completePage
35
     */
36
    public function __construct(
37
        SelectShippingPageInterface $selectShippingPage,
38
        SelectPaymentPageInterface $selectPaymentPage,
39
        CompletePageInterface $completePage
40
    ) {
41
        $this->selectShippingPage = $selectShippingPage;
42
        $this->selectPaymentPage = $selectPaymentPage;
43
        $this->completePage = $completePage;
44
    }
45
46
    /**
47
     * @Given I have proceeded selecting :shippingMethodName shipping method
48
     */
49
    public function iHaveProceededSelectingShippingMethod($shippingMethodName)
50
    {
51
        $this->iSelectShippingMethod($shippingMethodName);
52
        $this->selectShippingPage->nextStep();
53
    }
54
55
    /**
56
     * @Given I have selected :shippingMethod shipping method
57
     * @When I select :shippingMethod shipping method
58
     */
59
    public function iSelectShippingMethod($shippingMethod)
60
    {
61
        $this->selectShippingPage->selectShippingMethod($shippingMethod);
62
    }
63
64
    /**
65
     * @When I try to open checkout shipping page
66
     */
67
    public function iTryToOpenCheckoutShippingPage()
68
    {
69
        $this->selectShippingPage->tryToOpen();
70
    }
71
72
    /**
73
     * @When /^I(?:| try to) complete the shipping step$/
74
     */
75
    public function iCompleteTheShippingStep()
76
    {
77
        $this->selectShippingPage->nextStep();
78
    }
79
80
    /**
81
     * @When I decide to change my address
82
     */
83
    public function iDecideToChangeMyAddress()
84
    {
85
        $this->selectShippingPage->changeAddress();
86
    }
87
88
    /**
89
     * @When I go back to shipping step of the checkout
90
     */
91
    public function iGoBackToShippingStepOfTheCheckout()
92
    {
93
        $this->selectShippingPage->open();
94
    }
95
96
    /**
97
     * @Then I should not be able to select :shippingMethodName shipping method
98
     */
99
    public function iShouldNotBeAbleToSelectShippingMethod($shippingMethodName)
100
    {
101
        Assert::false(in_array($shippingMethodName, $this->selectShippingPage->getShippingMethods(), true));
102
    }
103
104
    /**
105
     * @Then I should have :shippingMethodName shipping method available as the first choice
106
     */
107
    public function iShouldHaveShippingMethodAvailableAsFirstChoice($shippingMethodName)
108
    {
109
        $shippingMethods = $this->selectShippingPage->getShippingMethods();
110
        $firstShippingMethod = reset($shippingMethods);
111
112
        Assert::same($shippingMethodName, $firstShippingMethod);
113
    }
114
115
    /**
116
     * @Then I should have :shippingMethodName shipping method available as the last choice
117
     */
118
    public function iShouldHaveShippingMethodAvailableAsLastChoice($shippingMethodName)
119
    {
120
        $shippingMethods = $this->selectShippingPage->getShippingMethods();
121
        $lastShippingMethod = end($shippingMethods);
122
123
        Assert::same($shippingMethodName, $lastShippingMethod);
124
    }
125
126
    /**
127
     * @Then I should be on the checkout shipping step
128
     * @Then I should be redirected to the shipping step
129
     */
130
    public function iShouldBeOnTheCheckoutShippingStep()
131
    {
132
        Assert::true($this->selectShippingPage->isOpen());
133
    }
134
135
    /**
136
     * @Then I should be informed that my order cannot be shipped to this address
137
     */
138
    public function iShouldBeInformedThatMyOrderCannotBeShippedToThisAddress()
139
    {
140
        Assert::true($this->selectShippingPage->hasNoShippingMethodsMessage());
141
    }
142
143
    /**
144
     * @Then I should be able to go to the complete step again
145
     */
146
    public function iShouldBeAbleToGoToTheCompleteStepAgain()
147
    {
148
        $this->selectShippingPage->nextStep();
149
150
        Assert::true($this->completePage->isOpen());
151
    }
152
153
    /**
154
     * @Then I should be able to go to the payment step again
155
     */
156
    public function iShouldBeAbleToGoToThePaymentStepAgain()
157
    {
158
        $this->selectShippingPage->nextStep();
159
160
        Assert::true($this->selectPaymentPage->isOpen());
161
    }
162
163
    /**
164
     * @Then I should see shipping method :shippingMethodName with fee :fee
165
     */
166
    public function iShouldSeeShippingFee($shippingMethodName, $fee)
167
    {
168
        Assert::true($this->selectShippingPage->hasShippingMethodFee($shippingMethodName, $fee));
169
    }
170
171
    /**
172
     * @Then there should be information about no available shipping methods
173
     */
174
    public function thereShouldBeInformationAboutNoShippingMethodsAvailableForMyShippingAddress()
175
    {
176
        Assert::true($this->selectShippingPage->hasNoAvailableShippingMethodsWarning());
177
    }
178
179
    /**
180
     * @Then I should see :shippingMethodName shipping method
181
     */
182
    public function iShouldSeeShippingMethod($shippingMethodName)
183
    {
184
        Assert::true($this->selectShippingPage->hasShippingMethod($shippingMethodName));
185
    }
186
187
    /**
188
     * @Then I should not see :shippingMethodName shipping method
189
     */
190
    public function iShouldNotSeeShippingMethod($shippingMethodName)
191
    {
192
        Assert::false($this->selectShippingPage->hasShippingMethod($shippingMethodName));
193
    }
194
195
    /**
196
     * @Then I should be checking out as :email
197
     */
198
    public function iShouldBeCheckingOutAs($email)
199
    {
200
        Assert::same('Checking out as '.$email.'.', $this->selectShippingPage->getPurchaserEmail());
201
    }
202
}
203