ltsecurityinc安防产品在线商城代码
This commit is contained in:
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency;
|
||||
|
||||
use Magento\Framework\Escaper;
|
||||
|
||||
/**
|
||||
* Test for fetchRates action
|
||||
*/
|
||||
class FetchRatesTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @var Escaper
|
||||
*/
|
||||
private $escaper;
|
||||
|
||||
/**
|
||||
* Initial setup
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->escaper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
Escaper::class
|
||||
);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fetch action without service
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFetchRatesActionWithoutService(): void
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$request->setParam(
|
||||
'rate_services',
|
||||
null
|
||||
);
|
||||
$this->dispatch('backend/admin/system_currency/fetchRates');
|
||||
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual('The Import Service is incorrect. Verify the service and try again.'),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test save action with nonexistent service
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFetchRatesActionWithNonexistentService(): void
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$request->setParam(
|
||||
'rate_services',
|
||||
'non-existent-service'
|
||||
);
|
||||
$this->dispatch('backend/admin/system_currency/fetchRates');
|
||||
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual(
|
||||
$this->escaper->escapeHtml(
|
||||
"The import model can't be initialized. Verify the model and try again."
|
||||
)
|
||||
),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Test index action
|
||||
*/
|
||||
public function testIndexAction()
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$configResource = $objectManager->get(\Magento\Config\Model\ResourceModel\Config::class);
|
||||
$configResource->saveConfig(
|
||||
'currency/options/base',
|
||||
'USD',
|
||||
ScopeInterface::SCOPE_STORE,
|
||||
0
|
||||
);
|
||||
$configResource->saveConfig(
|
||||
'currency/options/allow',
|
||||
'USD,GBP,EUR',
|
||||
ScopeInterface::SCOPE_STORE,
|
||||
0
|
||||
);
|
||||
$this->dispatch('backend/admin/system_currency/index');
|
||||
$this->getResponse()->isSuccess();
|
||||
$body = $this->getResponse()->getBody();
|
||||
$this->assertStringContainsString('id="rate-form"', $body);
|
||||
$this->assertStringContainsString('save primary save-currency-rates', $body);
|
||||
$this->assertStringContainsString('data-ui-id="page-actions-toolbar-reset-button"', $body);
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency;
|
||||
|
||||
use Magento\Directory\Model\Currency;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\Escaper;
|
||||
|
||||
class SaveRatesTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/** @var Currency $currencyRate */
|
||||
protected $currencyRate;
|
||||
|
||||
/**
|
||||
* @var Escaper
|
||||
*/
|
||||
private $escaper;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->currencyRate = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
Currency::class
|
||||
);
|
||||
$this->escaper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
Escaper::class
|
||||
);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test save action
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testSaveAction(): void
|
||||
{
|
||||
$currencyCode = 'USD';
|
||||
$currencyTo = 'USD';
|
||||
$rate = 1.0000;
|
||||
|
||||
$request = $this->getRequest();
|
||||
$request->setMethod(HttpRequest::METHOD_POST);
|
||||
$request->setPostValue(
|
||||
'rate',
|
||||
[
|
||||
$currencyCode => [$currencyTo => $rate]
|
||||
]
|
||||
);
|
||||
$this->dispatch('backend/admin/system_currency/saveRates');
|
||||
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual((string)__('All valid rates have been saved.')),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$rate,
|
||||
$this->currencyRate->load($currencyCode)->getRate($currencyTo),
|
||||
'Currency rate has not been saved'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test save action with warning
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testSaveWithWarningAction(): void
|
||||
{
|
||||
$currencyCode = 'USD';
|
||||
$currencyTo = 'USD';
|
||||
$rate = '0';
|
||||
|
||||
$request = $this->getRequest();
|
||||
$request->setMethod(HttpRequest::METHOD_POST);
|
||||
$request->setPostValue(
|
||||
'rate',
|
||||
[
|
||||
$currencyCode => [$currencyTo => $rate]
|
||||
]
|
||||
);
|
||||
$this->dispatch('backend/admin/system_currency/saveRates');
|
||||
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual(
|
||||
$this->escaper->escapeHtml(
|
||||
(string)__('Please correct the input data for "%1 => %2" rate.', $currencyCode, $currencyTo)
|
||||
)
|
||||
),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_WARNING
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test save action with warning
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testSaveWithNullRates(): void
|
||||
{
|
||||
$currencyCode = 'USD';
|
||||
$currencyTo = 'USD';
|
||||
$rate = null;
|
||||
|
||||
$request = $this->getRequest();
|
||||
$request->setMethod(HttpRequest::METHOD_POST);
|
||||
$request->setPostValue(
|
||||
'rate',
|
||||
[
|
||||
$currencyCode => [$currencyTo => $rate]
|
||||
]
|
||||
);
|
||||
$this->dispatch('backend/admin/system_currency/saveRates');
|
||||
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual(
|
||||
$this->escaper->escapeHtml(
|
||||
(string)__('Please correct the input data for "%1 => %2" rate.', $currencyCode, $currencyTo)
|
||||
)
|
||||
),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_WARNING
|
||||
);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol;
|
||||
|
||||
class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Test index action
|
||||
*
|
||||
* @magentoConfigFixture currency/options/allow USD
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testIndexAction()
|
||||
{
|
||||
$this->dispatch('backend/admin/system_currencysymbol/index');
|
||||
|
||||
$body = $this->getResponse()->getBody();
|
||||
$this->assertStringContainsString('id="currency-symbols-form"', $body);
|
||||
$this->assertStringContainsString('<input id="custom_currency_symbolUSD"', $body);
|
||||
$this->assertStringContainsString('save primary save-currency-symbols', $body);
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol;
|
||||
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
|
||||
class SaveTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Test save action.
|
||||
*
|
||||
* @param string $currencyCode
|
||||
* @param string $inputCurrencySymbol
|
||||
* @param string $outputCurrencySymbol
|
||||
*
|
||||
* @magentoConfigFixture currency/options/allow USD
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @dataProvider currencySymbolDataProvider
|
||||
*/
|
||||
public function testSaveAction($currencyCode, $inputCurrencySymbol, $outputCurrencySymbol)
|
||||
{
|
||||
/** @var \Magento\CurrencySymbol\Model\System\Currencysymbol $currencySymbol */
|
||||
$currencySymbol = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\CurrencySymbol\Model\System\Currencysymbol::class
|
||||
);
|
||||
|
||||
$currencySymbolOriginal = $currencySymbol->getCurrencySymbol($currencyCode);
|
||||
|
||||
$request = $this->getRequest();
|
||||
$request->setParam(
|
||||
'custom_currency_symbol',
|
||||
[
|
||||
$currencyCode => $inputCurrencySymbol,
|
||||
]
|
||||
);
|
||||
$request->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->dispatch('backend/admin/system_currencysymbol/save');
|
||||
|
||||
$this->assertRedirect();
|
||||
|
||||
$this->assertEquals(
|
||||
$outputCurrencySymbol,
|
||||
$currencySymbol->getCurrencySymbol($currencyCode),
|
||||
'Currency symbol has not been saved'
|
||||
);
|
||||
|
||||
//restore current symbol
|
||||
$currencySymbol->setCurrencySymbolsData([$currencyCode => $currencySymbolOriginal]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function currencySymbolDataProvider()
|
||||
{
|
||||
return [
|
||||
['USD', 'customSymbolUSD', 'customSymbolUSD'],
|
||||
['USD', '<script>customSymbolUSD</script>', 'customSymbolUSD']
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user