1 | <?php |
||
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 | |||
112 | Assert::same(reset($shippingMethods), $shippingMethodName); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @Then I should have :shippingMethodName shipping method available as the last choice |
||
117 | */ |
||
118 | public function iShouldHaveShippingMethodAvailableAsLastChoice($shippingMethodName) |
||
119 | { |
||
120 | $shippingMethods = $this->selectShippingPage->getShippingMethods(); |
||
121 | |||
122 | Assert::same(end($shippingMethods), $shippingMethodName); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * @Then I should be on the checkout shipping step |
||
127 | * @Then I should be redirected to the 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 able to go to the payment step again |
||
154 | */ |
||
155 | public function iShouldBeAbleToGoToThePaymentStepAgain() |
||
156 | { |
||
157 | $this->selectShippingPage->nextStep(); |
||
158 | |||
159 | Assert::true($this->selectPaymentPage->isOpen()); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * @Then I should see shipping method :shippingMethodName with fee :fee |
||
164 | */ |
||
165 | public function iShouldSeeShippingFee($shippingMethodName, $fee) |
||
166 | { |
||
167 | Assert::true($this->selectShippingPage->hasShippingMethodFee($shippingMethodName); |
||
|
|||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @Then there should be information about no available shipping methods |
||
172 | */ |
||
173 | public function thereShouldBeInformationAboutNoShippingMethodsAvailableForMyShippingAddress() |
||
174 | { |
||
175 | Assert::true($this->selectShippingPage->hasNoAvailableShippingMethodsWarning()); |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * @Then I should see :shippingMethodName shipping method |
||
180 | */ |
||
181 | public function iShouldSeeShippingMethod($shippingMethodName) |
||
182 | { |
||
183 | Assert::true($this->selectShippingPage->hasShippingMethod($shippingMethodName)); |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * @Then I should not see :shippingMethodName shipping method |
||
188 | */ |
||
189 | public function iShouldNotSeeShippingMethod($shippingMethodName) |
||
190 | { |
||
191 | Assert::false($this->selectShippingPage->hasShippingMethod($shippingMethodName)); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * @Then I should be checking out as :email |
||
196 | */ |
||
197 | public function iShouldBeCheckingOutAs($email) |
||
198 | { |
||
199 | Assert::same($this->selectShippingPage->getPurchaserEmail(), 'Checking out as '.$email.'.'); |
||
200 | } |
||
201 | } |
||
202 |