Completed
Push — master ( 71b70e...42cf72 )
by Kamil
19:08
created

iProceedWithoutSelectingShippingAddress()   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
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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
     * @When I proceed selecting :paymentMethodName payment method
92
     */
93
    public function iProceedSelectingOfflinePaymentMethod($paymentMethodName)
94
    {
95
        $this->proceedOrder(null, null, $paymentMethodName);
96
    }
97
98
    /**
99
     * @When /^I proceed selecting "([^"]+)" shipping method$/
100
     * @Given /^I chose "([^"]*)" shipping method$/
101
     */
102
    public function iProceedSelectingShippingMethod($shippingMethodName)
103
    {
104
        $this->proceedOrder(null, $shippingMethodName);
105
    }
106
107
    /**
108
     * @When /^I proceed selecting "([^"]*)" as shipping country with "([^"]*)" method$/
109
     */
110
    public function iProceedSelectingShippingCountryAndShippingMethod($shippingCountry, $shippingMethodName)
111
    {
112
        $this->proceedOrder($shippingCountry, $shippingMethodName);
113
    }
114
115
    /**
116
     * @When /^I proceed selecting "([^"]*)" as shipping country with "([^"]*)" payment method$/
117
     */
118
    public function iProceedSelectingShippingCountryAndPaymentMethod($shippingCountry, $paymentMethodName)
119
    {
120
        $this->proceedOrder($shippingCountry, null, $paymentMethodName);
121
    }
122
123
    /**
124
     * @When /^I change shipping method to "([^"]*)"$/
125
     */
126
    public function iChangeShippingMethod($shippingMethodName)
127
    {
128
        $this->checkoutShippingStep->open();
129
        $this->checkoutShippingStep->selectShippingMethod($shippingMethodName);
130
        $this->checkoutShippingStep->continueCheckout();
131
    }
132
133
    /**
134
     * @Given /^I proceed without selecting shipping address$/
135
     */
136
    public function iProceedWithoutSelectingShippingAddress()
137
    {
138
        $this->checkoutAddressingStep->open();
139
        $this->checkoutAddressingStep->continueCheckout();
140
    }
141
142
    /**
143
     * @Given /^I proceed logging as "([^"]*)" with "([^"]*)" password$/
144
     */
145
    public function iProceedLoggingAs($login, $password)
146
    {
147
        $this->checkoutSecurityStep->open();
148
        $this->checkoutSecurityStep->logInAsExistingUser($login, $password);
149
150
        $this->checkoutAddressingStep->continueCheckout();
151
    }
152
153
    /**
154
     * @When I confirm my order
155
     */
156
    public function iConfirmMyOrder()
157
    {
158
        $this->checkoutFinalizeStep->confirmOrder();
159
    }
160
161
    /**
162
     * @Then I should see the thank you page
163
     */
164
    public function iShouldSeeTheThankYouPage()
165
    {
166
        /** @var UserInterface $user */
167
        $user = $this->sharedStorage->getCurrentResource('user');
168
        $customer = $user->getCustomer();
169
170
        expect($this->checkoutThankYouPage->hasThankYouMessageFor($customer->getFullName()))->toBe(true);
171
    }
172
173
    /**
174
     * @param string|null $shippingCountry
175
     * @param string|null $shippingMethodName
176
     * @param string|null $paymentMethodName
177
     */
178
    private function proceedOrder($shippingCountry = null, $shippingMethodName = null, $paymentMethodName = null)
179
    {
180
        $this->checkoutAddressingStep->open();
181
        $this->checkoutAddressingStep->fillAddressingDetails([
182
            'firstName' => 'John',
183
            'lastName' => 'Doe',
184
            'country' => $shippingCountry ?: 'France',
185
            'street' => '0635 Myron Hollow Apt. 711',
186
            'city' => 'North Bridget',
187
            'postcode' => '93-554',
188
            'phoneNumber' => '321123456',
189
        ]);
190
        $this->checkoutAddressingStep->continueCheckout();
191
192
        $this->checkoutShippingStep->selectShippingMethod($shippingMethodName ?: 'Free');
193
        $this->checkoutShippingStep->continueCheckout();
194
195
        $this->checkoutPaymentStep->selectPaymentMethod($paymentMethodName ?: 'Offline');
196
        $this->checkoutPaymentStep->continueCheckout();
197
    }
198
}
199