@@ -32,6 +32,8 @@ class ReturnUrlTest extends TestCase
32
32
{
33
33
const LAST_REAL_ORDER_ID = '000000001 ' ;
34
34
35
+ const SILENT_POST_HASH = 'abcdfg ' ;
36
+
35
37
/**
36
38
* @var ReturnUrl
37
39
*/
@@ -142,7 +144,7 @@ protected function setUp(): void
142
144
143
145
$ this ->checkoutSession = $ this ->getMockBuilder (Session::class)
144
146
->disableOriginalConstructor ()
145
- ->setMethods (['getLastRealOrderId ' , 'getLastRealOrder ' , 'restoreQuote ' ])
147
+ ->setMethods (['setLastRealOrderId ' , 'getLastRealOrder ' , 'restoreQuote ' ])
146
148
->getMock ();
147
149
148
150
$ this ->paymentFailures = $ this ->getMockBuilder (PaymentFailuresInterface::class)
@@ -177,8 +179,15 @@ public function testExecuteAllowedOrderState($state)
177
179
$ this ->withLayout ();
178
180
$ this ->withOrder (self ::LAST_REAL_ORDER_ID , $ state );
179
181
180
- $ this ->checkoutSession ->method ('getLastRealOrderId ' )
181
- ->willReturn (self ::LAST_REAL_ORDER_ID );
182
+ $ this ->request ->method ('getParam ' )
183
+ ->willReturnMap ([
184
+ ['INVNUM ' , self ::LAST_REAL_ORDER_ID ],
185
+ ['USER2 ' , self ::SILENT_POST_HASH ],
186
+ ]);
187
+
188
+ $ this ->checkoutSession ->expects ($ this ->once ())
189
+ ->method ('setLastRealOrderId ' )
190
+ ->with (self ::LAST_REAL_ORDER_ID );
182
191
183
192
$ this ->block ->method ('setData ' )
184
193
->with ('goto_success_page ' , true )
@@ -202,6 +211,45 @@ public function allowedOrderStateDataProvider()
202
211
];
203
212
}
204
213
214
+ /**
215
+ * Checks a test case when silent post hash validation fails.
216
+ *
217
+ * @param string $requestHash
218
+ * @param string $orderHash
219
+ * @dataProvider invalidHashVariations
220
+ */
221
+ public function testFailedHashValidation (string $ requestHash , string $ orderHash )
222
+ {
223
+ $ this ->withLayout ();
224
+ $ this ->withOrder (self ::LAST_REAL_ORDER_ID , Order::STATE_PROCESSING , $ orderHash );
225
+
226
+ $ this ->request ->method ('getParam ' )
227
+ ->willReturnMap ([
228
+ ['INVNUM ' , self ::LAST_REAL_ORDER_ID ],
229
+ ['USER2 ' , $ requestHash ],
230
+ ]);
231
+
232
+ $ this ->checkoutSession ->expects ($ this ->never ())
233
+ ->method ('setLastRealOrderId ' )
234
+ ->with (self ::LAST_REAL_ORDER_ID );
235
+
236
+ $ this ->returnUrl ->execute ();
237
+ }
238
+
239
+ /**
240
+ * Gets list of allowed order states.
241
+ *
242
+ * @return array
243
+ */
244
+ public function invalidHashVariations ()
245
+ {
246
+ return [
247
+ ['requestHash ' => '' , 'orderHash ' => self ::SILENT_POST_HASH ],
248
+ ['requestHash ' => self ::SILENT_POST_HASH , 'orderHash ' => '' ],
249
+ ['requestHash ' => 'abcd ' , 'orderHash ' => 'dcba ' ],
250
+ ];
251
+ }
252
+
205
253
/**
206
254
* Checks a test case when action processes order with not allowed state.
207
255
*
@@ -218,8 +266,11 @@ public function testExecuteNotAllowedOrderState($state, $restoreQuote, $expected
218
266
$ this ->withCheckoutSession (self ::LAST_REAL_ORDER_ID , $ restoreQuote );
219
267
220
268
$ this ->request ->method ('getParam ' )
221
- ->with ('RESPMSG ' )
222
- ->willReturn ($ errMessage );
269
+ ->willReturnMap ([
270
+ ['RESPMSG ' , $ errMessage ],
271
+ ['INVNUM ' , self ::LAST_REAL_ORDER_ID ],
272
+ ['USER2 ' , self ::SILENT_POST_HASH ],
273
+ ]);
223
274
224
275
$ this ->payment ->method ('getMethod ' )
225
276
->willReturn (Config::METHOD_PAYFLOWLINK );
@@ -261,8 +312,14 @@ public function testCheckRejectByPaymentMethod()
261
312
$ this ->withLayout ();
262
313
$ this ->withOrder (self ::LAST_REAL_ORDER_ID , Order::STATE_NEW );
263
314
264
- $ this ->checkoutSession ->method ('getLastRealOrderId ' )
265
- ->willReturn (self ::LAST_REAL_ORDER_ID );
315
+ $ this ->checkoutSession ->expects ($ this ->once ())
316
+ ->method ('setLastRealOrderId ' )
317
+ ->with (self ::LAST_REAL_ORDER_ID );
318
+ $ this ->request ->method ('getParam ' )
319
+ ->willReturnMap ([
320
+ ['INVNUM ' , self ::LAST_REAL_ORDER_ID ],
321
+ ['USER2 ' , self ::SILENT_POST_HASH ],
322
+ ]);
266
323
267
324
$ this ->withBlockContent (false , 'Requested payment method does not match with order. ' );
268
325
@@ -285,8 +342,11 @@ public function testCheckXSSEscaped($errorMsg, $errorMsgEscaped)
285
342
$ this ->withCheckoutSession (self ::LAST_REAL_ORDER_ID , true );
286
343
287
344
$ this ->request ->method ('getParam ' )
288
- ->with ('RESPMSG ' )
289
- ->willReturn ($ errorMsg );
345
+ ->willReturnMap ([
346
+ ['RESPMSG ' , $ errorMsg ],
347
+ ['INVNUM ' , self ::LAST_REAL_ORDER_ID ],
348
+ ['USER2 ' , self ::SILENT_POST_HASH ],
349
+ ]);
290
350
291
351
$ this ->checkoutHelper ->method ('cancelCurrentOrder ' )
292
352
->with (self ::equalTo ($ errorMsgEscaped ));
@@ -323,8 +383,11 @@ public function testCheckAdvancedAcceptingByPaymentMethod()
323
383
$ this ->withCheckoutSession (self ::LAST_REAL_ORDER_ID , true );
324
384
325
385
$ this ->request ->method ('getParam ' )
326
- ->with ('RESPMSG ' )
327
- ->willReturn ('message ' );
386
+ ->willReturnMap ([
387
+ ['RESPMSG ' , 'message ' ],
388
+ ['INVNUM ' , self ::LAST_REAL_ORDER_ID ],
389
+ ['USER2 ' , self ::SILENT_POST_HASH ],
390
+ ]);
328
391
329
392
$ this ->withBlockContent ('paymentMethod ' , 'Your payment has been declined. Please try again. ' );
330
393
@@ -347,9 +410,10 @@ public function testCheckAdvancedAcceptingByPaymentMethod()
347
410
*
348
411
* @param string $incrementId
349
412
* @param string $state
413
+ * @param string $hash
350
414
* @return void
351
415
*/
352
- private function withOrder ($ incrementId , $ state )
416
+ private function withOrder ($ incrementId , $ state, $ hash = self :: SILENT_POST_HASH )
353
417
{
354
418
$ this ->orderFactory ->method ('create ' )
355
419
->willReturn ($ this ->order );
@@ -366,6 +430,8 @@ private function withOrder($incrementId, $state)
366
430
367
431
$ this ->order ->method ('getPayment ' )
368
432
->willReturn ($ this ->payment );
433
+ $ this ->payment ->method ('getAdditionalInformation ' )
434
+ ->willReturn ($ hash );
369
435
}
370
436
371
437
/**
@@ -390,8 +456,8 @@ private function withLayout()
390
456
*/
391
457
private function withCheckoutSession ($ orderId , $ restoreQuote )
392
458
{
393
- $ this ->checkoutSession ->method ('getLastRealOrderId ' )
394
- ->willReturn ($ orderId );
459
+ $ this ->checkoutSession ->method ('setLastRealOrderId ' )
460
+ ->with ($ orderId );
395
461
396
462
$ this ->checkoutSession ->method ('getLastRealOrder ' )
397
463
->willReturn ($ this ->order );
0 commit comments