|
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 Sylius\Behat\Context\FeatureContext; |
|
15
|
|
|
use Sylius\Behat\Page\Product\ProductShowPage; |
|
16
|
|
|
use Sylius\Component\Core\Test\Services\SharedStorageInterface; |
|
17
|
|
|
use Sylius\Component\Product\Model\ProductInterface; |
|
18
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class CheckoutContext extends FeatureContext |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var SharedStorageInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $sharedStorage; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var RepositoryInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $productRepository; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var RepositoryInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
private $orderRepository; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param SharedStorageInterface $sharedStorage |
|
42
|
|
|
* @param RepositoryInterface $productRepository |
|
43
|
|
|
* @param RepositoryInterface $orderRepository |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct(SharedStorageInterface $sharedStorage, RepositoryInterface $productRepository, RepositoryInterface $orderRepository) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->sharedStorage = $sharedStorage; |
|
48
|
|
|
$this->productRepository = $productRepository; |
|
49
|
|
|
$this->orderRepository = $orderRepository; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @Given I added product :name to the cart |
|
54
|
|
|
* @When I add product :name to the cart |
|
55
|
|
|
*/ |
|
56
|
|
|
public function iAddProductToTheCart($name) |
|
57
|
|
|
{ |
|
58
|
|
|
$productShowPage = $this->openProductPage($name); |
|
59
|
|
|
$productShowPage->addToCart(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @When /^I add (\d+) products "([^"]*)" to the cart$/ |
|
64
|
|
|
*/ |
|
65
|
|
|
public function iAddProductsToTheCart($quantity, $name) |
|
66
|
|
|
{ |
|
67
|
|
|
$productShowPage = $this->openProductPage($name); |
|
68
|
|
|
$productShowPage->addToCartWithQuantity($quantity); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @When I proceed selecting :paymentMethodName payment method |
|
73
|
|
|
*/ |
|
74
|
|
|
public function iProceedSelectingOfflinePaymentMethod($paymentMethodName) |
|
75
|
|
|
{ |
|
76
|
|
|
$checkoutAddressingPage = $this->getPage('Checkout\CheckoutAddressingStep')->open(); |
|
77
|
|
|
$addressingDetails = array( |
|
78
|
|
|
'firstName' => 'John', |
|
79
|
|
|
'lastName' => 'Doe', |
|
80
|
|
|
'country' => 'France', |
|
81
|
|
|
'street' => '0635 Myron Hollow Apt. 711', |
|
82
|
|
|
'city' => 'North Bridget', |
|
83
|
|
|
'postcode' => '93-554', |
|
84
|
|
|
'phoneNumber' => '321123456' |
|
85
|
|
|
); |
|
86
|
|
|
$checkoutAddressingPage->fillAddressingDetails($addressingDetails); |
|
87
|
|
|
$checkoutAddressingPage->pressButton('Continue'); |
|
88
|
|
|
|
|
89
|
|
|
$checkoutShippingPage = $this->getPage('Checkout\CheckoutShippingStep'); |
|
90
|
|
|
$checkoutShippingPage->pressRadio('Free'); |
|
91
|
|
|
$checkoutShippingPage->pressButton('Continue'); |
|
92
|
|
|
|
|
93
|
|
|
$checkoutPaymentPage = $this->getPage('Checkout\CheckoutPaymentStep'); |
|
94
|
|
|
$checkoutPaymentPage->pressRadio($paymentMethodName); |
|
95
|
|
|
$checkoutPaymentPage->pressButton('Continue'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @When I confirm my order |
|
100
|
|
|
*/ |
|
101
|
|
|
public function iConfirmMyOrder() |
|
102
|
|
|
{ |
|
103
|
|
|
$checkoutFinalizePage = $this->getPage('Checkout\CheckoutFinalizeStep'); |
|
104
|
|
|
$checkoutFinalizePage->assertRoute(); |
|
105
|
|
|
$checkoutFinalizePage->clickLink('Place order'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @Then I should see the thank you page |
|
110
|
|
|
*/ |
|
111
|
|
|
public function iShouldSeeTheThankYouPage() |
|
112
|
|
|
{ |
|
113
|
|
|
$user = $this->sharedStorage->getCurrentResource('user'); |
|
114
|
|
|
$customer = $user->getCustomer(); |
|
115
|
|
|
$thankYouPage = $this->getPage('Checkout\CheckoutThankYouPage'); |
|
116
|
|
|
$thankYouPage->assertRoute(); |
|
117
|
|
|
$this->assertSession()->elementTextContains('css', '#thanks', sprintf('Thank you %s', $customer->getFullName())); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param $productName |
|
122
|
|
|
* |
|
123
|
|
|
* @return ProductShowPage |
|
124
|
|
|
* |
|
125
|
|
|
* @throws \Exception |
|
126
|
|
|
*/ |
|
127
|
|
|
private function openProductPage($productName) |
|
128
|
|
|
{ |
|
129
|
|
|
/** @var ProductInterface $product */ |
|
130
|
|
|
$product = $this->productRepository->findOneBy(array('name' => $productName)); |
|
131
|
|
|
if (null === $product) { |
|
132
|
|
|
throw new \Exception('Store has no product with name "'.$productName.'".'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return $this->getPage('Product\ProductShowPage')->openSpecificProductPage($product); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|