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,273 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Design\Fallback;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Filesystem;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Factory Test
* @magentoComponentsDir Magento/Framework/View/_files/fallback
* @magentoDbIsolation enabled
*/
class RulePoolTest extends \PHPUnit\Framework\TestCase
{
/**
* @var RulePool
*/
protected $model;
/**
* @var array
*/
protected $defaultParams;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Theme\Model\Theme\Registration $registration */
$registration = $objectManager->get(
\Magento\Theme\Model\Theme\Registration::class
);
$registration->register();
$this->model = $objectManager->create(\Magento\Framework\View\Design\Fallback\RulePool::class);
/** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $collection */
$collection = $objectManager->create(\Magento\Theme\Model\ResourceModel\Theme\Collection::class);
/** @var \Magento\Theme\Model\Theme $theme */
$theme = $collection->getThemeByFullPath('frontend/Vendor_ViewTest/custom_theme');
$this->defaultParams = [
'area' => 'area',
'theme' => $theme,
'module_name' => 'ViewTest_Module',
'locale' => 'en_US',
];
}
protected function tearDown(): void
{
$this->model = null;
$this->defaultParams = [];
}
public function testGetRuleUnsupportedType()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Fallback rule \'unsupported_type\' is not supported');
$this->model->getRule('unsupported_type');
}
/**
* @param string $type
* @param array $overriddenParams
* @param string $expectedErrorMessage
*
* @dataProvider getPatternDirsExceptionDataProvider
*/
public function testGetPatternDirsException($type, array $overriddenParams, $expectedErrorMessage)
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage($expectedErrorMessage);
$params = $overriddenParams + $this->defaultParams;
$this->model->getRule($type)->getPatternDirs($params);
}
/**
* @return array
*/
public function getPatternDirsExceptionDataProvider()
{
$exceptions = [
'no theme' => [
['theme' => null],
'Parameter "theme" should be specified and should implement the theme interface',
],
'no area' => [
['area' => null],
"Required parameter 'area' was not passed",
],
];
$exceptionsPerTypes = [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_LOCALE_FILE => [
'no theme',
],
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_FILE => [
'no theme', 'no area',
],
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_TEMPLATE_FILE => [
'no theme', 'no area',
],
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE => [
'no theme', 'no area',
],
];
$data = [];
foreach ($exceptionsPerTypes as $type => $exceptionKeys) {
foreach ($exceptionKeys as $key) {
$data[$type . ', ' . $key] = [$type, $exceptions[$key][0], $exceptions[$key][1]];
}
}
return $data;
}
/**
* @param string $type
* @param array $overriddenParams
* @param array $expectedResult
*
* @dataProvider getPatternDirsDataProvider
*/
public function testGetPatternDirs($type, array $overriddenParams, array $expectedResult)
{
$actualResult = $this->model->getRule($type)
->getPatternDirs($overriddenParams + $this->defaultParams);
$this->assertEquals($expectedResult, $actualResult);
}
/**
* @return array
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getPatternDirsDataProvider()
{
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar */
$componentRegistrar = $objectManager->get(
\Magento\Framework\Component\ComponentRegistrarInterface::class
);
$coreModulePath = $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Theme');
/** @var \Magento\Framework\Filesystem $filesystem */
$filesystem = $objectManager->get(\Magento\Framework\Filesystem::class);
$libPath = rtrim($filesystem->getDirectoryRead(DirectoryList::LIB_WEB)->getAbsolutePath(), '/');
$themeOnePath = BP . '/dev/tests/integration/testsuite/Magento/Framework/View/_files/fallback/design/frontend/'
. 'Vendor/custom_theme';
$themeTwoPath = BP . '/dev/tests/integration/testsuite/Magento/Framework/View/_files/fallback/design/frontend/'
. 'Vendor/default';
$modulePath = BP . '/dev/tests/integration/testsuite/Magento/Framework/View/_files/fallback/app/code/'
. 'ViewTest_Module';
return [
'locale' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_LOCALE_FILE,
[],
[
$themeOnePath,
$themeTwoPath,
],
],
'file, modular' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_FILE,
[],
[
$themeOnePath . '/ViewTest_Module',
$themeTwoPath . '/ViewTest_Module',
$modulePath . '/view/area',
$modulePath . '/view/base',
],
],
'file, non-modular' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_FILE,
['namespace' => null, 'module_name' => null],
[
$themeOnePath,
$themeTwoPath,
],
],
'template, modular' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_TEMPLATE_FILE,
[],
[
$themeOnePath . '/ViewTest_Module/templates',
$themeTwoPath . '/ViewTest_Module/templates',
$modulePath . '/view/area/templates',
$modulePath . '/view/base/templates',
],
],
'template, non-modular' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_TEMPLATE_FILE,
['namespace' => null, 'module_name' => null],
[
$themeOnePath . '/templates',
$themeTwoPath . '/templates',
],
],
'template, non-modular-magento-core' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_TEMPLATE_FILE,
['module_name' => 'Magento_Theme'],
[
$themeOnePath . '/Magento_Theme/templates',
$themeTwoPath . '/Magento_Theme/templates',
$coreModulePath . '/view/area/templates',
$coreModulePath . '/view/base/templates',
],
],
'view, modular localized' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE,
[],
[
$themeOnePath . '/ViewTest_Module/web/i18n/en_US',
$themeOnePath . '/ViewTest_Module/web',
$themeTwoPath . '/ViewTest_Module/web/i18n/en_US',
$themeTwoPath . '/ViewTest_Module/web',
$modulePath . '/view/area/web/i18n/en_US',
$modulePath . '/view/base/web/i18n/en_US',
$modulePath . '/view/area/web',
$modulePath . '/view/base/web',
],
],
'view, modular non-localized' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE,
['locale' => null],
[
$themeOnePath . '/ViewTest_Module/web',
$themeTwoPath . '/ViewTest_Module/web',
$modulePath . '/view/area/web',
$modulePath . '/view/base/web',
],
],
'view, non-modular localized' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE,
['module_name' => null],
[
$themeOnePath . '/web/i18n/en_US',
$themeOnePath . '/web',
$themeTwoPath . '/web/i18n/en_US',
$themeTwoPath . '/web',
$libPath,
],
],
'view, non-modular non-localized' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE,
['module_name' => null, 'locale' => null],
[
$themeOnePath . '/web',
$themeTwoPath . '/web',
$libPath,
],
],
// Single test, as emails will always be loaded in a modular context with no locale specificity
'email' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_EMAIL_TEMPLATE,
[],
[
$themeOnePath . '/ViewTest_Module/email',
$themeTwoPath . '/ViewTest_Module/email',
$modulePath . '/view/area/email',
],
],
];
}
}
@@ -0,0 +1,319 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Design\FileResolution;
use Magento\Framework\App\Bootstrap as AppBootstrap;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoComponentsDir Magento/Framework/View/_files/fallback
* @magentoDbIsolation enabled
*/
class FallbackTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\Design\Theme\FlyweightFactory
*/
private $themeFactory;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Theme\Model\Theme\Registration $registration */
$registration = $objectManager->get(
\Magento\Theme\Model\Theme\Registration::class
);
$registration->register();
/** @var \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory */
$this->themeFactory = $objectManager
->get(\Magento\Framework\View\Design\Theme\FlyweightFactory::class);
}
/**
* Reinitialize environment with test directories
*
* Since the testGetEmailTemplateFile test uses a @magentoDataFixture that reinitializes the environment, we
* must reinitialize the environment only when a test specifically requests it
*
* @return void
*/
protected function reinitializeEnvironment()
{
Bootstrap::getInstance()->reinitialize([
AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => [
DirectoryList::LIB_WEB => [
'path' => __DIR__ . '/../../_files/fallback/lib/web',
],
],
]);
}
/**
* @param string $file
* @param string $themePath
* @param string|null $module
* @param string|null $expectedFilename
*
* @dataProvider getTemplateFileDataProvider
*/
public function testGetTemplateFile($file, $themePath, $module, $expectedFilename)
{
$this->reinitializeEnvironment();
/** @var \Magento\Framework\View\Design\FileResolution\Fallback\TemplateFile $model */
$model = Bootstrap::getObjectManager()
->create(\Magento\Framework\View\Design\FileResolution\Fallback\TemplateFile::class);
$themeModel = $this->themeFactory->create($themePath);
$actualFilename = $model->getFile('frontend', $themeModel, $file, $module);
if ($expectedFilename) {
$this->assertIsString($actualFilename);
$this->assertStringMatchesFormat($expectedFilename, $actualFilename);
$this->assertFileExists($actualFilename);
} else {
$this->assertFalse($actualFilename);
}
}
/**
* @return array
*/
public function getTemplateFileDataProvider()
{
return [
'non-modular: no default inheritance' => [
'fixture_template.phtml', 'Vendor_ViewTest/standalone_theme', null,
null,
],
'non-modular: inherit parent theme' => [
'fixture_template.phtml', 'Vendor_ViewTest/custom_theme', null,
'%s/frontend/Vendor/default/templates/fixture_template.phtml',
],
'non-modular: inherit grandparent theme' => [
'fixture_template.phtml', 'Vendor_ViewTest/custom_theme2', null,
'%s/frontend/Vendor/default/templates/fixture_template.phtml',
],
'modular: no default inheritance' => [
'fixture_template.phtml', 'Vendor_ViewTest/standalone_theme', 'ViewTest_Module',
null,
],
'modular: no fallback to non-modular file' => [
'nonexistent_fixture_script.phtml', 'Vendor_ViewTest/default', 'ViewTest_Module',
null,
],
'modular: inherit parent theme' => [
'fixture_template.phtml', 'Vendor_ViewTest/custom_theme', 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/templates/fixture_template.phtml',
],
'modular: inherit grandparent theme' => [
'fixture_template.phtml', 'Vendor_ViewTest/custom_theme2', 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/templates/fixture_template.phtml',
],
];
}
/**
* @param string $themePath
* @param string $locale
* @param string|null $expectedFilename
*
* @dataProvider getLocaleFileDataProvider
*/
public function testGetI18nCsvFile($themePath, $locale, $expectedFilename)
{
$this->reinitializeEnvironment();
/** @var \Magento\Framework\View\Design\FileResolution\Fallback\File $model */
$model = Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\FileResolution\Fallback\File::class
);
$themeModel = $this->themeFactory->create($themePath);
$actualFilename = $model->getFile('frontend', $themeModel, 'i18n/' . $locale . '.csv');
if ($expectedFilename) {
$this->assertIsString($actualFilename);
$this->assertStringMatchesFormat($expectedFilename, $actualFilename);
$this->assertFileExists($actualFilename);
} else {
$this->assertFalse($actualFilename);
}
}
public function getLocaleFileDataProvider()
{
return [
'no default inheritance' => [
'Vendor_ViewTest/standalone_theme', 'en_US',
null,
],
'inherit parent theme' => [
'Vendor_ViewTest/custom_theme', 'en_US',
'%s/frontend/Vendor/custom_theme/i18n/en_US.csv',
],
'inherit grandparent theme' => [
'Vendor_ViewTest/custom_theme2', 'en_US',
'%s/frontend/Vendor/custom_theme/i18n/en_US.csv',
],
];
}
/**
* Test for the static files fallback according to the themes inheritance
*
* @param string $file
* @param string $themePath
* @param string $locale
* @param string $module
* @param string|null $expectedFilename
*
* @dataProvider getViewFileDataProvider
*/
public function testGetViewFile($file, $themePath, $locale, $module, $expectedFilename)
{
$this->reinitializeEnvironment();
/** @var \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile $model */
$model = Bootstrap::getObjectManager()
->create(\Magento\Framework\View\Design\FileResolution\Fallback\StaticFile::class);
$themeModel = $this->themeFactory->create($themePath);
$actualFilename = $model->getFile('frontend', $themeModel, $locale, $file, $module);
if ($expectedFilename) {
$this->assertIsString($actualFilename);
$this->assertStringMatchesFormat($expectedFilename, $actualFilename);
$this->assertFileExists($actualFilename);
} else {
$this->assertFalse($actualFilename);
}
}
public function getViewFileDataProvider()
{
return [
'non-modular: no default inheritance' => [
'fixture_script.js', 'Vendor_ViewTest/standalone_theme', null, null,
null,
],
'non-modular: inherit same package & parent theme' => [
'fixture_script.js', 'Vendor_ViewTest/custom_theme', null, null,
'%s/frontend/Vendor/default/web/fixture_script.js',
],
'non-modular: inherit same package & grandparent theme' => [
'fixture_script.js', 'Vendor_ViewTest/custom_theme2', null, null,
'%s/frontend/Vendor/default/web/fixture_script.js',
],
'non-modular: fallback to non-localized file' => [
'fixture_script.js', 'Vendor_ViewTest/default', 'en_US', null,
'%s/frontend/Vendor/default/web/fixture_script.js',
],
'non-modular: localized file' => [
'fixture_script.js', 'Vendor_ViewTest/default', 'ru_RU', null,
'%s/frontend/Vendor/default/web/i18n/ru_RU/fixture_script.js',
],
'non-modular: override js lib file' => [
'mage/script.js', 'Vendor_ViewTest/custom_theme', null, null,
'%s/frontend/Vendor/custom_theme/web/mage/script.js',
],
'non-modular: inherit js lib file' => [
'mage/script.js', 'Vendor_ViewTest/default', null, null,
'%s/lib/web/mage/script.js',
],
'modular: no default inheritance' => [
'fixture_script.js', 'Vendor_ViewTest/standalone_theme', null, 'ViewTest_Module',
null,
],
'modular: no fallback to non-modular file' => [
'nonexistent_fixture_script.js', 'Vendor_ViewTest/default', null, 'ViewTest_Module',
null,
],
'modular: no fallback to js lib file' => [
'mage/script.js', 'Vendor_ViewTest/default', null, 'ViewTest_Module',
null,
],
'modular: no fallback to non-modular localized file' => [
'nonexistent_fixture_script.js', 'Vendor_ViewTest/default', 'ru_RU', 'ViewTest_Module',
null,
],
'modular: inherit same package & parent theme' => [
'fixture_script.js', 'Vendor_ViewTest/custom_theme', null, 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/web/fixture_script.js',
],
'modular: inherit same package & grandparent theme' => [
'fixture_script.js', 'Vendor_ViewTest/custom_theme2', null, 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/web/fixture_script.js',
],
'modular: fallback to non-localized file' => [
'fixture_script.js', 'Vendor_ViewTest/default', 'en_US', 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/web/fixture_script.js',
],
'modular: localized file' => [
'fixture_script.js', 'Vendor_ViewTest/custom_theme2', 'ru_RU', 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/web/i18n/ru_RU/fixture_script.js',
],
];
}
/**
* Test for the email template files fallback according to the themes inheritance
*
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
* @magentoComponentsDir Magento/Email/Model/_files/design
*
* @param string $file
* @param string $themePath
* @param string $module
* @param string|null $expectedFilename
*
* @dataProvider getEmailTemplateFileDataProvider
*/
public function testGetEmailTemplateFile($file, $themePath, $module, $expectedFilename)
{
$area = \Magento\Framework\App\Area::AREA_FRONTEND;
/** @var \Magento\Framework\View\Design\FileResolution\Fallback\EmailTemplateFile $model */
$model = Bootstrap::getObjectManager()
->create(\Magento\Framework\View\Design\FileResolution\Fallback\EmailTemplateFile::class);
$themeModel = $this->themeFactory->create($themePath);
$locale = \Magento\Setup\Module\I18n\Locale::DEFAULT_SYSTEM_LOCALE;
$actualFilename = $model->getFile($area, $themeModel, $locale, $file, $module);
if ($expectedFilename) {
$this->assertIsString($actualFilename);
$this->assertStringMatchesFormat($expectedFilename, $actualFilename);
$this->assertFileExists($actualFilename);
} else {
$this->assertFalse($actualFilename);
}
}
/**
* @return array
*/
public function getEmailTemplateFileDataProvider()
{
return [
'no fallback' => [
'account_new.html',
'Vendor_EmailTest/custom_theme',
'Magento_Customer',
'%s/frontend/Vendor/custom_theme/Magento_Customer/email/account_new.html',
],
'inherit same package & parent theme' => [
'account_new_confirmation.html',
'Vendor_EmailTest/custom_theme',
'Magento_Customer',
'%s/frontend/Vendor/default/Magento_Customer/email/account_new_confirmation.html',
],
'inherit parent package & grandparent theme' => [
'account_new_confirmed.html',
'Vendor_EmailTest/custom_theme',
'Magento_Customer',
'%s/frontend/Magento/default/Magento_Customer/email/account_new_confirmed.html',
],
];
}
}
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Design\Theme;
class LabelTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\Design\Theme\Label
*/
protected $_model;
protected function setUp(): void
{
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\Theme\Label::class
);
}
/**
* @covers \Magento\Framework\View\Design\Theme\Label::getLabelsCollection
*/
public function testGetLabelsCollection()
{
/** @var $expectedCollection \Magento\Theme\Model\ResourceModel\Theme\Collection */
$expectedCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\Theme\Label\ListInterface::class
);
$expectedItemsCount = count($expectedCollection->getLabels());
$labelsCollection = $this->_model->getLabelsCollection();
$this->assertEquals($expectedItemsCount, count($labelsCollection));
$labelsCollection = $this->_model->getLabelsCollection('-- Please Select --');
$this->assertEquals(++$expectedItemsCount, count($labelsCollection));
}
}
@@ -0,0 +1,89 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Test theme data validator
*/
namespace Magento\Framework\View\Design\Theme;
class ValidatorTest extends \PHPUnit\Framework\TestCase
{
/**
* Test validator with valid data
*/
public function testValidateWithValidData()
{
/** @var $validator \Magento\Framework\View\Design\Theme\Validator */
$validator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\Theme\Validator::class
);
$themeModel = $this->_getThemeModel();
$themeModel->setData($this->_getThemeValidData());
$this->assertTrue($validator->validate($themeModel));
}
/**
* Test validator with invalid data
*/
public function testValidateWithInvalidData()
{
/** @var $validator \Magento\Framework\View\Design\Theme\Validator */
$validator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\Theme\Validator::class
);
$themeModel = $this->_getThemeModel();
$themeModel->setData($this->_getThemeInvalidData());
$this->assertFalse($validator->validate($themeModel));
}
/**
* Get theme model
*
* @return \Magento\Framework\Model\AbstractModel
*/
protected function _getThemeModel()
{
return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\ThemeInterface::class
);
}
/**
* Get theme valid data
*
* @return array
*/
protected function _getThemeValidData()
{
return [
'theme_code' => 'space',
'theme_title' => 'Space theme',
'parent_theme' => null,
'theme_path' => 'default/space',
'preview_image' => 'images/preview.png'
];
}
/**
* Get theme invalid data
*
* @return array
*/
protected function _getThemeInvalidData()
{
return [
'theme_code' => 'space',
'theme_title' => '',
'parent_theme' => null,
'theme_path' => 'default/space',
'preview_image' => 'images/preview.png'
];
}
}