Skip to content

Commit

Permalink
Merge pull request #11 from mbissonho/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mbissonho authored Jun 12, 2023
2 parents 79b79fe + 4b138cc commit bd7b01b
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Test/Integration/AbstractTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Mbissonho\BancoInter\Test\Integration;

use Magento\Framework\ObjectManagerInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order\Payment;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
use Mbissonho\BancoInter\Model\Ui\Boleto\ConfigProvider as BoletoConfigProvider;
use Magento\Sales\Model\OrderFactory;

abstract class AbstractTestCase extends TestCase
{

protected function getObjectManager(): ObjectManagerInterface
{
return Bootstrap::getObjectManager();
}

protected function getOrderWithBoletoPaymentMethod(): OrderInterface
{
$order = $this->getObjectManager()->get(OrderFactory::class)->create()
->loadByIncrementId('100000001');
/** @var Payment $payment */
$payment = $this->getObjectManager()->create(Payment::class);
$payment->setMethod(BoletoConfigProvider::CODE);;
$payment->setOrder($order);
$order->setPayment($payment);
$order->save();

return $order;
}

}
30 changes: 30 additions & 0 deletions Test/Integration/BoletoPaymentMethodTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Mbissonho\BancoInter\Test\Integration;

use Magento\Payment\Model\Method\Adapter as PaymentMethodAdapter;
use Magento\Quote\Api\Data\CartInterface;

class BoletoPaymentMethodTest extends AbstractTestCase
{

public function testBoletoMethodIsRegistered()
{
$boletoPaymentMethodAdapter = $this->getPaymentMethodAdapter();
$this->assertSame('mbissonho_bancointer_boleto', $boletoPaymentMethodAdapter->getCode());

/** @var CartInterface $quote */
$quote = $this->createMock(CartInterface::class);
$quote->method('getStoreId')->willReturn(0);
$this->assertFalse($boletoPaymentMethodAdapter->isAvailable($quote));
$this->assertTrue($boletoPaymentMethodAdapter->canUseCheckout());
}

private function getPaymentMethodAdapter(): PaymentMethodAdapter
{
return $this->getObjectManager()->get('BancoInterBoletoRemoteMethodAdapter');
}

}
20 changes: 20 additions & 0 deletions Test/Integration/Gateway/AbstractGatewayTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Mbissonho\BancoInter\Test\Integration\Gateway;

use Magento\Payment\Gateway\Data\PaymentDataObjectFactoryInterface;
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Mbissonho\BancoInter\Test\Integration\AbstractTestCase;

abstract class AbstractGatewayTestCase extends AbstractTestCase
{

protected function getNewPaymentDataObjectFromOrder(OrderInterface $order): PaymentDataObjectInterface
{
/** @var PaymentDataObjectFactoryInterface $paymentDataObjectFactory */
$paymentDataObjectFactory = $this->getObjectManager()->get(PaymentDataObjectFactoryInterface::class);
return $paymentDataObjectFactory->create($order->getPayment());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Mbissonho\BancoInter\Test\Integration\Gateway\Boleto\Response;

use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Mbissonho\BancoInter\Gateway\Boleto\Response\IssueResponseHandler;
use Mbissonho\BancoInter\Test\Integration\Gateway\AbstractGatewayTestCase;

class IssueResponseHandlerTest extends AbstractGatewayTestCase
{
private IssueResponseHandler $issueResponseHandler;

protected function setUp(): void
{
parent::setUp();
$this->issueResponseHandler = $this->getObjectManager()->get(IssueResponseHandler::class);
}

/**
* @magentoDataFixture Magento/Sales/_files/order.php
* @throws LocalizedException
*/
public function testThatValidGatewayResponseCausesCorrectEffects()
{
$order = $this->getOrderWithBoletoPaymentMethod();

$this->issueResponseHandler->handle(
[
'payment' => $this->getNewPaymentDataObjectFromOrder($order),
'stateObject' => new DataObject
],
[
'body' => json_encode([
"seuNumero" => "1234",
"nossoNumero" => "98754",
"codigoBarras" => "5555555555555555554",
"linhaDigitavel" => "444444444444444445",
]),
]
);

$payment = $order->getPayment();

self::assertEquals("98754", $payment->getTransactionId());
self::assertFalse($payment->getIsTransactionClosed());
}

}
12 changes: 12 additions & 0 deletions Test/Mftf/Page/AdminConfigPaymentMethodsPage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
<page name="AdminConfigPaymentMethodsPage" url="admin/system_config/edit/section/payment/" area="admin" module="Magento_Config">
<section name="BancoInterMbissonhoPaymentsConfigSection"/>
</page>
</pages>
3 changes: 3 additions & 0 deletions Test/Mftf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Functional Tests

The Functional Test Module for **Mbissonho BancoInter** module.
15 changes: 15 additions & 0 deletions Test/Mftf/Section/BancoInterMbissonhoPaymentsConfigSection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="BancoInterMbissonhoPaymentsConfigSection">
<element name="mbissonho_bancointer_payments_config_section_header"
type="text" selector="#payment_us_mbissonho_bancointer-head"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminConfigPaymentsSectionSeeMbissonhoBancoInterSectionTest">
<annotations>
<features value="Mbissonho_BancoInter"/>
<stories value="Payment methods"/>
</annotations>
<after>
<actionGroup ref="AdminLogoutActionGroup" stepKey="amOnLogoutPage"/>
</after>

<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin1"/>
<amOnPage url="{{AdminConfigPaymentMethodsPage.url}}" stepKey="navigateToConfigurationPage"/>
<waitForPageLoad stepKey="waitForPageLoad1"/>
<seeElement selector="{{BancoInterMbissonhoPaymentsConfigSection.mbissonho_bancointer_payments_config_section_header}}"
stepKey="seeSection"/>
</test>
</tests>

0 comments on commit bd7b01b

Please sign in to comment.