Completed
Push — master ( b0156c...5bd0a6 )
by Kamil
17:10
created

iProceedLoggingAsGuestWithAsShippingCountry()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
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\Checkout\CheckoutAddressingStep;
16
use Sylius\Behat\Page\Checkout\CheckoutFinalizeStep;
17
use Sylius\Behat\Page\Checkout\CheckoutPaymentStep;
18
use Sylius\Behat\Page\Checkout\CheckoutSecurityStep;
19
use Sylius\Behat\Page\Checkout\CheckoutShippingStep;
20
use Sylius\Behat\Page\Checkout\CheckoutThankYouPage;
21
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
22
23
/**
24
 * @author Arkadiusz Krakowiak <[email protected]>
25
 */
26
final class CheckoutContext implements Context
27
{
28
    /**
29
     * @var SharedStorageInterface
30
     */
31
    private $sharedStorage;
32
33
    /**
34
     * @var CheckoutSecurityStep
35
     */
36
    private $checkoutSecurityStep;
37
38
    /**
39
     * @var CheckoutAddressingStep
40
     */
41
    private $checkoutAddressingStep;
42
43
    /**
44
     * @var CheckoutShippingStep
45
     */
46
    private $checkoutShippingStep;
47
48
    /**
49
     * @var CheckoutPaymentStep
50
     */
51
    private $checkoutPaymentStep;
52
53
    /**
54
     * @var CheckoutFinalizeStep
55
     */
56
    private $checkoutFinalizeStep;
57
58
    /**
59
     * @var CheckoutThankYouPage
60
     */
61
    private $checkoutThankYouPage;
62
63
    /**
64
     * @param SharedStorageInterface $sharedStorage
65
     * @param CheckoutSecurityStep $checkoutSecurityStep
66
     * @param CheckoutAddressingStep $checkoutAddressingStep
67
     * @param CheckoutShippingStep $checkoutShippingStep
68
     * @param CheckoutPaymentStep $checkoutPaymentStep
69
     * @param CheckoutFinalizeStep $checkoutFinalizeStep
70
     * @param CheckoutThankYouPage $checkoutThankYouPage
71
     */
72
    public function __construct(
73
        SharedStorageInterface $sharedStorage,
74
        CheckoutSecurityStep $checkoutSecurityStep,
75
        CheckoutAddressingStep $checkoutAddressingStep,
76
        CheckoutShippingStep $checkoutShippingStep,
77
        CheckoutPaymentStep $checkoutPaymentStep,
78
        CheckoutFinalizeStep $checkoutFinalizeStep,
79
        CheckoutThankYouPage $checkoutThankYouPage
80
    ) {
81
        $this->sharedStorage = $sharedStorage;
82
        $this->checkoutSecurityStep = $checkoutSecurityStep;
83
        $this->checkoutAddressingStep = $checkoutAddressingStep;
84
        $this->checkoutShippingStep = $checkoutShippingStep;
85
        $this->checkoutPaymentStep = $checkoutPaymentStep;
86
        $this->checkoutFinalizeStep = $checkoutFinalizeStep;
87
        $this->checkoutThankYouPage = $checkoutThankYouPage;
88
    }
89
90
    /**
91
     * @Given /^I proceed without selecting shipping address$/
92
     */
93
    public function iProceedWithoutSelectingShippingAddress()
94
    {
95
        $this->checkoutAddressingStep->open();
96
        $this->checkoutAddressingStep->continueCheckout();
97
    }
98
99
    /**
100
     * @When /^I proceed selecting "([^"]*)" as shipping country$/
101
     */
102
    public function iProceedSelectingShippingCountry($shippingCountry)
103
    {
104
        $this->checkoutAddressingStep->open();
105
        $this->checkoutAddressingStep->fillAddressingDetails([
106
            'firstName' => 'John',
107
            'lastName' => 'Doe',
108
            'country' => $shippingCountry ?: 'France',
109
            'street' => '0635 Myron Hollow Apt. 711',
110
            'city' => 'North Bridget',
111
            'postcode' => '93-554',
112
            'phoneNumber' => '321123456',
113
        ]);
114
        $this->checkoutAddressingStep->continueCheckout();
115
    }
116
117
    /**
118
     * @When /^I proceed selecting "([^"]*)" as shipping country with "([^"]*)" method$/
119
     */
120
    public function iProceedSelectingShippingCountryAndShippingMethod($shippingCountry, $shippingMethodName)
121
    {
122
        $this->iProceedSelectingShippingCountry($shippingCountry);
123
124
        $this->checkoutShippingStep->selectShippingMethod($shippingMethodName ?: 'Free');
125
        $this->checkoutShippingStep->continueCheckout();
126
    }
127
128
    /**
129
     * @When /^I proceed selecting "([^"]+)" shipping method$/
130
     * @Given /^I chose "([^"]*)" shipping method$/
131
     */
132
    public function iProceedSelectingShippingMethod($shippingMethodName)
133
    {
134
        $this->iProceedSelectingShippingCountryAndShippingMethod(null, $shippingMethodName);
135
    }
136
137
    /**
138
     * @When /^I choose "([^"]*)" payment method$/
139
     */
140
    public function iChoosePaymentMethod($paymentMethodName)
141
    {
142
        $this->checkoutPaymentStep->verify([]);
143
        $this->checkoutPaymentStep->selectPaymentMethod($paymentMethodName ?: 'Offline');
144
        $this->checkoutPaymentStep->continueCheckout();
145
    }
146
147
    /**
148
     * @When /^I proceed selecting "([^"]*)" as shipping country with "([^"]*)" payment method$/
149
     */
150
    public function iProceedSelectingShippingCountryAndPaymentMethod($shippingCountry, $paymentMethodName)
151
    {
152
        $this->iProceedSelectingShippingCountryAndShippingMethod($shippingCountry, null);
153
154
        $this->iChoosePaymentMethod($paymentMethodName);
155
    }
156
157
    /**
158
     * @When I proceed selecting :paymentMethodName payment method
159
     */
160
    public function iProceedSelectingOfflinePaymentMethod($paymentMethodName)
161
    {
162
        $this->iProceedSelectingShippingCountryAndPaymentMethod(null, $paymentMethodName);
163
    }
164
165
    /**
166
     * @When /^I change shipping method to "([^"]*)"$/
167
     */
168
    public function iChangeShippingMethod($shippingMethodName)
169
    {
170
        $this->checkoutShippingStep->open();
171
        $this->checkoutShippingStep->selectShippingMethod($shippingMethodName);
172
        $this->checkoutShippingStep->continueCheckout();
173
    }
174
175
    /**
176
     * @Given /^I proceed logging as "([^"]*)" with "([^"]*)" password$/
177
     */
178
    public function iProceedLoggingAs($login, $password)
179
    {
180
        $this->checkoutSecurityStep->open();
181
        $this->checkoutSecurityStep->logInAsExistingUser($login, $password);
182
183
        $this->checkoutAddressingStep->continueCheckout();
184
    }
185
186
    /**
187
     * @When /^I proceed as guest "([^"]*)" with "([^"]*)" as shipping country$/
188
     */
189
    public function iProceedLoggingAsGuestWithAsShippingCountry($email, $shippingCountry)
190
    {
191
        $this->checkoutSecurityStep->open();
192
        $this->checkoutSecurityStep->proceedAsGuest($email);
193
194
        $this->iProceedSelectingShippingCountry($shippingCountry);
195
    }
196
197
    /**
198
     * @When I confirm my order
199
     */
200
    public function iConfirmMyOrder()
201
    {
202
        $this->checkoutFinalizeStep->confirmOrder();
203
    }
204
205
    /**
206
     * @Then I should see the thank you page
207
     */
208
    public function iShouldSeeTheThankYouPage()
209
    {
210
        /** @var UserInterface $user */
211
        $user = $this->sharedStorage->getCurrentResource('user');
212
        $customer = $user->getCustomer();
213
214
        expect($this->checkoutThankYouPage->hasThankYouMessageFor($customer->getFullName()))->toBe(true);
215
    }
216
}
217