From c00a23a27e225a20a14727eb579f13f0fdacf6b3 Mon Sep 17 00:00:00 2001 From: Adam Kasperczak Date: Fri, 18 Jun 2021 08:45:51 +0200 Subject: [PATCH] Fix original payment method on refund page --- ...m_completed_payment_on_refund_page.feature | 24 +++++++ src/Resources/views/_paymentMethod.html.twig | 6 +- tests/Behat/Context/Setup/PaymentContext.php | 68 +++++++++++++++++++ tests/Behat/Context/Ui/RefundingContext.php | 8 +++ tests/Behat/Page/Admin/OrderRefundsPage.php | 6 ++ .../Page/Admin/OrderRefundsPageInterface.php | 2 + tests/Behat/Resources/services.xml | 5 ++ tests/Behat/Resources/suites.yml | 1 + 8 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 features/seeing_original_payment_method_from_completed_payment_on_refund_page.feature create mode 100644 tests/Behat/Context/Setup/PaymentContext.php diff --git a/features/seeing_original_payment_method_from_completed_payment_on_refund_page.feature b/features/seeing_original_payment_method_from_completed_payment_on_refund_page.feature new file mode 100644 index 00000000..c8f433bf --- /dev/null +++ b/features/seeing_original_payment_method_from_completed_payment_on_refund_page.feature @@ -0,0 +1,24 @@ +@refunds +Feature: Seeing an original payment method from completed payment on the refund page + In order to choose proper payment method while refunding + As an Administrator + I want to see the original payment method of completed payment + + Background: + Given the store operates on a single green channel in "United States" + And the store has a product "Mr. Meeseeks T-Shirt" priced at "$10.00" + And the store allows shipping with "Galaxy Post" + And the store allows paying with "Space money" + And the store also allows paying with "Mars money" + And there is a customer "morty.smith@look-at-me.com" that placed an order "#00000023" + And the customer bought 2 "Mr. Meeseeks T-Shirt" products + And the customer chose "Galaxy Post" shipping method to "United States" with "Space money" payment + And the payment of order "#00000023" failed + And the customer chose "Mars money" payment method + And this payment has been paid + And I am logged in as an administrator + + @ui + Scenario: Seeing original payment method of completed payment + When I want to refund some units of order "#00000023" + Then I should see original payment method "Mars money" diff --git a/src/Resources/views/_paymentMethod.html.twig b/src/Resources/views/_paymentMethod.html.twig index f601eb8d..3d66a3ea 100644 --- a/src/Resources/views/_paymentMethod.html.twig +++ b/src/Resources/views/_paymentMethod.html.twig @@ -1,6 +1,6 @@ {% if order.payments.first() %} - {% set original_payment_method = order.payments.first().method %} - + {% set completed = constant('Sylius\\Component\\Core\\Model\\PaymentInterface::STATE_COMPLETED') %} + {% set original_payment_method = order.lastPayment(completed).method %}
@@ -15,7 +15,7 @@ {% endfor %} - {{ 'sylius.ui.original_payment_method'|trans }}: {{ original_payment_method }} + {{ 'sylius.ui.original_payment_method'|trans }}: {{ original_payment_method }}
diff --git a/tests/Behat/Context/Setup/PaymentContext.php b/tests/Behat/Context/Setup/PaymentContext.php new file mode 100644 index 00000000..05e8fae4 --- /dev/null +++ b/tests/Behat/Context/Setup/PaymentContext.php @@ -0,0 +1,68 @@ +stateMachineFactory = $stateMachineFactory; + $this->sharedStorage = $sharedStorage; + } + + /** + * @Given the payment of order :order failed + */ + public function paymentOfOrderFailed(OrderInterface $order): void + { + $payment = $order->getLastPayment(); + $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH)->apply(PaymentTransitions::TRANSITION_FAIL); + } + + /** + * @Given /^the customer chose ("[^"]+" payment) method$/ + */ + public function theCustomerChosePaymentMethod(PaymentMethodInterface $paymentMethod): void + { + /** @var OrderInterface $order */ + $order = $this->sharedStorage->get('order'); + + $lastPayment = $order->getLastPayment(); + $lastPayment->setMethod($paymentMethod); + + $this->sharedStorage->set('payment', $lastPayment); + } + + /** + * @Given /^(this payment) has been paid$/ + */ + public function andThisPaymentHasBeenPaid(PaymentInterface $payment): void + { + $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH)->apply(PaymentTransitions::TRANSITION_COMPLETE); + } +} diff --git a/tests/Behat/Context/Ui/RefundingContext.php b/tests/Behat/Context/Ui/RefundingContext.php index 9b00df51..103c586e 100644 --- a/tests/Behat/Context/Ui/RefundingContext.php +++ b/tests/Behat/Context/Ui/RefundingContext.php @@ -369,6 +369,14 @@ public function emailToWithCreditMemoShouldNotBeSent(string $email): void } } + /** + * @Then I should see original payment method :paymentMethodName + */ + public function iShouldSeeOriginalPaymentMethod(string $paymentMethodName): void + { + Assert::same($this->orderRefundsPage->getOriginalPaymentMethodName(), sprintf('Original Payment Method: %s', $paymentMethodName)); + } + private function provideLongComment(): string { return 'Tu ne quaesieris scire nefas, quem mihi quem tibi finem di dederint, Leuconoe, nec Babylonios temptaris numeros. Ut melius quidquid erit pati. Seu plures hiemes sue tribuit Iuppiter ultimam. Qae nunc oppositis debilitat pumicibus mare Tyrrenum: sapias vina liques et spatio brevi. Spem longam resecens. Dum loquimur fugerit invida Aetas: CARPE DIEM, quam minimum credula postero.'; diff --git a/tests/Behat/Page/Admin/OrderRefundsPage.php b/tests/Behat/Page/Admin/OrderRefundsPage.php index 362eb588..3f098a10 100644 --- a/tests/Behat/Page/Admin/OrderRefundsPage.php +++ b/tests/Behat/Page/Admin/OrderRefundsPage.php @@ -154,9 +154,15 @@ public function isPaymentMethodSelected(string $paymentMethodName): bool return true; } + public function getOriginalPaymentMethodName(): string + { + return $this->getTextFromElement($this->getElement('original_payment_method')); + } + protected function getDefinedElements(): array { return [ + 'original_payment_method' => '#original-payment-method', 'payment_methods' => '#payment-methods', 'refunded_total' => '#refunded-total', ]; diff --git a/tests/Behat/Page/Admin/OrderRefundsPageInterface.php b/tests/Behat/Page/Admin/OrderRefundsPageInterface.php index 64a363a3..59f9e789 100644 --- a/tests/Behat/Page/Admin/OrderRefundsPageInterface.php +++ b/tests/Behat/Page/Admin/OrderRefundsPageInterface.php @@ -41,4 +41,6 @@ public function hasBackButton(): bool; public function canChoosePaymentMethod(): bool; public function isPaymentMethodVisible(string $paymentMethodName): bool; + + public function getOriginalPaymentMethodName(): string; } diff --git a/tests/Behat/Resources/services.xml b/tests/Behat/Resources/services.xml index af4f3d95..d9cae01a 100644 --- a/tests/Behat/Resources/services.xml +++ b/tests/Behat/Resources/services.xml @@ -85,6 +85,11 @@ + + + + + diff --git a/tests/Behat/Resources/suites.yml b/tests/Behat/Resources/suites.yml index 2eab07a6..0d05d209 100644 --- a/tests/Behat/Resources/suites.yml +++ b/tests/Behat/Resources/suites.yml @@ -41,6 +41,7 @@ default: - sylius.behat.context.ui.admin.managing_orders - Tests\Sylius\RefundPlugin\Behat\Context\Application\EmailsContext + - Tests\Sylius\RefundPlugin\Behat\Context\Setup\PaymentContext - Tests\Sylius\RefundPlugin\Behat\Context\Ui\CreditMemoContext - Tests\Sylius\RefundPlugin\Behat\Context\Ui\ManagingOrdersContext - Tests\Sylius\RefundPlugin\Behat\Context\Ui\RefundingContext