ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -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
);
}
}
@@ -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);
}
}
@@ -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
);
}
}
@@ -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);
}
}
@@ -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']
];
}
}
@@ -0,0 +1,127 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CurrencySymbol\Model\System;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Test for Magento\CurrencySymbol\Model\System\Currencysymbol
*
* @magentoAppArea adminhtml
*/
class CurrencysymbolTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\CurrencySymbol\Model\System\Currencysymbol
*/
protected $currencySymbolModel;
/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->currencySymbolModel = Bootstrap::getObjectManager()->create(
\Magento\CurrencySymbol\Model\System\Currencysymbol::class
);
}
/**
* @inheritDoc
*/
protected function tearDown(): void
{
$this->currencySymbolModel = null;
Bootstrap::getObjectManager()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class)->reinit();
Bootstrap::getObjectManager()->create(\Magento\Store\Model\StoreManagerInterface::class)->reinitStores();
}
/**
* Test that getCurrencySymbolsData method returns valid data
*
* @return void
*/
public function testGetCurrencySymbolsData()
{
$currencySymbolsData = $this->currencySymbolModel->getCurrencySymbolsData();
$this->assertArrayHasKey('USD', $currencySymbolsData, 'Default currency option for USD is missing.');
$this->assertArrayHasKey('EUR', $currencySymbolsData, 'Default currency option for EUR is missing.');
}
/**
* @magentoDbIsolation enabled
*/
public function testSetEmptyCurrencySymbolsData()
{
$currencySymbolsDataBefore = $this->currencySymbolModel->getCurrencySymbolsData();
$this->currencySymbolModel->setCurrencySymbolsData([]);
$currencySymbolsDataAfter = $this->currencySymbolModel->getCurrencySymbolsData();
//Make sure symbol data is unchanged
$this->assertEquals($currencySymbolsDataBefore, $currencySymbolsDataAfter);
}
/**
* @magentoDbIsolation enabled
*/
public function testSetCurrencySymbolsData()
{
$currencySymbolsData = $this->currencySymbolModel->getCurrencySymbolsData();
$this->assertArrayHasKey('EUR', $currencySymbolsData);
//Change currency symbol
$currencySymbolsData = [
'EUR' => '@',
];
$this->currencySymbolModel->setCurrencySymbolsData($currencySymbolsData);
//Verify if the new symbol is set
$this->assertEquals(
'@',
$this->currencySymbolModel->getCurrencySymbolsData()['EUR']['displaySymbol'],
'Symbol not set correctly.'
);
$this->assertEquals('@', $this->currencySymbolModel->getCurrencySymbol('EUR'), 'Symbol not set correctly.');
}
/**
* Test that method returns valid data
*
* @return void
*/
public function testGetCurrencySymbolNonExistent()
{
$this->assertFalse($this->currencySymbolModel->getCurrencySymbol('AUD'));
}
/**
* Test that default symbol can be set to use explicitly in the system
*
* @return void
*/
public function testSetCurrencySymbolLikeParent()
{
$currencySymbolsData = ['USD' => '$'];
$this->currencySymbolModel->setCurrencySymbolsData($currencySymbolsData);
//Verify if the new symbol is set
$this->assertEquals(
'$',
$this->currencySymbolModel->getCurrencySymbolsData()['USD']['displaySymbol'],
'Symbol was not correctly set.'
);
$this->assertEquals(
false,
$this->currencySymbolModel->getCurrencySymbolsData()['USD']['inherited'],
'Symbol\'s inheritance was not correctly set.'
);
}
}