diff --git a/features/checkout/paying_for_order/changing_payment_method_after_order_confirmation.feature b/features/checkout/paying_for_order/changing_payment_method_after_order_confirmation.feature
index f49b46b5f0d8..fcd27b797871 100644
--- a/features/checkout/paying_for_order/changing_payment_method_after_order_confirmation.feature
+++ b/features/checkout/paying_for_order/changing_payment_method_after_order_confirmation.feature
@@ -11,34 +11,24 @@ Feature: Changing the method after order confirmation
And the store has a product "PHP T-Shirt" priced at "$19.99"
And the store ships everywhere for free
- @ui
+ @ui @api
Scenario: Retrying the payment with offline payment
Given I added product "PHP T-Shirt" to the cart
And I complete addressing step with email "john@example.com" and "United States" based billing address
+ And I have proceeded selecting "Free" shipping method
And I have proceeded selecting "Cash on delivery" payment method
And I have confirmed order
- When I go to the change payment method page
- And I try to pay with "Offline" payment method
- Then I should see the thank you page
+ When I change payment method to "Offline"
+ Then I should have chosen "Offline" payment method
- @ui
+ @ui @api
Scenario: Retrying the payment with offline payment works correctly together with inventory
Given there is 1 unit of product "PHP T-Shirt" available in the inventory
And this product is tracked by the inventory
And I added product "PHP T-Shirt" to the cart
And I complete addressing step with email "john@example.com" and "United States" based billing address
+ And I have proceeded selecting "Free" shipping method
And I have proceeded selecting "Cash on delivery" payment method
And I have confirmed order
- When I go to the change payment method page
- And I try to pay with "Offline" payment method
- Then I should see the thank you page
-
- @api
- Scenario: Changing the payment method for placed order
- Given I added product "PHP T-Shirt" to the cart
- When I complete addressing step with email "john@example.com" and "United States" based billing address
- And I select "Free" shipping method
- And I select "Cash on delivery" payment method
- And I confirm my order
- And I change payment method to "Offline"
- Then I should have chosen "Offline" payment method for my order
+ When I change payment method to "Offline"
+ Then I should have chosen "Offline" payment method
diff --git a/src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php b/src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
index 71855445b54b..ca0b9c1e584b 100644
--- a/src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
+++ b/src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
@@ -302,6 +302,7 @@ public function iProvideAdditionalNotesLike(string $notes): void
/**
* @Given I confirmed my order
* @When I confirm my order
+ * @When I have confirmed order
* @When I try to confirm my order
* @When /^the (?:visitor|customer) confirm his order$/
*/
@@ -340,6 +341,7 @@ public function iConfirmMyOrder(): void
* @Given /^the (?:visitor|customer) has proceeded ("[^"]+" shipping method)$/
* @When /^the visitor try to proceed with ("[^"]+" shipping method) in the customer cart$/
* @When I try to change shipping method to :shippingMethod
+ * @When I have proceeded selecting :shippingMethod shipping method
*/
public function iProceededWithShippingMethod(ShippingMethodInterface $shippingMethod): void
{
diff --git a/src/Sylius/Behat/Context/Api/Shop/OrderContext.php b/src/Sylius/Behat/Context/Api/Shop/OrderContext.php
index 2a412b01456a..a7a9300466f2 100644
--- a/src/Sylius/Behat/Context/Api/Shop/OrderContext.php
+++ b/src/Sylius/Behat/Context/Api/Shop/OrderContext.php
@@ -260,7 +260,7 @@ public function theShouldHaveUnitPriceDiscountedFor(ProductInterface $product, i
}
/**
- * @Then I should have chosen :paymentMethod payment method for my order
+ * @Then I should have chosen :paymentMethod payment method
*/
public function iShouldHaveChosenPaymentMethodForMyOrder(PaymentMethod $paymentMethod): void
{
diff --git a/src/Sylius/Behat/Context/Ui/Shop/Checkout/CheckoutOrderDetailsContext.php b/src/Sylius/Behat/Context/Ui/Shop/Checkout/CheckoutOrderDetailsContext.php
index b47671abcf7a..6a038e8c687b 100644
--- a/src/Sylius/Behat/Context/Ui/Shop/Checkout/CheckoutOrderDetailsContext.php
+++ b/src/Sylius/Behat/Context/Ui/Shop/Checkout/CheckoutOrderDetailsContext.php
@@ -15,6 +15,7 @@
use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Shop\Order\ShowPageInterface;
+use Sylius\Behat\Page\Shop\Order\ThankYouPageInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Webmozart\Assert\Assert;
@@ -23,15 +24,19 @@ final class CheckoutOrderDetailsContext implements Context
/** @var ShowPageInterface */
private $orderDetails;
- public function __construct(ShowPageInterface $orderDetails)
+ /** @var ThankYouPageInterface */
+ private $thankYouPage;
+
+ public function __construct(ShowPageInterface $orderDetails, ThankYouPageInterface $thankYouPage)
{
$this->orderDetails = $orderDetails;
+ $this->thankYouPage = $thankYouPage;
}
/**
* @When /^I want to browse order details for (this order)$/
*/
- public function iWantToBrowseOrderDetailsForThisOrder(OrderInterface $order)
+ public function iWantToBrowseOrderDetailsForThisOrder(OrderInterface $order): void
{
$this->orderDetails->open(['tokenValue' => $order->getTokenValue()]);
}
@@ -39,7 +44,7 @@ public function iWantToBrowseOrderDetailsForThisOrder(OrderInterface $order)
/**
* @When I try to pay with :paymentMethodName payment method
*/
- public function iChangePaymentMethodTo($paymentMethodName)
+ public function iChangePaymentMethodTo(string $paymentMethodName): void
{
$this->orderDetails->choosePaymentMethod($paymentMethodName);
$this->orderDetails->pay();
@@ -48,7 +53,7 @@ public function iChangePaymentMethodTo($paymentMethodName)
/**
* @Then I should be able to pay (again)
*/
- public function iShouldBeAbleToPay()
+ public function iShouldBeAbleToPay(): void
{
Assert::true($this->orderDetails->hasPayAction());
}
@@ -56,7 +61,7 @@ public function iShouldBeAbleToPay()
/**
* @Then I should not be able to pay (again)
*/
- public function iShouldNotBeAbleToPay()
+ public function iShouldNotBeAbleToPay(): void
{
Assert::false($this->orderDetails->hasPayAction());
}
@@ -68,4 +73,13 @@ public function iShouldSeeAsNumberOfItems(int $quantity): void
{
Assert::same($this->orderDetails->getAmountOfItems(), $quantity);
}
+
+ /**
+ * @Then I should have chosen :paymentMethodName payment method
+ */
+ public function iShouldHaveChosenPaymentMethod(string $paymentMethodName): void
+ {
+ $this->thankYouPage->goToTheChangePaymentMethodPage();
+ Assert::same($this->orderDetails->getChosenPaymentMethod(), $paymentMethodName);
+ }
}
diff --git a/src/Sylius/Behat/Context/Ui/Shop/Checkout/CheckoutThankYouContext.php b/src/Sylius/Behat/Context/Ui/Shop/Checkout/CheckoutThankYouContext.php
index 681916c7631d..bdc70fdc0460 100644
--- a/src/Sylius/Behat/Context/Ui/Shop/Checkout/CheckoutThankYouContext.php
+++ b/src/Sylius/Behat/Context/Ui/Shop/Checkout/CheckoutThankYouContext.php
@@ -15,6 +15,7 @@
use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Shop\Account\Order\ShowPageInterface;
+use Sylius\Behat\Page\Shop\Order\ShowPageInterface as OrderDetailsPage;
use Sylius\Behat\Page\Shop\Order\ThankYouPageInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
@@ -28,17 +29,22 @@ final class CheckoutThankYouContext implements Context
/** @var ShowPageInterface */
private $orderShowPage;
+ /** @var OrderDetailsPage */
+ private $orderDetails;
+
/** @var OrderRepositoryInterface */
private $orderRepository;
public function __construct(
ThankYouPageInterface $thankYouPage,
ShowPageInterface $orderShowPage,
- OrderRepositoryInterface $orderRepository
+ OrderRepositoryInterface $orderRepository,
+ OrderDetailsPage $orderDetails
) {
$this->thankYouPage = $thankYouPage;
$this->orderShowPage = $orderShowPage;
$this->orderRepository = $orderRepository;
+ $this->orderDetails = $orderDetails;
}
/**
@@ -57,6 +63,16 @@ public function iProceedToTheRegistration(): void
$this->thankYouPage->createAccount();
}
+ /**
+ * @When I change payment method to :paymentMethodName
+ */
+ public function iChoosePaymentMethod(string $paymentMethodName): void
+ {
+ $this->iGoToTheChangePaymentMethodPage();
+ $this->orderDetails->choosePaymentMethod($paymentMethodName);
+ $this->orderDetails->pay();
+ }
+
/**
* @Then I should be able to access this order's details
*/
diff --git a/src/Sylius/Behat/Page/Shop/Order/ShowPage.php b/src/Sylius/Behat/Page/Shop/Order/ShowPage.php
index 7c3879525a24..bd32808dd6ac 100644
--- a/src/Sylius/Behat/Page/Shop/Order/ShowPage.php
+++ b/src/Sylius/Behat/Page/Shop/Order/ShowPage.php
@@ -59,6 +59,19 @@ public function getAmountOfItems(): int
return count($paymentItems);
}
+ public function getChosenPaymentMethod(): string
+ {
+ $paymentItems = $this->getDocument()->findAll('css', '[data-test-payment-item]');
+
+ foreach ($paymentItems as $method) {
+ if ($method->find('css', '[data-test-payment-method-select]')->hasAttribute('checked')) {
+ return $method->find('css', 'a')->getText();
+ }
+ }
+
+ return '';
+ }
+
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
diff --git a/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php b/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php
index 185bea6a2fbd..e5b2df8b4fa6 100644
--- a/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php
+++ b/src/Sylius/Behat/Page/Shop/Order/ShowPageInterface.php
@@ -26,4 +26,6 @@ public function choosePaymentMethod(string $paymentMethodName): void;
public function getNotifications(): array;
public function getAmountOfItems(): int;
+
+ public function getChosenPaymentMethod(): string;
}
diff --git a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml
index 6cb827514e08..5f6f24747563 100644
--- a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml
+++ b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml
@@ -319,12 +319,14 @@
-
+
+
+