@@ -261,7 +261,7 @@ public function testCheckoutWithExistingPaymentMethod() {
261261 $ order = Order::load (1 );
262262 $ this ->assertEquals ('onsite ' , $ order ->get ('payment_gateway ' )->target_id );
263263 $ this ->assertEquals ('1 ' , $ order ->get ('payment_method ' )->target_id );
264-
264+ $ this -> assertFalse ( $ order -> isLocked ());
265265 // Verify that a payment was created.
266266 $ payment = Payment::load (1 );
267267 $ this ->assertNotNull ($ payment );
@@ -315,7 +315,7 @@ public function testCheckoutWithNewPaymentMethod() {
315315 $ payment_method = $ order ->get ('payment_method ' )->entity ;
316316 $ this ->assertEquals ('1881 ' , $ payment_method ->get ('card_number ' )->value );
317317 $ this ->assertEquals ('123 New York Drive ' , $ payment_method ->getBillingProfile ()->get ('address ' )->address_line1 );
318-
318+ $ this -> assertFalse ( $ order -> isLocked ());
319319 // Verify that a payment was created.
320320 $ payment = Payment::load (1 );
321321 $ this ->assertNotNull ($ payment );
@@ -354,6 +354,8 @@ public function testCheckoutWithDeclinedPaymentMethod() {
354354 $ this ->assertSession ()->pageTextContains ('We encountered an error processing your payment method. Please verify your details and try again. ' );
355355 $ this ->assertSession ()->addressEquals ('checkout/1/order_information ' );
356356
357+ $ order = Order::load (1 );
358+ $ this ->assertFalse ($ order ->isLocked ());
357359 // Verify a payment was not created.
358360 $ payment = Payment::load (1 );
359361 $ this ->assertNull ($ payment );
@@ -384,9 +386,63 @@ public function testCheckoutWithOffsiteRedirectPost() {
384386 $ this ->assertSession ()->pageTextContains ('123 New York Drive ' );
385387 $ this ->submitForm ([], 'Pay and complete purchase ' );
386388 $ this ->assertSession ()->pageTextContains ('Your order number is 1. You can view your order on your account page when logged in. ' );
389+
387390 $ order = Order::load (1 );
388391 $ this ->assertEquals ('offsite ' , $ order ->get ('payment_gateway ' )->target_id );
392+ $ this ->assertFalse ($ order ->isLocked ());
393+ // Verify that a payment was created.
394+ $ payment = Payment::load (1 );
395+ $ this ->assertNotNull ($ payment );
396+ $ this ->assertEquals ($ payment ->getAmount (), $ order ->getTotalPrice ());
397+ }
398+
399+ /**
400+ * Tests checkout with an off-site gateway (POST redirect method, manual).
401+ *
402+ * In this scenario the customer must click the submit button on the payment
403+ * page in order to proceed to the gateway.
404+ */
405+ public function testCheckoutWithOffsiteRedirectPostManual () {
406+ $ payment_gateway = PaymentGateway::load ('offsite ' );
407+ $ payment_gateway ->getPlugin ()->setConfiguration ([
408+ 'redirect_method ' => 'post_manual ' ,
409+ 'payment_method_types ' => ['credit_card ' ],
410+ ]);
411+ $ payment_gateway ->save ();
389412
413+ $ this ->drupalGet ($ this ->product ->toUrl ()->toString ());
414+ $ this ->submitForm ([], 'Add to cart ' );
415+ $ this ->drupalGet ('checkout/1 ' );
416+ $ radio_button = $ this ->getSession ()->getPage ()->findField ('Example ' );
417+ $ radio_button ->click ();
418+ $ this ->waitForAjaxToFinish ();
419+
420+ $ this ->submitForm ([
421+ 'payment_information[billing_information][address][0][address][given_name] ' => 'Johnny ' ,
422+ 'payment_information[billing_information][address][0][address][family_name] ' => 'Appleseed ' ,
423+ 'payment_information[billing_information][address][0][address][address_line1] ' => '123 New York Drive ' ,
424+ 'payment_information[billing_information][address][0][address][locality] ' => 'New York City ' ,
425+ 'payment_information[billing_information][address][0][address][administrative_area] ' => 'NY ' ,
426+ 'payment_information[billing_information][address][0][address][postal_code] ' => '10001 ' ,
427+ ], 'Continue to review ' );
428+ $ this ->assertSession ()->pageTextContains ('Payment information ' );
429+ $ this ->assertSession ()->pageTextContains ('Example ' );
430+ $ this ->assertSession ()->pageTextContains ('Johnny Appleseed ' );
431+ $ this ->assertSession ()->pageTextContains ('123 New York Drive ' );
432+ $ this ->submitForm ([], 'Pay and complete purchase ' );
433+
434+ $ this ->assertSession ()->addressEquals ('checkout/1/payment ' );
435+ $ order = Order::load (1 );
436+ $ this ->assertEquals ('offsite ' , $ order ->get ('payment_gateway ' )->target_id );
437+ $ this ->assertTrue ($ order ->isLocked ());
438+
439+ $ this ->submitForm ([], 'Proceed to Example ' );
440+ $ this ->assertSession ()->pageTextContains ('Your order number is 1. You can view your order on your account page when logged in. ' );
441+
442+ \Drupal::entityTypeManager ()->getStorage ('commerce_order ' )->resetCache (['1 ' ]);
443+ $ order = Order::load (1 );
444+ $ this ->assertEquals ('offsite ' , $ order ->get ('payment_gateway ' )->target_id );
445+ $ this ->assertFalse ($ order ->isLocked ());
390446 // Verify that a payment was created.
391447 $ payment = Payment::load (1 );
392448 $ this ->assertNotNull ($ payment );
@@ -431,9 +487,10 @@ public function testCheckoutWithOffsiteRedirectGet() {
431487 $ this ->assertSession ()->pageTextContains ('123 New York Drive ' );
432488 $ this ->submitForm ([], 'Pay and complete purchase ' );
433489 $ this ->assertSession ()->pageTextContains ('Your order number is 1. You can view your order on your account page when logged in. ' );
490+
434491 $ order = Order::load (1 );
435492 $ this ->assertEquals ('offsite ' , $ order ->get ('payment_gateway ' )->target_id );
436-
493+ $ this -> assertFalse ( $ order -> isLocked ());
437494 // Verify that a payment was created.
438495 $ payment = Payment::load (1 );
439496 $ this ->assertNotNull ($ payment );
@@ -477,6 +534,9 @@ public function testFailedCheckoutWithOffsiteRedirectGet() {
477534 $ this ->assertSession ()->pageTextContains ('We encountered an unexpected error processing your payment. Please try again later. ' );
478535 $ this ->assertSession ()->addressEquals ('checkout/1/order_information ' );
479536
537+ $ order = Order::load (1 );
538+ // @todo Fix order unlocking in this situation.
539+ // $this->assertFalse($order->isLocked());
480540 // Verify a payment was not created.
481541 $ payment = Payment::load (1 );
482542 $ this ->assertNull ($ payment );
@@ -508,9 +568,10 @@ public function testCheckoutWithManual() {
508568 $ this ->submitForm ([], 'Pay and complete purchase ' );
509569 $ this ->assertSession ()->pageTextContains ('Your order number is 1. You can view your order on your account page when logged in. ' );
510570 $ this ->assertSession ()->pageTextContains ('Sample payment instructions. ' );
571+
511572 $ order = Order::load (1 );
512573 $ this ->assertEquals ('manual ' , $ order ->get ('payment_gateway ' )->target_id );
513-
574+ $ this -> assertFalse ( $ order -> isLocked ());
514575 // Verify that a payment was created.
515576 $ payment = Payment::load (1 );
516577 $ this ->assertNotNull ($ payment );
0 commit comments