Skip to content

Commit

Permalink
PAYOSWXP-47: Add Unit Test: Unzer invoice purchase: if there is no co…
Browse files Browse the repository at this point in the history
…mpany name in config, paymentmethod should be hidden
  • Loading branch information
amirinterlutions authored and janteuber committed Mar 22, 2024
1 parent 5d5311f commit c6d55f7
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function hidePaymentMethods(
$page = $event->getPage();

$paymentMethods = $page->getPaymentMethods();
$paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInstallment::UUID);

if ($this->companyNameMissing($event->getSalesChannelContext(), PayonePayolutionInvoicingPaymentHandler::class)) {
$paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInvoicing::UUID);
Expand Down
158 changes: 158 additions & 0 deletions tests/EventListener/CheckoutConfirmPayolutionEventListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php

declare(strict_types=1);

namespace PayonePayment\EventListener;

use PayonePayment\Configuration\ConfigurationPrefixes;
use PayonePayment\Installer\ConfigInstaller;
use PayonePayment\PaymentHandler\PayonePayolutionDebitPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInstallmentPaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInvoicingPaymentHandler;
use PayonePayment\PaymentMethod\PayonePayolutionDebit;
use PayonePayment\PaymentMethod\PayonePayolutionInstallment;
use PayonePayment\PaymentMethod\PayonePayolutionInvoicing;
use PayonePayment\TestCaseBase\ConfigurationHelper;
use PayonePayment\TestCaseBase\PayoneTestBehavior;
use PHPUnit\Framework\TestCase;
use Shopware\Core\Checkout\Payment\PaymentMethodCollection;
use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPage;
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
use Shopware\Storefront\Page\Page;
use Symfony\Component\HttpFoundation\Request;

/**
* @covers \PayonePayment\EventListener\CheckoutConfirmPayolutionEventListener
*/
class CheckoutConfirmPayolutionEventListenerTest extends TestCase
{
use PayoneTestBehavior;
use ConfigurationHelper;

public function testItHidesPaymentMethodsOnCheckoutConfirmPage(): void
{
$page = new CheckoutConfirmPage();
$this->setPaymentMethods($page);

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

$event = new CheckoutConfirmPageLoadedEvent($page, $salesChannelContext, new Request());
$listener = $this->getContainer()->get(CheckoutConfirmPayolutionEventListener::class);

$listener->hidePaymentMethods($event);

static::assertSame(0, $event->getPage()->getPaymentMethods()->count());
}

public function testItHidesAnotherPaymentMethodsWithInvoicingOnCheckoutConfirmPage(): void
{
$page = new CheckoutConfirmPage();
$this->setPaymentMethods($page);

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

$this->setPayoneConfig(
$this->getContainer(),
ConfigInstaller::CONFIG_FIELD_PAYOLUTION_INVOICING_TRANSFER_COMPANY_DATA,
true
);

$this->setPayoneConfig(
$this->getContainer(),
ConfigurationPrefixes::CONFIGURATION_PREFIXES[PayonePayolutionInvoicingPaymentHandler::class] . 'CompanyName',
'the-company'
);

$event = new CheckoutConfirmPageLoadedEvent($page, $salesChannelContext, new Request());
$listener = $this->getContainer()->get(CheckoutConfirmPayolutionEventListener::class);

$listener->hidePaymentMethods($event);

static::assertSame(1, $event->getPage()->getPaymentMethods()->count());
static::assertSame(PayonePayolutionInvoicing::UUID, $event->getPage()->getPaymentMethods()->first()->getId());
}

public function testItHidesAnotherPaymentMethodsWithDebitOnCheckoutConfirmPage(): void
{
$page = new CheckoutConfirmPage();
$this->setPaymentMethods($page);

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

$this->setPayoneConfig(
$this->getContainer(),
ConfigInstaller::CONFIG_FIELD_PAYOLUTION_INVOICING_TRANSFER_COMPANY_DATA,
true
);

$this->setPayoneConfig(
$this->getContainer(),
ConfigurationPrefixes::CONFIGURATION_PREFIXES[PayonePayolutionDebitPaymentHandler::class] . 'CompanyName',
'the-company'
);

$event = new CheckoutConfirmPageLoadedEvent($page, $salesChannelContext, new Request());
$listener = $this->getContainer()->get(CheckoutConfirmPayolutionEventListener::class);

$listener->hidePaymentMethods($event);

static::assertSame(1, $event->getPage()->getPaymentMethods()->count());
static::assertSame(PayonePayolutionDebit::UUID, $event->getPage()->getPaymentMethods()->first()->getId());
}

public function testItHidesAnotherPaymentMethodsWithInstallmentOnCheckoutConfirmPage(): void
{
$page = new CheckoutConfirmPage();
$this->setPaymentMethods($page);

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

$this->setPayoneConfig(
$this->getContainer(),
ConfigInstaller::CONFIG_FIELD_PAYOLUTION_INVOICING_TRANSFER_COMPANY_DATA,
true
);

$this->setPayoneConfig(
$this->getContainer(),
ConfigurationPrefixes::CONFIGURATION_PREFIXES[PayonePayolutionInstallmentPaymentHandler::class] . 'CompanyName',
'the-company'
);

$event = new CheckoutConfirmPageLoadedEvent($page, $salesChannelContext, new Request());
$listener = $this->getContainer()->get(CheckoutConfirmPayolutionEventListener::class);

$listener->hidePaymentMethods($event);

static::assertSame(1, $event->getPage()->getPaymentMethods()->count());
static::assertSame(PayonePayolutionInstallment::UUID, $event->getPage()->getPaymentMethods()->first()->getId());
}

protected function setPaymentMethods(Page $page): void
{
$paymentMethod1 = new PaymentMethodEntity();
$paymentMethod2 = new PaymentMethodEntity();
$paymentMethod3 = new PaymentMethodEntity();
$paymentMethod4 = new PaymentMethodEntity();

$paymentMethod1->setId(PayonePayolutionInstallment::UUID);
$paymentMethod1->setHandlerIdentifier(PayonePayolutionInstallmentPaymentHandler::class);

$paymentMethod2->setId(PayonePayolutionInvoicing::UUID);
$paymentMethod2->setHandlerIdentifier(PayonePayolutionInvoicingPaymentHandler::class);

$paymentMethod3->setId(PayonePayolutionDebit::UUID);
$paymentMethod3->setHandlerIdentifier(PayonePayolutionDebitPaymentHandler::class);

$paymentMethod4->setId(PayonePayolutionInstallment::UUID);
$paymentMethod4->setHandlerIdentifier(PayonePayolutionInstallmentPaymentHandler::class);

$page->setPaymentMethods(new PaymentMethodCollection([
$paymentMethod1,
$paymentMethod2,
$paymentMethod3,
$paymentMethod4,
]));
}
}

0 comments on commit c6d55f7

Please sign in to comment.