Completed
Push — locale-in-url ( 6d9eda...81052c )
by Kamil
57:16 queued 38:25
created

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