Completed
Push — checkout-context-cleanup ( 3b30b9...1e6a42 )
by Kamil
18:57
created

iShouldBeAbleToGoToTheCompleteStepAgain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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 ShippingContext 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
     * @When I try to open checkout shipping page
57
     */
58
    public function iTryToOpenCheckoutShippingPage()
59
    {
60
        $this->selectShippingPage->tryToOpen();
61
    }
62
63
    /**
64
     * @Given I have selected :shippingMethod shipping method
65
     * @When I select :shippingMethod shipping method
66
     */
67
    public function iSelectShippingMethod($shippingMethod)
68
    {
69
        $this->selectShippingPage->selectShippingMethod($shippingMethod);
70
    }
71
72
    /**
73
     * @Then I should not be able to select :shippingMethodName shipping method
74
     */
75
    public function iShouldNotBeAbleToSelectShippingMethod($shippingMethodName)
76
    {
77
        Assert::false(in_array($shippingMethodName, $this->selectShippingPage->getShippingMethods(), true));
78
    }
79
80
    /**
81
     * @Then I should have :shippingMethodName shipping method available as the first choice
82
     */
83
    public function iShouldHaveShippingMethodAvailableAsFirstChoice($shippingMethodName)
84
    {
85
        $shippingMethods = $this->selectShippingPage->getShippingMethods();
86
        $firstShippingMethod = reset($shippingMethods);
87
88
        Assert::same($shippingMethodName, $firstShippingMethod);
89
    }
90
91
    /**
92
     * @Then I should have :shippingMethodName shipping method available as the last choice
93
     */
94
    public function iShouldHaveShippingMethodAvailableAsLastChoice($shippingMethodName)
95
    {
96
        $shippingMethods = $this->selectShippingPage->getShippingMethods();
97
        $lastShippingMethod = end($shippingMethods);
98
99
        Assert::same($shippingMethodName, $lastShippingMethod);
100
    }
101
102
    /**
103
     * @When /^I(?:| try to) complete the shipping step$/
104
     */
105
    public function iCompleteTheShippingStep()
106
    {
107
        $this->selectShippingPage->nextStep();
108
    }
109
110
    /**
111
     * @When I decide to change my address
112
     */
113
    public function iDecideToChangeMyAddress()
114
    {
115
        $this->selectShippingPage->changeAddress();
116
    }
117
118
    /**
119
     * @When I go back to shipping step of the checkout
120
     */
121
    public function iGoBackToShippingStepOfTheCheckout()
122
    {
123
        $this->selectShippingPage->open();
124
    }
125
126
    /**
127
     * @Then I should be on the checkout shipping step
128
     */
129
    public function iShouldBeOnTheCheckoutShippingStep()
130
    {
131
        Assert::true($this->selectShippingPage->isOpen());
132
    }
133
134
    /**
135
     * @Then I should be informed that my order cannot be shipped to this address
136
     */
137
    public function iShouldBeInformedThatMyOrderCannotBeShippedToThisAddress()
138
    {
139
        Assert::true($this->selectShippingPage->hasNoShippingMethodsMessage());
140
    }
141
142
    /**
143
     * @Then I should be able to go to the complete step again
144
     */
145
    public function iShouldBeAbleToGoToTheCompleteStepAgain()
146
    {
147
        $this->selectShippingPage->nextStep();
148
149
        Assert::true($this->completePage->isOpen());
150
    }
151
152
    /**
153
     * @Then I should be redirected to the shipping step
154
     */
155
    public function iShouldBeRedirectedToTheShippingStep()
156
    {
157
        Assert::true($this->selectShippingPage->isOpen());
158
    }
159
160
    /**
161
     * @Given I should be able to go to the payment step again
162
     */
163
    public function iShouldBeAbleToGoToThePaymentStepAgain()
164
    {
165
        $this->selectShippingPage->nextStep();
166
167
        Assert::true($this->selectPaymentPage->isOpen());
168
    }
169
170
    /**
171
     * @Given I should see shipping method :shippingMethodName with fee :fee
172
     */
173
    public function iShouldSeeShippingFee($shippingMethodName, $fee)
174
    {
175
        Assert::true($this->selectShippingPage->hasShippingMethodFee($shippingMethodName, $fee));
176
    }
177
178
    /**
179
     * @Then there should be information about no available shipping methods
180
     */
181
    public function thereShouldBeInformationAboutNoShippingMethodsAvailableForMyShippingAddress()
182
    {
183
        Assert::true($this->selectShippingPage->hasNoAvailableShippingMethodsWarning());
184
    }
185
186
    /**
187
     * @Then I should see :shippingMethodName shipping method
188
     */
189
    public function iShouldSeeShippingMethod($shippingMethodName)
190
    {
191
        Assert::true($this->selectShippingPage->hasShippingMethod($shippingMethodName));
192
    }
193
194
    /**
195
     * @Then I should not see :shippingMethodName shipping method
196
     */
197
    public function iShouldNotSeeShippingMethod($shippingMethodName)
198
    {
199
        Assert::false($this->selectShippingPage->hasShippingMethod($shippingMethodName));
200
    }
201
202
    /**
203
     * @Then I should be checking out as :email
204
     */
205
    public function iShouldBeCheckingOutAs($email)
206
    {
207
        Assert::same('Checking out as '.$email.'.', $this->selectShippingPage->getPurchaserEmail());
208
    }
209
}
210