init
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CancelTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::actions_manage';
|
||||
$this->uri = 'backend/paypal/billing_agreement/cancel';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DeleteTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::actions_manage';
|
||||
$this->uri = 'backend/paypal/billing_agreement/delete';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class GridTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::billing_agreement_actions_view';
|
||||
$this->uri = 'backend/paypal/billing_agreement/grid';
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testAclHasAccess()
|
||||
{
|
||||
/** @var $session \Magento\Backend\Model\Session */
|
||||
Bootstrap::getObjectManager()->create(\Magento\Backend\Model\Session::class);
|
||||
|
||||
parent::testAclHasAccess();
|
||||
|
||||
$response = $this->getResponse();
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//button[@type="button" and @title="Reset Filter"]',
|
||||
$response->getBody()
|
||||
),
|
||||
"Response for billing agreement grid doesn't contain 'Reset Filter' button"
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id="billing_agreements"]',
|
||||
$response->getBody()
|
||||
),
|
||||
"Response for billing agreement grid doesn't contain grid"
|
||||
);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::billing_agreement_actions_view';
|
||||
$this->uri = 'backend/paypal/billing_agreement/index';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ViewTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::billing_agreement_actions_view';
|
||||
$this->uri = 'backend/paypal/billing_agreement/view';
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testAclHasAccess()
|
||||
{
|
||||
/** @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection $billingAgreementCollection */
|
||||
$billingAgreementCollection = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection::class
|
||||
);
|
||||
$agreementId = $billingAgreementCollection->getFirstItem()->getId();
|
||||
$this->uri = $this->uri . '/agreement/' . $agreementId;
|
||||
|
||||
parent::testAclHasAccess();
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//a[@name="billing_agreement_info"]',
|
||||
$this->getResponse()->getBody()
|
||||
),
|
||||
"Response for billing agreement info doesn't contain billing agreement info tab"
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//a[contains(text(), "customer@example.com")]',
|
||||
$this->getResponse()->getBody()
|
||||
),
|
||||
"Response for billing agreement info doesn't contain Customer info"
|
||||
);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Paypal\Controller\Adminhtml\Billing\Agreement
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class AgreementTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testCustomerGrid()
|
||||
{
|
||||
$this->dispatch('backend/paypal/billing_agreement/customergrid/id/1');
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//th[contains(@class,"col-reference_id")]',
|
||||
$this->getResponse()->getBody()
|
||||
),
|
||||
"Response for billing agreement orders doesn't contain billing agreement customers grid"
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//td[contains(text(), "REF-ID-TEST-678")]',
|
||||
$this->getResponse()->getBody()
|
||||
),
|
||||
"Response for billing agreement info doesn't contain reference ID"
|
||||
);
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Express;
|
||||
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Paypal\Model\Api\Nvp;
|
||||
use Magento\Paypal\Model\Api\Type\Factory as ApiFactory;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\OrderValidatorInterface;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\Sales\Model\Order\Payment\Transaction;
|
||||
use Magento\Sales\Model\Order\Validation\CanInvoice;
|
||||
use Magento\Sales\Model\ValidatorResultInterface;
|
||||
|
||||
/**
|
||||
* Makes a test of the payment authorization for Paypal Express when payment action is order.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class AuthorizationTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::authorization';
|
||||
$this->uri = 'backend/paypal/express/authorization';
|
||||
|
||||
parent::setUp();
|
||||
$this->createSharedInstances();
|
||||
}
|
||||
|
||||
/**
|
||||
* Negative scenario for controller calls.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNoOrderPassed()
|
||||
{
|
||||
$this->dispatch('backend/paypal/express/authorization');
|
||||
$this->assertRedirect($this->stringContains('backend/sales/order/index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of authorization of full order amount.
|
||||
*
|
||||
* @magentoConfigFixture current_store payment/paypal_express/active 1
|
||||
* @magentoConfigFixture current_store payment/paypal_express/payment_action Order
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_express_payment_action_order.php
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthorization()
|
||||
{
|
||||
/** @var Order $order */
|
||||
$order = $this->_objectManager->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
$orderValidator = $this->_objectManager->create(OrderValidatorInterface::class);
|
||||
|
||||
/** @var ValidatorResultInterface $validationResult */
|
||||
$validationResult = $orderValidator->validate($order, [CanInvoice::class]);
|
||||
$validationMessages = $validationResult->getMessages();
|
||||
|
||||
$this->assertCount(1, $validationMessages);
|
||||
$this->assertEquals(
|
||||
'An invoice cannot be created when none of authorization transactions available.',
|
||||
$validationMessages[0]
|
||||
);
|
||||
|
||||
/** @var RequestInterface $request */
|
||||
$request = $this->getRequest();
|
||||
$request->setParam('order_id', $order->getId());
|
||||
|
||||
$this->dispatch('backend/paypal/express/authorization');
|
||||
|
||||
$orderRepository = $this->_objectManager->get(OrderRepositoryInterface::class);
|
||||
$order = $orderRepository->get($order->getId());
|
||||
|
||||
/** @var Payment $payment */
|
||||
$payment = $order->getPayment();
|
||||
|
||||
/** @var ValidatorResultInterface $validationResult */
|
||||
$validationResult = $orderValidator->validate($order, [CanInvoice::class]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Transaction::class,
|
||||
$payment->getAuthorizationTransaction()
|
||||
);
|
||||
$this->assertEquals($order->getBaseGrandTotal(), $payment->getAmountAuthorized());
|
||||
$this->assertEmpty($validationResult->getMessages());
|
||||
$this->assertRedirect($this->stringContains('backend/sales/order/view/order_id/' . $order->getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates required shared instances.
|
||||
*/
|
||||
private function createSharedInstances()
|
||||
{
|
||||
$nvpMock = $this->getMockBuilder(Nvp::class)
|
||||
->setMethods(['call'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$nvpMock->method('call')
|
||||
->willReturn([]);
|
||||
|
||||
$apiFactoryMock = $this->getMockBuilder(ApiFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['create'])
|
||||
->getMock();
|
||||
|
||||
$apiFactoryMock->method('create')
|
||||
->with(Nvp::class)
|
||||
->willReturn($nvpMock);
|
||||
|
||||
$this->_objectManager->addSharedInstance($apiFactoryMock, ApiFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_objectManager->removeSharedInstance(ApiFactory::class);
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Paypal\Reports;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DetailsTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::paypal_settlement_reports_view';
|
||||
$this->uri = 'backend/paypal/paypal_reports/details';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Paypal\Reports;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FetchTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::fetch';
|
||||
$this->uri = 'backend/paypal/paypal_reports/fetch';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Paypal\Reports;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::paypal_settlement_reports_view';
|
||||
$this->uri = 'backend/paypal/paypal_reports/index';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Controller\Adminhtml\System;
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ConfigTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*
|
||||
* @dataProvider saveMerchantCountryDataProvider
|
||||
*
|
||||
* @param string $section
|
||||
* @param array $groups
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveMerchantCountry(string $section, array $groups): void
|
||||
{
|
||||
/** @var ScopeConfigInterface $scopeConfig */
|
||||
$scopeConfig = Bootstrap::getObjectManager()->get(ScopeConfigInterface::class);
|
||||
|
||||
$request = $this->getRequest();
|
||||
$request->setPostValue($groups)
|
||||
->setParam('section', $section)
|
||||
->setMethod(HttpRequest::METHOD_POST);
|
||||
|
||||
$this->dispatch('backend/admin/system_config/save');
|
||||
|
||||
$this->assertSessionMessages($this->equalTo(['You saved the configuration.']));
|
||||
|
||||
$this->assertEquals(
|
||||
'GB',
|
||||
$scopeConfig->getValue('paypal/general/merchant_country')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function saveMerchantCountryDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'section' => 'paypal',
|
||||
'groups' => [
|
||||
'groups' => [
|
||||
'general' => [
|
||||
'fields' => [
|
||||
'merchant_country' => ['value' => 'GB'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'section' => 'payment',
|
||||
'groups' => [
|
||||
'groups' => [
|
||||
'account' => [
|
||||
'fields' => [
|
||||
'merchant_country' => ['value' => 'GB'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Transparent;
|
||||
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Session\Generic;
|
||||
use Magento\Paypal\Model\Payflow\Transparent;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\PaymentMethodManagementInterface;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* Tests PayPal transparent response controller.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ResponseTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Tests storing payment information on backend from PayPal response.
|
||||
*
|
||||
* @throws NoSuchEntityException
|
||||
*
|
||||
* @magentoConfigFixture current_store payment/payflowpro/active 1
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
*/
|
||||
public function testStoringPaymentInformation()
|
||||
{
|
||||
$reservedOrderId = 'test01';
|
||||
$pnref = 'A10AAD866C87';
|
||||
$postData = [
|
||||
'EXPDATE' => '0321',
|
||||
'AMT' => '0.00',
|
||||
'RESPMSG' => 'Verified',
|
||||
'CVV2MATCH' => 'Y',
|
||||
'PNREF' => $pnref,
|
||||
'SECURETOKEN' => '3HYEHfG06skydAdBXbpIl8QJZ',
|
||||
'AVSDATA' => 'YNY',
|
||||
'RESULT' => '0',
|
||||
'IAVS' => 'N',
|
||||
'AVSADDR' => 'Y',
|
||||
'SECURETOKENID' => 'yqanLisRZbI0HAG8q3SbbKbhiwjNZAGf',
|
||||
];
|
||||
|
||||
$quote = $this->getQuote($reservedOrderId);
|
||||
$this->getRequest()->setPostValue($postData);
|
||||
$this->getRequest()->setMethod('POST');
|
||||
/** @var Session $checkoutSession */
|
||||
$checkoutSession = $this->_objectManager->get(Generic::class);
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
|
||||
$this->dispatch('backend/paypal/transparent/response');
|
||||
|
||||
/** @var PaymentMethodManagementInterface $paymentManagment */
|
||||
$paymentManagment = $this->_objectManager->get(PaymentMethodManagementInterface::class);
|
||||
$payment = $paymentManagment->get($quote->getId());
|
||||
|
||||
$this->assertEquals($pnref, $payment->getAdditionalInformation(Transparent::PNREF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote by reserved order ID.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return CartInterface
|
||||
*/
|
||||
private function getQuote(string $reservedOrderId): CartInterface
|
||||
{
|
||||
$searchCriteria = $this->_objectManager->get(SearchCriteriaBuilder::class)
|
||||
->addFilter('reserved_order_id', $reservedOrderId)
|
||||
->create();
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user