ltsecurityinc安防产品在线商城代码
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Adminhtml\Billing\Agreement\View\Tab;
|
||||
|
||||
class InfoTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testCustomerGridAction()
|
||||
{
|
||||
/** @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection $billingAgreementCollection */
|
||||
$billingAgreementCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection::class
|
||||
)->load();
|
||||
$agreementId = $billingAgreementCollection->getFirstItem()->getId();
|
||||
$this->dispatch('backend/paypal/billing_agreement/view/agreement/' . $agreementId);
|
||||
|
||||
$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'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Test for \Magento\Paypal\Block\Billing\Agreement\View
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Billing\Agreement;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class ViewTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/** @var \Magento\Paypal\Block\Billing\Agreement\View */
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_block = Bootstrap::getObjectManager()->create(\Magento\Paypal\Block\Billing\Agreement\View::class);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting orders associated with specified billing agreement.
|
||||
*
|
||||
* Create two identical orders, associate one of them with billing agreement and invoke testGetRelatedOrders()
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetRelatedOrders()
|
||||
{
|
||||
/** Customer ID declared in the fixture */
|
||||
$customerId = 1;
|
||||
/** Assign first order to the active customer */
|
||||
/** @var \Magento\Sales\Model\Order $orderA */
|
||||
$orderA = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$orderA->loadByIncrementId('100000001');
|
||||
$orderA->setCustomerIsGuest(false)->setCustomerId($customerId)->save();
|
||||
/** @var \Magento\Customer\Model\Session $customerSession */
|
||||
$customerSession = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Session::class);
|
||||
$customerSession->setCustomerId($customerId);
|
||||
|
||||
/** Assign second order to the active customer */
|
||||
$orderB = clone $orderA;
|
||||
$orderB->setId(
|
||||
null
|
||||
)->setIncrementId(
|
||||
'100000002'
|
||||
)->setCustomerIsGuest(
|
||||
false
|
||||
)->setCustomerId(
|
||||
$customerId
|
||||
)->save();
|
||||
|
||||
/** @var \Magento\Customer\Model\Session $customerSession */
|
||||
$customerSession = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Session::class);
|
||||
$customerSession->setCustomerId($customerId);
|
||||
|
||||
/** @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection $billingAgreementCollection */
|
||||
$billingAgreementCollection = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection::class
|
||||
);
|
||||
/** @var \Magento\Paypal\Model\Billing\Agreement $billingAgreement */
|
||||
$billingAgreement = $billingAgreementCollection->getFirstItem();
|
||||
$billingAgreement->addOrderRelation($orderA->getId())->save();
|
||||
|
||||
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
$registry->register('current_billing_agreement', $billingAgreement);
|
||||
|
||||
$relatedOrders = $this->_block->getRelatedOrders();
|
||||
$this->assertEquals(1, $relatedOrders->count(), "Only one order must be returned.");
|
||||
$this->assertEquals(
|
||||
$orderA->getId(),
|
||||
$relatedOrders->getFirstItem()->getId(),
|
||||
"Invalid order returned as associated with billing agreement."
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Bml;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class BannersTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @param int $publisherId
|
||||
* @param int $display
|
||||
* @param int $position
|
||||
* @param int $configPosition
|
||||
* @param bool $isEmptyHtml
|
||||
* @param string $methodWppBml
|
||||
* @param string $methodWppPeBml
|
||||
* @dataProvider toHtmlDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testToHtml(
|
||||
$publisherId,
|
||||
$display,
|
||||
$position,
|
||||
$configPosition,
|
||||
$isEmptyHtml,
|
||||
$methodWppBml,
|
||||
$methodWppPeBml
|
||||
) {
|
||||
/** @var \Magento\Paypal\Model\Config|\PHPUnit\Framework\MockObject\MockObject $paypalConfig */
|
||||
$paypalConfig = $this->createMock(\Magento\Paypal\Model\Config::class);
|
||||
$paypalConfig->expects($this->any())->method('getBmlPublisherId')->willReturn($publisherId);
|
||||
$paypalConfig->expects($this->any())->method('getBmlDisplay')->willReturn($display);
|
||||
$paypalConfig->expects($this->any())->method('getBmlPosition')->willReturn($configPosition);
|
||||
|
||||
$paypalConfig->expects($this->any())
|
||||
->method('isMethodAvailable')
|
||||
->willReturnMap(
|
||||
[
|
||||
[
|
||||
$methodWppBml,
|
||||
true,
|
||||
],
|
||||
[
|
||||
$methodWppPeBml,
|
||||
true,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
/** @var \Magento\Framework\View\LayoutInterface $layout */
|
||||
$layout = Bootstrap::getObjectManager()->get(\Magento\Framework\View\LayoutInterface::class);
|
||||
$block = $layout->createBlock(
|
||||
\Magento\Paypal\Block\Bml\Banners::class,
|
||||
'',
|
||||
[
|
||||
'paypalConfig' => $paypalConfig,
|
||||
'data' => ['position' => $position]
|
||||
]
|
||||
);
|
||||
$block->setTemplate('bml.phtml');
|
||||
$html = $block->toHtml();
|
||||
|
||||
if ($isEmptyHtml) {
|
||||
$this->assertEmpty($html);
|
||||
} else {
|
||||
$this->assertStringContainsString('data-pp-pubid="' . $block->getPublisherId() . '"', $html);
|
||||
$this->assertStringContainsString('data-pp-placementtype="' . $block->getSize() . '"', $html);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toHtmlDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'publisherId' => 1,
|
||||
'display' => 1,
|
||||
'position' => 100,
|
||||
'configPosition' => 100,
|
||||
'isEmptyHtml' => false,
|
||||
'methodWppBml' => 'paypal_express_bml',
|
||||
'methodWppPeBml' => 'payflow_express_bml',
|
||||
],
|
||||
[
|
||||
'publisherId' => 0,
|
||||
'display' => 1,
|
||||
'position' => 100,
|
||||
'configPosition' => 100,
|
||||
'isEmptyHtml' => true,
|
||||
'methodWppBml' => 'paypal_express_bml',
|
||||
'methodWppPeBml' => 'payflow_express_bml',
|
||||
],
|
||||
[
|
||||
'publisherId' => 1,
|
||||
'display' => 0,
|
||||
'position' => 100,
|
||||
'configPosition' => 100,
|
||||
'isEmptyHtml' => true,
|
||||
'methodWppBml' => 'paypal_express_bml',
|
||||
'methodWppPeBml' => 'payflow_express_bml',
|
||||
],
|
||||
[
|
||||
'publisherId' => 1,
|
||||
'display' => 0,
|
||||
'position' => 10,
|
||||
'configPosition' => 100,
|
||||
'isEmptyHtml' => true,
|
||||
'methodWppBml' => 'paypal_express_bml',
|
||||
'methodWppPeBml' => 'payflow_express_bml',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Express\Review;
|
||||
|
||||
use Magento\Customer\Model\Context;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class BillingTest
|
||||
*/
|
||||
class BillingTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Paypal\Block\Express\Review\Billing */
|
||||
protected $_block;
|
||||
|
||||
/** @var \Magento\Customer\Api\AddressRepositoryInterface */
|
||||
protected $_addressRepository;
|
||||
|
||||
/** @var \Magento\Quote\Model\Quote\AddressFactory */
|
||||
protected $_quoteAddressFactory;
|
||||
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface */
|
||||
protected $_customerRepository;
|
||||
|
||||
const FIXTURE_CUSTOMER_ID = 1;
|
||||
|
||||
const FIXTURE_ADDRESS_ID = 1;
|
||||
|
||||
const SAMPLE_FIRST_NAME = 'UpdatedFirstName';
|
||||
|
||||
const SAMPLE_LAST_NAME = 'UpdatedLastName';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->_customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
|
||||
$customer = $this->_customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
|
||||
|
||||
$customerSession = $objectManager->get(\Magento\Customer\Model\Session::class);
|
||||
$customerSession->setCustomerData($customer);
|
||||
|
||||
$this->_addressRepository = $objectManager->get(\Magento\Customer\Api\AddressRepositoryInterface::class);
|
||||
//fetch sample address
|
||||
$address = $this->_addressRepository->getById(self::FIXTURE_ADDRESS_ID);
|
||||
|
||||
/** @var \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection */
|
||||
$quoteCollection = $objectManager->get(\Magento\Quote\Model\ResourceModel\Quote\Collection::class);
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = $quoteCollection->getLastItem();
|
||||
$quote->setCustomer($customer);
|
||||
/** @var $quoteAddressFactory \Magento\Quote\Model\Quote\AddressFactory */
|
||||
$this->_quoteAddressFactory = $objectManager->get(\Magento\Quote\Model\Quote\AddressFactory::class);
|
||||
$billingAddress = $this->_quoteAddressFactory->create()->importCustomerAddressData($address);
|
||||
$quote->setBillingAddress($billingAddress);
|
||||
$quote->save();
|
||||
|
||||
/** @var \Magento\Checkout\Model\Session $checkoutSession */
|
||||
$checkoutSession = $objectManager->get(\Magento\Checkout\Model\Session::class);
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
$checkoutSession->setLoadInactive(true);
|
||||
|
||||
$objectManager->get(\Magento\Framework\App\Http\Context::class)
|
||||
->setValue(Context::CONTEXT_AUTH, true, false);
|
||||
$this->_block = $objectManager->get(\Magento\Framework\View\LayoutInterface::class)
|
||||
->createBlock(
|
||||
\Magento\Paypal\Block\Express\Review\Billing::class,
|
||||
'',
|
||||
['customerSession' => $customerSession, 'resourceSession' => $checkoutSession]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_product_and_payment.php
|
||||
*/
|
||||
public function testGetAddress()
|
||||
{
|
||||
$addressFromFixture = $this->_addressRepository->getById(self::FIXTURE_ADDRESS_ID);
|
||||
$address = $this->_block->getAddress();
|
||||
$this->assertEquals($addressFromFixture->getFirstname(), $address->getFirstname());
|
||||
$this->assertEquals($addressFromFixture->getLastname(), $address->getLastname());
|
||||
$this->assertEquals($addressFromFixture->getCustomerId(), $address->getCustomerId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_product_and_payment.php
|
||||
*/
|
||||
public function testGetAddressNotSetInQuote()
|
||||
{
|
||||
$this->_updateQuoteCustomerName();
|
||||
$address = $this->_block->getAddress();
|
||||
//Make sure the data from sample address was set correctly to the block from customer
|
||||
$this->assertEquals(self::SAMPLE_FIRST_NAME, $address->getFirstname());
|
||||
$this->assertEquals(self::SAMPLE_LAST_NAME, $address->getLastname());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_product_and_payment.php
|
||||
*/
|
||||
public function testGetFirstNameAndLastName()
|
||||
{
|
||||
$this->_updateQuoteCustomerName();
|
||||
//Make sure the data from sample address was set correctly to the block from customer
|
||||
$this->assertEquals(self::SAMPLE_FIRST_NAME, $this->_block->getFirstname());
|
||||
$this->assertEquals(self::SAMPLE_LAST_NAME, $this->_block->getLastname());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Customer name in Quote
|
||||
*/
|
||||
protected function _updateQuoteCustomerName()
|
||||
{
|
||||
/** @var $emptyAddress \Magento\Quote\Model\Quote\Address */
|
||||
$emptyAddress = $this->_quoteAddressFactory->create();
|
||||
$emptyAddress->setFirstname(null);
|
||||
$emptyAddress->setLastname(null);
|
||||
$this->_block->getQuote()->setBillingAddress($emptyAddress);
|
||||
$customer = $this->_customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
|
||||
$customer->setFirstname(
|
||||
self::SAMPLE_FIRST_NAME
|
||||
)->setLastname(
|
||||
self::SAMPLE_LAST_NAME
|
||||
);
|
||||
$this->_block->getQuote()->setCustomer($customer);
|
||||
$this->_block->getQuote()->save();
|
||||
|
||||
$this->assertEquals(self::SAMPLE_FIRST_NAME, $this->_block->getFirstname());
|
||||
$this->assertEquals(self::SAMPLE_LAST_NAME, $this->_block->getLastname());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Paypal\Block\Express\Review
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Express;
|
||||
|
||||
class ReviewTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
*/
|
||||
public function testRenderAddress()
|
||||
{
|
||||
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test01', 'reserved_order_id');
|
||||
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Paypal\Block\Express\Review::class
|
||||
);
|
||||
$addressData = include __DIR__ . '/../../../Sales/_files/address_data.php';
|
||||
$address = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Quote\Model\Quote\Address::class,
|
||||
['data' => $addressData]
|
||||
);
|
||||
$address->setAddressType('billing');
|
||||
$address->setQuote($quote);
|
||||
$this->assertStringContainsString('Los Angeles', $block->renderAddress($address));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Block\PayLater;
|
||||
|
||||
use Magento\Framework\App\Config\MutableScopeConfigInterface;
|
||||
use Magento\Framework\App\MutableScopeConfig;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BannerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
* @dataProvider getJsLayoutDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Paypal\Block\PayLater\Banner::getJsLayout()
|
||||
* @covers \Magento\Paypal\Block\PayLater\Banner::getStyleAttributesConfig()
|
||||
*/
|
||||
public function testGetJsLayout($systemConfig, $blockConfig, $expectedConfig)
|
||||
{
|
||||
$this->setConfig($systemConfig);
|
||||
|
||||
/** @var LayoutInterface $layout */
|
||||
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
|
||||
$block = $layout->createBlock(Banner::class, '', ['data' => $blockConfig]);
|
||||
|
||||
$jsConfig = json_decode($block->getJsLayout(), true);
|
||||
$this->assertArrayHasKey('config', $jsConfig['components']['payLater']);
|
||||
$this->assertArrayHasKey('component', $jsConfig['components']['payLater']);
|
||||
|
||||
$optionsConfig = $jsConfig['components']['payLater']['config'];
|
||||
$this->assertEquals($expectedConfig, array_intersect_key($optionsConfig, $expectedConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getJsLayoutDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'systemConfig' => [
|
||||
'payment/paypal_paylater/test1page_stylelayout' => 'flex',
|
||||
'payment/paypal_paylater/test1page_ratio' => '20x1',
|
||||
'payment/paypal_paylater/test1page_color' => 'blue'
|
||||
],
|
||||
'blockConfig' => [
|
||||
'placement' => 'test1',
|
||||
'jsLayout' => [
|
||||
'components' => [
|
||||
'payLater' => [
|
||||
'config' => [
|
||||
'attributes' => [
|
||||
'data-pp-style-ratio' => '1x1'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'expectedConfig' => [
|
||||
'attributes' => [
|
||||
'data-pp-style-layout' => 'flex',
|
||||
'data-pp-style-logo-type' => null,
|
||||
'data-pp-style-logo-position' => null,
|
||||
'data-pp-style-text-color' => null,
|
||||
'data-pp-style-text-size' => null,
|
||||
'data-pp-style-color' => 'blue',
|
||||
'data-pp-style-ratio' => '1x1',
|
||||
'data-pp-placement' => 'test1'
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'systemConfig' => [
|
||||
'payment/paypal_paylater/test2page_stylelayout' => 'text',
|
||||
'payment/paypal_paylater/test2page_logotype' => 'primary',
|
||||
'payment/paypal_paylater/test2page_logoposition' => 'left',
|
||||
'payment/paypal_paylater/test2page_textcolor' => 'white',
|
||||
'payment/paypal_paylater/test2page_textsize' => '10'
|
||||
|
||||
],
|
||||
'blockConfig' => [
|
||||
'placement' => 'test2',
|
||||
'jsLayout' => [
|
||||
'components' => [
|
||||
'payLater' => [
|
||||
'config' => [
|
||||
'attributes' => [
|
||||
'data-pp-style-text-color' => 'black'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'expectedConfig' => [
|
||||
'attributes' => [
|
||||
'data-pp-style-layout' => 'text',
|
||||
'data-pp-style-logo-type' => 'primary',
|
||||
'data-pp-style-logo-position' => 'left',
|
||||
'data-pp-style-text-color' => 'black',
|
||||
'data-pp-style-text-size' => '10',
|
||||
'data-pp-style-color' => null,
|
||||
'data-pp-style-ratio' => null,
|
||||
'data-pp-placement' => 'test2'
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
* @dataProvider sdkUrlDataProvider
|
||||
* @covers \Magento\Paypal\Block\PayLater\Banner::getJsLayout()
|
||||
* @covers \Magento\Paypal\Block\PayLater\Banner::getPayPalSdkUrl()
|
||||
*/
|
||||
public function testSdkUrl($blockConfig, $expectedUrl)
|
||||
{
|
||||
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
|
||||
$block = $layout->createBlock(Banner::class, '', ['data' => $blockConfig]);
|
||||
|
||||
$jsConfig = json_decode($block->getJsLayout(), true);
|
||||
$this->assertArrayHasKey('config', $jsConfig['components']['payLater']);
|
||||
$this->assertArrayHasKey('sdkUrl', $jsConfig['components']['payLater']['config']);
|
||||
$this->assertStringContainsString($expectedUrl, $jsConfig['components']['payLater']['config']['sdkUrl']);
|
||||
}
|
||||
|
||||
public function sdkUrlDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'blockConfig' => [
|
||||
'jsLayout' => [
|
||||
'components' => [
|
||||
'payLater' => [
|
||||
'config' => [
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'expectedUrl' => 'paypal.com/sdk'
|
||||
],
|
||||
[
|
||||
'blockConfig' => [
|
||||
'jsLayout' => [
|
||||
'components' => [
|
||||
'payLater' => [
|
||||
'config' => [
|
||||
'attributes' => ['test1' => 'value1']
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'expectedUrl' => 'paypal.com/sdk'
|
||||
],
|
||||
[
|
||||
'blockConfig' => [
|
||||
'jsLayout' => [
|
||||
'components' => [
|
||||
'payLater' => [
|
||||
'config' => [
|
||||
'sdkUrl' => 'http://mock.url'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'expectedUrl' => 'mock.url'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
$paymentMethod = sprintf('payment/%s/active', Config::METHOD_EXPRESS);
|
||||
$systemConfig = [
|
||||
$paymentMethod => 1,
|
||||
'payment/paypal_paylater/experience_active' => 1,
|
||||
'payment/paypal_paylater/enabled' => 1,
|
||||
'payment/paypal_paylater/test3page_display' => 1,
|
||||
'payment/paypal_paylater/test3page_position' => 'header'
|
||||
];
|
||||
$blockConfig = [
|
||||
'placement' => 'test3',
|
||||
'position' => 'header'
|
||||
];
|
||||
$this->setConfig($systemConfig);
|
||||
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
|
||||
|
||||
/** @var Banner $block */
|
||||
$block = $layout->createBlock(Banner::class, '', ['data' => $blockConfig]);
|
||||
$block->setTemplate('Magento_Paypal::paylater/banner.phtml');
|
||||
|
||||
$this->assertNotEmpty($block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check display configuration
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoAppIsolation enabled
|
||||
* @dataProvider toHtmlEmptyDataProvider
|
||||
* @param $systemConfig
|
||||
* @param $blockConfig
|
||||
*/
|
||||
public function testToHtmlEmpty($systemConfig, $blockConfig)
|
||||
{
|
||||
//Enable all required options
|
||||
$paymentMethod = sprintf('payment/%s/active', Config::METHOD_EXPRESS);
|
||||
$enableSystemConfig = [
|
||||
$paymentMethod => 1,
|
||||
'payment/paypal_paylater/experience_active' => 1,
|
||||
'payment/paypal_paylater/enabled' => 1,
|
||||
'payment/paypal_paylater/test4page_display' => 1,
|
||||
'payment/paypal_paylater/test4page_position' => 'near_pp_button'
|
||||
];
|
||||
$enableBlockConfig = [
|
||||
'placement' => 'test4',
|
||||
'position' => 'near_pp_button'
|
||||
];
|
||||
//Disable specific system configuration option
|
||||
$systemConfig = array_replace($enableSystemConfig, $systemConfig);
|
||||
// Update block config
|
||||
$blockConfig = array_replace($enableBlockConfig, $blockConfig);
|
||||
$this->setConfig($systemConfig);
|
||||
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
|
||||
/** @var Banner $block */
|
||||
$block = $layout->createBlock(Banner::class, '', ['data' => $blockConfig]);
|
||||
$block->setTemplate('Magento_Paypal::paylater/banner.phtml');
|
||||
|
||||
$this->assertEmpty($block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function toHtmlEmptyDataProvider()
|
||||
{
|
||||
$paymentPath = 'payment/%s/active';
|
||||
return [
|
||||
[
|
||||
'systemConfig' => ['payment/paypal_paylater/experience_active' => 0],
|
||||
'blockConfig' => []
|
||||
],
|
||||
[
|
||||
'systemConfig' => ['payment/paypal_paylater/enabled' => 0],
|
||||
'blockConfig' => []
|
||||
],
|
||||
[
|
||||
'systemConfig' => ['payment/paypal_paylater/test4page_display' => 0],
|
||||
'blockConfig' => []
|
||||
],
|
||||
[
|
||||
'systemConfig' => [],
|
||||
'blockConfig' => ['position' => 'header']
|
||||
],
|
||||
[
|
||||
'systemConfig' => [sprintf($paymentPath, Config::METHOD_EXPRESS) => 0],
|
||||
'blockConfig' => []
|
||||
],
|
||||
[
|
||||
'systemConfig' => ['paypal/style/disable_funding_options' => 'CREDIT'],
|
||||
'blockConfig' => []
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set system configuration value for test
|
||||
*
|
||||
* @param $config
|
||||
*/
|
||||
private function setConfig($config)
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var $scopeConfig MutableScopeConfig */
|
||||
$scopeConfig = $objectManager->get(MutableScopeConfigInterface::class);
|
||||
foreach ($config as $path => $value) {
|
||||
$scopeConfig->setValue($path, $value, ScopeInterface::SCOPE_STORE);
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Test for \Magento\Paypal\Block\Payment\Form\Billing\Agreement
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Payment\Form\Billing;
|
||||
|
||||
class AgreementTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Paypal\Block\Payment\Form\Billing\Agreement */
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Quote\Model\ResourceModel\Quote\Collection::class
|
||||
)->getFirstItem();
|
||||
/** @var \Magento\Framework\View\LayoutInterface $layout */
|
||||
$layout = $this->getMockBuilder(\Magento\Framework\View\LayoutInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$layout->expects(
|
||||
$this->once()
|
||||
)->method(
|
||||
'getBlock'
|
||||
)->willReturn(
|
||||
new \Magento\Framework\DataObject(['quote' => $quote])
|
||||
);
|
||||
$layout->expects($this->once())->method('getParentName')->willReturn('billing_agreement_form');
|
||||
|
||||
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Block\Payment\Form\Billing\Agreement::class
|
||||
);
|
||||
$this->_block->setLayout($layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testGetBillingAgreements()
|
||||
{
|
||||
$billingAgreements = $this->_block->getBillingAgreements();
|
||||
$this->assertCount(1, $billingAgreements);
|
||||
$this->assertEquals('REF-ID-TEST-678', array_shift($billingAgreements));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user