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,136 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Translation\Model;
use Magento\Framework\App\Config\MutableScopeConfigInterface;
use Magento\Framework\App\State;
use Magento\Framework\Translate\Inline;
use Magento\Framework\App\Area;
use Magento\Store\Model\ScopeInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Translation\Model\Inline\Parser;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
/**
* Test for \Magento\Translation\Model\Inline\Parser.
*/
class InlineParserTest extends TestCase
{
private const STUB_STORE = 'default';
private const XML_PATH_TRANSLATE_INLINE_ACTIVE = 'dev/translate_inline/active';
/**
* @var Parser
*/
private $model;
/**
* @inheritDoc
*/
protected function setUp(): void
{
$inline = Bootstrap::getObjectManager()->create(Inline::class);
$this->model = Bootstrap::getObjectManager()->create(Parser::class, ['translateInline' => $inline]);
Bootstrap::getObjectManager()->get(MutableScopeConfigInterface::class)
->setValue(self::XML_PATH_TRANSLATE_INLINE_ACTIVE, true, ScopeInterface::SCOPE_STORE, self::STUB_STORE);
}
/**
* Process ajax post test
*
* @dataProvider processAjaxPostDataProvider
*
* @param string $originalText
* @param string $translatedText
* @param string $area
* @param bool|null $isPerStore
* @return void
*/
public function testProcessAjaxPost(
string $originalText,
string $translatedText,
string $area,
?bool $isPerStore = null
): void {
Bootstrap::getObjectManager()->get(State::class)
->setAreaCode($area);
$inputArray = [['original' => $originalText, 'custom' => $translatedText]];
if ($isPerStore !== null) {
$inputArray[0]['perstore'] = $isPerStore;
}
$this->model->processAjaxPost($inputArray);
$model = Bootstrap::getObjectManager()->create(StringUtils::class);
$model->load($originalText);
try {
$this->assertEquals($translatedText, $model->getTranslate());
$model->delete();
} catch (\Exception $e) {
$model->delete();
Bootstrap::getObjectManager()->get(LoggerInterface::class)
->critical($e);
}
}
/**
* Data provider for testProcessAjaxPost
*
* @return array
*/
public function processAjaxPostDataProvider(): array
{
return [
['original text 1', 'translated text 1', Area::AREA_ADMINHTML],
['original text 1', 'translated text 1', Area::AREA_FRONTEND],
['original text 2', 'translated text 2', Area::AREA_ADMINHTML, true],
['original text 2', 'translated text 2', Area::AREA_FRONTEND, true],
];
}
/**
* Set get is json test
*
* @dataProvider allowedAreasDataProvider
*
* @param string $area
* @return void
*/
public function testSetGetIsJson(string $area): void
{
Bootstrap::getObjectManager()->get(State::class)
->setAreaCode($area);
$isJsonProperty = new \ReflectionProperty(get_class($this->model), '_isJson');
$isJsonProperty->setAccessible(true);
$this->assertFalse($isJsonProperty->getValue($this->model));
$setIsJsonMethod = new \ReflectionMethod($this->model, 'setIsJson');
$setIsJsonMethod->setAccessible(true);
$setIsJsonMethod->invoke($this->model, true);
$this->assertTrue($isJsonProperty->getValue($this->model));
}
/**
* Data provider for testSetGetIsJson
*
* @return array
*/
public function allowedAreasDataProvider(): array
{
return [
[Area::AREA_ADMINHTML],
[Area::AREA_FRONTEND]
];
}
}
@@ -0,0 +1,74 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Translation\Model\Js;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\TranslateInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Translation\Model\ResourceModel\StringUtils;
use PHPUnit\Framework\TestCase;
/**
* Integration tests for \Magento\Translation\Model\Js\DataProvider class.
*/
class DataProviderTest extends TestCase
{
/**
* @var StringUtils
*/
private $stringUtils;
/**
* @var TranslateInterface
*/
private $translate;
/**
* @var DataProviderInterface
*/
private $translationDataProvider;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->stringUtils = $objectManager->get(StringUtils::class);
$this->translate = $objectManager->get(TranslateInterface::class);
$this->translationDataProvider = $objectManager->get(DataProviderInterface::class);
}
/**
* Test translation data.
*
* @magentoAppArea frontend
* @magentoConfigFixture default_store dev/translate_inline/active 1
*/
public function testGetData()
{
$expectedDictionary = ['Proceed to Checkout' => 'Proceed to Checkout - Translated'];
$this->stringUtils->saveTranslate('Proceed to Checkout', 'Proceed to Checkout - Translated');
$this->translate->setLocale('en_US')->loadData('frontend', true);
$dictionary = $this->translationDataProvider->getData('Magento/luma');
$this->assertEquals($expectedDictionary, $dictionary);
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
try {
$this->stringUtils->deleteTranslate('Proceed to Checkout');
} catch (NoSuchEntityException $exception) {
// translate already deleted
}
}
}
@@ -0,0 +1,188 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Translation\Model\Js;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\View\FileSystem;
use Magento\TestFramework\Helper\CacheCleaner;
use Magento\Framework\Translate;
use Magento\Framework\App\AreaList;
use Magento\Framework\Phrase;
use Magento\Framework\Phrase\RendererInterface;
/**
* Class for testing translation.
*/
class PreProcessorTest extends \PHPUnit\Framework\TestCase
{
/**
* @var PreProcessor
*/
private $model;
/**
* @var RendererInterface
*/
private $origRenderer;
/**
* Set up.
*/
protected function setUp(): void
{
$viewFileSystem = $this->createPartialMock(FileSystem::class, ['getLocaleFileName']);
$viewFileSystem->expects($this->any())->method('getLocaleFileName')
->willReturn(
// phpcs:ignore Magento2.Functions.DiscouragedFunction
dirname(__DIR__) . '/_files/Magento/Store/i18n/en_AU.csv'
);
$objectManager = Bootstrap::getObjectManager();
$objectManager->addSharedInstance($viewFileSystem, FileSystem::class);
$translator = $objectManager->create(Translate::class);
$objectManager->addSharedInstance($translator, Translate::class);
$areaList = $this->getMockBuilder(AreaList::class)->disableOriginalConstructor()->getMock();
$this->origRenderer = Phrase::getRenderer();
Phrase::setRenderer(
$objectManager->get(RendererInterface::class)
);
$this->model = $objectManager->create(
PreProcessor::class,
[
'translate' => $translator,
'areaList' => $areaList
]
);
$translator->setLocale('en_AU');
$translator->loadData();
}
/**
* Tear down.
*/
protected function tearDown(): void
{
Phrase::setRenderer($this->origRenderer);
}
/**
* Test for backend translation strategy.
*
* @param string $content
* @param string $translation
* @return void
* @dataProvider contentForTranslateDataProvider
*/
public function testProcess(string $content, string $translation)
{
$this->assertEquals($translation, $this->model->translate($content));
}
/**
* Data provider for translation.
*
* @return array
*/
public function contentForTranslateDataProvider()
{
return [
'i18n_js_file_error' => [
'setTranslateProp = function (el, original) {
var location = $(el).prop(\'tagName\').toLowerCase(),
translated = $.mage.__(original),
translationData = {
shown: translated,
translated: translated,
original: original
},
translateAttr = composeTranslateAttr(translationData, location);
$(el).attr(\'data-translate\', translateAttr);
setText(el, translationData.shown);
},',
'setTranslateProp = function (el, original) {
var location = $(el).prop(\'tagName\').toLowerCase(),
translated = $.mage.__(original),
translationData = {
shown: translated,
translated: translated,
original: original
},
translateAttr = composeTranslateAttr(translationData, location);
$(el).attr(\'data-translate\', translateAttr);
setText(el, translationData.shown);
},'
],
'checkTranslationWithWhiteSpaces' => [
<<<i18n
title: $.mage.__(
'Original value for Magento_Store module'
),
title: \$t(
'Original value for Magento_Store module'
);
title: jQuery.mage.__(
'Original value for Magento_Store module'
);
i18n
,
<<<i18n
title: 'Translated value for Magento_Store module in en_AU',
title: 'Translated value for Magento_Store module in en_AU';
title: 'Translated value for Magento_Store module in en_AU';
i18n
],
'checkTranslationWithReplace' => [
<<<i18n
$.mage.__('The maximum you may purchase is %1.').replace('%1', params.maxAllowed);
\$t('The maximum you may purchase is %1.').replace('%1', params.maxAllowed);
i18n
,
<<<i18n
'The maximum you may purchase is %1.'.replace('%1', params.maxAllowed);
'The maximum you may purchase is %1.'.replace('%1', params.maxAllowed);
i18n
],
'checkAvoidingMatchingWithJsInString' => [
<<<i18n
\$t('Payment ' + this.getTitle() + ' can\'t be initialized')
\$t(
'Set unique country-state combinations within the same fixed product tax. ' +
'Verify the combinations and try again.'
)
i18n
,
<<<i18n
\$t('Payment ' + this.getTitle() + ' can\'t be initialized')
\$t(
'Set unique country-state combinations within the same fixed product tax. ' +
'Verify the combinations and try again.'
)
i18n
],
'checkAvoidMatchingPhtml' => [
<<<i18n
globalMessageList.addErrorMessage({
message: \$t(<?= /* @noEscape */ json_encode(\$params['error_msg'])?>)
});
i18n
,
<<<i18n
globalMessageList.addErrorMessage({
message: \$t(<?= /* @noEscape */ json_encode(\$params['error_msg'])?>)
});
i18n
]
];
}
}
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Translation\Model;
class StringTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Translation\Model\StringUtils
*/
protected $_model;
protected function setUp(): void
{
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Translation\Model\StringUtils::class
);
}
public function testConstructor()
{
$this->assertInstanceOf(
\Magento\Translation\Model\ResourceModel\StringUtils::class,
$this->_model->getResource()
);
}
public function testSetGetString()
{
$expectedString = __METHOD__;
$this->_model->setString($expectedString);
$actualString = $this->_model->getString();
$this->assertEquals($expectedString, $actualString);
}
}
@@ -0,0 +1,4 @@
"%s - %s","%s - %s"
"Some non-translated value for Magento_Catalog","Translation for some value for Magento_Catalog"
"Another non-translated value for Magento_Catalog","Translation for another value for Magento_Catalog"
"Text with different translation on different modules","Text translation that was last loaded"
1 %s - %s %s - %s
2 Some non-translated value for Magento_Catalog Translation for some value for Magento_Catalog
3 Another non-translated value for Magento_Catalog Translation for another value for Magento_Catalog
4 Text with different translation on different modules Text translation that was last loaded
@@ -0,0 +1 @@
"Original value for Magento_Store module","Translated value for Magento_Store module in en_AU"
1 Original value for Magento_Store module Translated value for Magento_Store module in en_AU
@@ -0,0 +1 @@
"Text with different translation on different modules","Text translation by Magento_Store module in en_UK"
1 Text with different translation on different modules Text translation by Magento_Store module in en_UK
@@ -0,0 +1,3 @@
"%s","%s"
"Original value for Magento_Store module","Translated value for Magento_Store module"
"Text with different translation on different modules","Text translation that was last loaded"
1 %s %s
2 Original value for Magento_Store module Translated value for Magento_Store module
3 Text with different translation on different modules Text translation that was last loaded
@@ -0,0 +1,3 @@
"Theme phrase will be translated","Theme phrase is translated"
"Magento_Catalog module phrase will be overridden by theme translation","Magento_Catalog module phrase is overridden by theme translation"
"Magento_Store module phrase will be overridden by theme translation","Magento_Store module phrase is overridden by theme translation"
1 Theme phrase will be translated Theme phrase is translated
2 Magento_Catalog module phrase will be overridden by theme translation Magento_Catalog module phrase is overridden by theme translation
3 Magento_Store module phrase will be overridden by theme translation Magento_Store module phrase is overridden by theme translation
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<root>
<global>
<resources>
<core_setup>
<connection>
<model>custom</model>
</connection>
</core_setup>
</resources>
</global>
</root>
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<root>
<global>
<resources>
<core_setup>
<connection>
<model>prohibited_value</model>
</connection>
</core_setup>
</resources>
</global>
</root>
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<root>
<global>
<resources>
<core_setup>
<connection>
<model>local</model>
</connection>
</core_setup>
</resources>
</global>
</root>
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<root>
<global>
<resources>
<core_setup>
<connection>
<model>z</model>
</connection>
</core_setup>
</resources>
</global>
</root>
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<root>
<global>
<resources>
<core_setup>
<connection>
<model>a</model>
</connection>
</core_setup>
</resources>
</global>
</root>
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<root>
<global>
<resources>
<core_setup>
<connection>
<model>b</model>
</connection>
</core_setup>
</resources>
</global>
</root>
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<root>
<global>
<resources>
<core_setup>
<connection>
<model>custom</model>
</connection>
</core_setup>
</resources>
</global>
</root>
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<locale>
<inheritance>
<en_AU>en_UK</en_AU>
</inheritance>
</locale>
</default>
</config>