ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Payment\Block;
|
||||
|
||||
use Magento\Framework\View\Element\Text;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\OfflinePayments\Model\Banktransfer;
|
||||
use Magento\OfflinePayments\Model\Checkmo;
|
||||
use Magento\Payment\Block\Info as BlockInfo;
|
||||
use Magento\Payment\Block\Info\Instructions;
|
||||
use Magento\Payment\Model\Info;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test for Magento\Payment\Block\Info
|
||||
*/
|
||||
class InfoTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Tests payment info block.
|
||||
*
|
||||
* @magentoConfigFixture current_store payment/banktransfer/title Bank Method Title
|
||||
* @magentoConfigFixture current_store payment/checkmo/title Checkmo Title Of The Method
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testGetChildPdfAsArray()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
|
||||
$block = $layout->createBlock(BlockInfo::class, 'block');
|
||||
|
||||
/** @var $paymentInfoBank Info */
|
||||
$paymentInfoBank = Bootstrap::getObjectManager()->create(
|
||||
Info::class
|
||||
);
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class);
|
||||
$banktransferPayment = Bootstrap::getObjectManager()->create(Banktransfer::class);
|
||||
$paymentInfoBank->setMethodInstance($banktransferPayment);
|
||||
$paymentInfoBank->setOrder($order);
|
||||
/** @var $childBank Instructions */
|
||||
$childBank = $layout->addBlock(Instructions::class, 'child.one', 'block');
|
||||
$childBank->setInfo($paymentInfoBank);
|
||||
|
||||
$nonExpectedHtml = 'non-expected html';
|
||||
$childHtml = $layout->addBlock(Text::class, 'child.html', 'block');
|
||||
$childHtml->setText($nonExpectedHtml);
|
||||
|
||||
/** @var $paymentInfoCheckmo Info */
|
||||
$paymentInfoCheckmo = Bootstrap::getObjectManager()->create(
|
||||
Info::class
|
||||
);
|
||||
$checkmoPayment = Bootstrap::getObjectManager()->create(Checkmo::class);
|
||||
$paymentInfoCheckmo->setMethodInstance($checkmoPayment);
|
||||
$paymentInfoCheckmo->setOrder($order);
|
||||
/** @var $childCheckmo \Magento\OfflinePayments\Block\Info\Checkmo */
|
||||
$childCheckmo = $layout->addBlock(
|
||||
\Magento\OfflinePayments\Block\Info\Checkmo::class,
|
||||
'child.just.another',
|
||||
'block'
|
||||
);
|
||||
$childCheckmo->setInfo($paymentInfoCheckmo);
|
||||
|
||||
$pdfArray = $block->getChildPdfAsArray();
|
||||
|
||||
$this->assertIsArray($pdfArray);
|
||||
$this->assertCount(2, $pdfArray);
|
||||
$text = implode('', $pdfArray);
|
||||
$this->assertStringContainsString('Bank Method Title', $text);
|
||||
$this->assertStringContainsString('Checkmo Title Of The Method', $text);
|
||||
$this->assertStringNotContainsString($nonExpectedHtml, $text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Payment\Block\Transparent;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Payment\Block\Transparent\Iframe
|
||||
*/
|
||||
class IframeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
* @dataProvider xssDataProvider
|
||||
*/
|
||||
public function testToHtml($xssString)
|
||||
{
|
||||
/** @var $block Iframe */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Payment\Block\Transparent\Iframe::class
|
||||
);
|
||||
|
||||
$block->setTemplate('transparent/iframe.phtml');
|
||||
$block->setData(
|
||||
'params',
|
||||
[
|
||||
'redirect' => $xssString,
|
||||
'redirect_parent' => $xssString,
|
||||
'error_msg' => $xssString
|
||||
]
|
||||
);
|
||||
|
||||
$content = $block->toHtml();
|
||||
|
||||
$this->assertStringNotContainsString($xssString, $content, 'Params must be escaped');
|
||||
$this->assertStringContainsString($block->escapeJs($xssString), $content, 'Content must be present');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function xssDataProvider()
|
||||
{
|
||||
return [
|
||||
['</script><script>alert("XSS")</script>'],
|
||||
['javascript%3Aalert%28String.fromCharCode%280x78%29%2BString.fromCharCode%280x73%29%2BString.'
|
||||
. 'fromCharCode%280x73%29%29'],
|
||||
['javascript:alert(String.fromCharCode(0x78)+String.fromCharCode(0x73)+String.fromCharCode(0x73))']
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Payment\Helper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\OfflinePayments\Block\Info\Checkmo;
|
||||
use Magento\Payment\Model\Info;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Payment\Helper\Data
|
||||
*/
|
||||
class DataTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Data
|
||||
*/
|
||||
private $helper;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->helper = Bootstrap::getObjectManager()->get(Data::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInfoBlock()
|
||||
{
|
||||
$paymentInfo = Bootstrap::getObjectManager()->create(
|
||||
Info::class
|
||||
);
|
||||
$paymentInfo->setMethod('checkmo');
|
||||
$result = $this->helper->getInfoBlock($paymentInfo);
|
||||
$this->assertInstanceOf(Checkmo::class, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to load Payment method title from store config
|
||||
*
|
||||
* @magentoConfigFixture current_store payment/cashondelivery/title Cash On Delivery Title Of The Method
|
||||
*/
|
||||
public function testPaymentMethodLabelByStore()
|
||||
{
|
||||
$result = $this->helper->getPaymentMethodList(true, true);
|
||||
$this->assertArrayHasKey('cashondelivery', $result, 'Payment info does not exist');
|
||||
$this->assertEquals(
|
||||
'Cash On Delivery Title Of The Method',
|
||||
$result['cashondelivery']['label'],
|
||||
'Payment method title is not loaded from store config'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* \Magento\Payment\Model\Config\Reader
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Payment\Model\Config;
|
||||
|
||||
class ReaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Payment\Model\Config\Reader
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/** @var \Magento\Framework\Config\FileResolverInterface/PHPUnit\Framework\MockObject_MockObject */
|
||||
protected $_fileResolverMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $cache \Magento\Framework\App\Cache */
|
||||
$cache = $objectManager->create(\Magento\Framework\App\Cache::class);
|
||||
$cache->clean();
|
||||
$this->_fileResolverMock = $this->getMockBuilder(
|
||||
\Magento\Framework\Config\FileResolverInterface::class
|
||||
)->disableOriginalConstructor()->getMock();
|
||||
$this->_model = $objectManager->create(
|
||||
\Magento\Payment\Model\Config\Reader::class,
|
||||
['fileResolver' => $this->_fileResolverMock]
|
||||
);
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$fileList = [file_get_contents(__DIR__ . '/../_files/payment.xml')];
|
||||
$this->_fileResolverMock->expects($this->any())->method('get')->willReturn($fileList);
|
||||
$result = $this->_model->read('global');
|
||||
$expected = [
|
||||
'credit_cards' => ['SO' => 'Solo', 'SM' => 'Switch/Maestro'],
|
||||
'groups' => ['any_payment' => 'Any Payment'],
|
||||
'methods' => ['checkmo' => ['allow_multiple_address' => 1]],
|
||||
];
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testMergeCompleteAndPartial()
|
||||
{
|
||||
$fileList = [
|
||||
file_get_contents(__DIR__ . '/../_files/payment.xml'),
|
||||
file_get_contents(__DIR__ . '/../_files/payment2.xml'),
|
||||
];
|
||||
$this->_fileResolverMock->expects($this->any())->method('get')->willReturn($fileList);
|
||||
|
||||
$result = $this->_model->read('global');
|
||||
$expected = [
|
||||
'credit_cards' => ['AE' => 'American Express', 'SM' => 'Switch/Maestro', 'SO' => 'Solo'],
|
||||
'groups' => ['any_payment' => 'Any Payment Methods', 'offline' => 'Offline Payment Methods'],
|
||||
'methods' => [
|
||||
'checkmo' => ['allow_multiple_address' => 1],
|
||||
'deny-method' => ['allow_multiple_address' => 0],
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* \Magento\Payment\Model\Config
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Payment\Model;
|
||||
|
||||
use Magento\Payment\Model\Config;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class ConfigTest
|
||||
*/
|
||||
class ConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $model = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var $cache \Magento\Framework\App\Cache */
|
||||
$cache = $objectManager->create(\Magento\Framework\App\Cache::class);
|
||||
$cache->clean();
|
||||
$fileResolverMock = $this->getMockBuilder(
|
||||
\Magento\Framework\Config\FileResolverInterface::class
|
||||
)->disableOriginalConstructor()->getMock();
|
||||
$fileList = [
|
||||
file_get_contents(__DIR__ . '/_files/payment.xml'),
|
||||
file_get_contents(__DIR__ . '/_files/payment2.xml'),
|
||||
];
|
||||
$fileResolverMock->expects($this->any())->method('get')->willReturn($fileList);
|
||||
$reader = $objectManager->create(
|
||||
\Magento\Payment\Model\Config\Reader::class,
|
||||
['fileResolver' => $fileResolverMock]
|
||||
);
|
||||
$data = $objectManager->create(\Magento\Payment\Model\Config\Data::class, ['reader' => $reader]);
|
||||
$this->model = $objectManager->create(Config::class, ['dataStorage' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Payment\Model\Config::getActiveMethods
|
||||
*/
|
||||
public function testGetActiveMethods()
|
||||
{
|
||||
$paymentMethods = $this->model->getActiveMethods();
|
||||
static::assertNotEmpty($paymentMethods);
|
||||
|
||||
/** @var \Magento\Payment\Model\MethodInterface $method */
|
||||
foreach ($paymentMethods as $method) {
|
||||
static::assertNotEmpty($method->getCode());
|
||||
static::assertTrue($method->isActive());
|
||||
static::assertEquals(0, $method->getStore());
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetCcTypes()
|
||||
{
|
||||
$expected = ['AE' => 'American Express', 'SM' => 'Switch/Maestro', 'SO' => 'Solo'];
|
||||
$ccTypes = $this->model->getCcTypes();
|
||||
$this->assertEquals($expected, $ccTypes);
|
||||
}
|
||||
|
||||
public function testGetGroups()
|
||||
{
|
||||
$expected = ['any_payment' => 'Any Payment Methods', 'offline' => 'Offline Payment Methods'];
|
||||
$groups = $this->model->getGroups();
|
||||
$this->assertEquals($expected, $groups);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var $cache \Magento\Framework\App\Cache */
|
||||
$cache = $objectManager->create(\Magento\Framework\App\Cache::class);
|
||||
$cache->clean();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Payment\Model;
|
||||
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class PaymentInfoTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
protected $_objectManager;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
protected $_order;
|
||||
|
||||
/** @var Quote */
|
||||
protected $_quote;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_objectManager = Bootstrap::getObjectManager();
|
||||
$this->_order = $this->_objectManager->create(
|
||||
Order::class
|
||||
);
|
||||
$this->_quote = $this->_objectManager->create(
|
||||
Quote::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Payment/_files/payment_info.php
|
||||
*/
|
||||
public function testUnsetPaymentInformation()
|
||||
{
|
||||
$order = $this->_order->loadByIncrementId('100000001');
|
||||
/** @var \Magento\Sales\Model\Order\Payment $paymentOrder */
|
||||
$paymentOrder = $order->getPayment();
|
||||
$paymentOrder->unsAdditionalInformation('testing');
|
||||
|
||||
$quote = $this->_quote->load('reserved_order_id', 'reserved_order_id');
|
||||
/** @var \Magento\Quote\Model\Quote\Payment $paymentQuote */
|
||||
$paymentQuote = $quote->getPayment();
|
||||
$paymentQuote->unsAdditionalInformation('testing');
|
||||
|
||||
$this->assertFalse($paymentOrder->hasAdditionalInformation('testing'));
|
||||
$this->assertFalse($paymentQuote->hasAdditionalInformation('testing'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<payment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Payment:etc/payment.xsd">
|
||||
<credit_cards>
|
||||
<type id="SM" order="60">
|
||||
<label>Switch/Maestro</label>
|
||||
</type>
|
||||
<type id="SO" order="31">
|
||||
<label>Solo</label>
|
||||
</type>
|
||||
</credit_cards>
|
||||
<groups>
|
||||
<group id="any_payment">
|
||||
<label>Any Payment</label>
|
||||
</group>
|
||||
</groups>
|
||||
<methods>
|
||||
<method name="checkmo">
|
||||
<allow_multiple_address>1</allow_multiple_address>
|
||||
</method>
|
||||
</methods>
|
||||
</payment>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<payment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Payment:etc/payment.xsd">
|
||||
<credit_cards>
|
||||
<type id="AE" order="0">
|
||||
<label>American Express</label>
|
||||
</type>
|
||||
<type id="SO" order="90">
|
||||
<label>Solo</label>
|
||||
</type>
|
||||
</credit_cards>
|
||||
<groups>
|
||||
<group id="any_payment">
|
||||
<label>Any Payment Methods</label>
|
||||
</group>
|
||||
<group id="offline">
|
||||
<label>Offline Payment Methods</label>
|
||||
</group>
|
||||
</groups>
|
||||
<methods>
|
||||
<method name="deny-method">
|
||||
<allow_multiple_address>0</allow_multiple_address>
|
||||
</method>
|
||||
</methods>
|
||||
</payment>
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Payment\Observer;
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class UpdateOrderStatusForPaymentMethodsObserverTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Event\Observer
|
||||
*/
|
||||
protected $_eventObserver;
|
||||
|
||||
/**
|
||||
* @var \Magento\TestFramework\ObjectManager
|
||||
*/
|
||||
protected $_objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_eventObserver = $this->_createEventObserver();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that \Magento\Payment\Observer\UpdateOrderStatusForPaymentMethodsObserver::execute()
|
||||
* is called as event and it can change status
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Payment/_files/order_status.php
|
||||
*/
|
||||
public function testUpdateOrderStatusForPaymentMethodsEvent()
|
||||
{
|
||||
$statusCode = 'custom_new_status';
|
||||
$data = [
|
||||
'section' => 'payment',
|
||||
'website' => 1,
|
||||
'store' => 1,
|
||||
'groups' => ['checkmo' => ['fields' => ['order_status' => ['value' => $statusCode]]]],
|
||||
];
|
||||
$this->_objectManager->create(
|
||||
\Magento\Config\Model\Config::class
|
||||
)->setSection(
|
||||
'payment'
|
||||
)->setWebsite(
|
||||
'base'
|
||||
)->setGroups(
|
||||
['groups' => $data['groups']]
|
||||
)->save();
|
||||
|
||||
/** @var \Magento\Sales\Model\Order\Status $status */
|
||||
$status = $this->_objectManager->get(\Magento\Sales\Model\Order\Status::class)->load($statusCode);
|
||||
|
||||
/** @var $scopeConfig \Magento\Framework\App\Config\ScopeConfigInterface */
|
||||
$scopeConfig = $this->_objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class);
|
||||
$defaultStatus = (string)$scopeConfig->getValue(
|
||||
'payment/checkmo/order_status',
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
|
||||
/** @var \Magento\Config\Model\ResourceModel\Config $config */
|
||||
$config = $this->_objectManager->get(\Magento\Config\Model\ResourceModel\Config::class);
|
||||
$config->saveConfig(
|
||||
'payment/checkmo/order_status',
|
||||
$statusCode,
|
||||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
0
|
||||
);
|
||||
|
||||
$this->_resetConfig();
|
||||
|
||||
$newStatus = (string)$scopeConfig->getValue(
|
||||
'payment/checkmo/order_status',
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
|
||||
$status->unassignState(\Magento\Sales\Model\Order::STATE_NEW);
|
||||
|
||||
$this->_resetConfig();
|
||||
|
||||
$unassignedStatus = $scopeConfig->getValue(
|
||||
'payment/checkmo/order_status',
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
|
||||
$this->assertEquals('pending', $defaultStatus);
|
||||
$this->assertEquals($statusCode, $newStatus);
|
||||
$this->assertEquals('pending', $unassignedStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testUpdateOrderStatusForPaymentMethods()
|
||||
{
|
||||
$statusCode = 'custom_new_status';
|
||||
|
||||
/** @var \Magento\Config\Model\ResourceModel\Config $config */
|
||||
$config = $this->_objectManager->get(\Magento\Config\Model\ResourceModel\Config::class);
|
||||
$config->saveConfig('payment/checkmo/order_status', $statusCode, 'default', 0);
|
||||
|
||||
$this->_resetConfig();
|
||||
|
||||
$observer = $this->_objectManager->create(
|
||||
\Magento\Payment\Observer\UpdateOrderStatusForPaymentMethodsObserver::class
|
||||
);
|
||||
$observer->execute($this->_eventObserver);
|
||||
|
||||
$this->_resetConfig();
|
||||
|
||||
/** @var $scopeConfig \Magento\Framework\App\Config\ScopeConfigInterface */
|
||||
$scopeConfig = $this->_objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class);
|
||||
$unassignedStatus = (string)$scopeConfig->getValue(
|
||||
'payment/checkmo/order_status',
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
$this->assertEquals('pending', $unassignedStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create event observer
|
||||
*
|
||||
* @return \Magento\Framework\Event\Observer
|
||||
*/
|
||||
protected function _createEventObserver()
|
||||
{
|
||||
$data = ['status' => 'custom_new_status', 'state' => \Magento\Sales\Model\Order::STATE_NEW];
|
||||
$event = $this->_objectManager->create(\Magento\Framework\Event::class, ['data' => $data]);
|
||||
return $this->_objectManager
|
||||
->create(\Magento\Framework\Event\Observer::class, ['data' => ['event' => $event]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear config cache
|
||||
*/
|
||||
protected function _resetConfig()
|
||||
{
|
||||
$this->_objectManager->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class)->reinit();
|
||||
$this->_objectManager->create(\Magento\Store\Model\StoreManagerInterface::class)->reinitStores();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var \Magento\Sales\Model\Order\Status $status */
|
||||
$status = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order\Status::class);
|
||||
//status for state new
|
||||
$status->setData('status', 'custom_new_status')->setData('label', 'Test Status')->save();
|
||||
$status->assignState(\Magento\Sales\Model\Order::STATE_NEW, true);
|
||||
//status for state canceled
|
||||
$status->setData('status', 'custom_canceled_status')->setData('label', 'Test Status')->unsetData('id')->save();
|
||||
$status->assignState(\Magento\Sales\Model\Order::STATE_CANCELED, true);
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Sales\Model\Order\Address;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Payment as PaymentQuote;
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$addressData = [
|
||||
'firstname' => 'guest',
|
||||
'lastname' => 'guest',
|
||||
'email' => 'customer@example.com',
|
||||
'street' => 'street',
|
||||
'city' => 'Los Angeles',
|
||||
'region' => 'CA',
|
||||
'postcode' => '1',
|
||||
'country_id' => 'US',
|
||||
'telephone' => '1'
|
||||
];
|
||||
$billingAddress = $objectManager->create(
|
||||
Address::class,
|
||||
['data' => $addressData]
|
||||
);
|
||||
$billingAddress->setAddressType('billing');
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
|
||||
/** @var Payment $paymentOrder */
|
||||
$paymentOrder = $objectManager->create(
|
||||
Payment::class
|
||||
);
|
||||
|
||||
$paymentOrder->setMethod(Config::METHOD_WPP_EXPRESS);
|
||||
$paymentOrder->setAdditionalInformation('testing', 'testing additional data');
|
||||
|
||||
$amount = 100;
|
||||
|
||||
/** @var Order $order */
|
||||
$order = $objectManager->create(Order::class);
|
||||
$order->setCustomerEmail('co@co.co')
|
||||
->setIncrementId('100000001')
|
||||
->setSubtotal($amount)
|
||||
->setBaseSubtotal($amount)
|
||||
->setBaseGrandTotal($amount)
|
||||
->setGrandTotal($amount)
|
||||
->setBaseCurrencyCode('USD')
|
||||
->setCustomerIsGuest(true)
|
||||
->setStoreId(1)
|
||||
->setEmailSent(true)
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress)
|
||||
->setPayment($paymentOrder);
|
||||
$order->save();
|
||||
|
||||
|
||||
|
||||
/** @var Quote $quote */
|
||||
$quote = $objectManager->create(Quote::class);
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(false)
|
||||
->setReservedOrderId('reserved_order_id');
|
||||
|
||||
$quote->getPayment()
|
||||
->setMethod(Config::METHOD_WPP_EXPRESS)
|
||||
->setAdditionalInformation('testing', 'testing additional data');
|
||||
|
||||
$quote->collectTotals();
|
||||
|
||||
|
||||
/** @var CartRepositoryInterface $repository */
|
||||
$repository = $objectManager->get(CartRepositoryInterface::class);
|
||||
$repository->save($quote);
|
||||
Reference in New Issue
Block a user