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,126 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Developer\Console\Command;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* Test for Install command.
*/
class SetupInstallTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var ComponentRegistrar
*/
private $componentRegistrar;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->cliCommand = $objectManager->get(CliCommand::class);
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->componentRegistrar = $objectManager->create(
ComponentRegistrar::class
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule8
* @moduleName Magento_TestSetupDeclarationModule9
* @throws \Exception
*/
public function testInstallWithConverting()
{
$modules = [
'Magento_TestSetupDeclarationModule8',
'Magento_TestSetupDeclarationModule9',
];
foreach ($modules as $moduleName) {
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'InstallSchema.php',
'Setup'
);
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'UpgradeSchema.php',
'Setup'
);
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'module.xml',
'etc'
);
}
$this->cliCommand->install($modules, ['convert-old-scripts' => true]);
foreach ($modules as $moduleName) {
$modulePath = $this->componentRegistrar->getPath('module', $moduleName);
$schemaFileName = $modulePath
. DIRECTORY_SEPARATOR
. \Magento\Framework\Module\Dir::MODULE_ETC_DIR
. DIRECTORY_SEPARATOR
. 'db_schema.xml';
$generatedSchema = $this->getSchemaDocument($schemaFileName);
$expectedSchemaFileName = dirname(__DIR__, 2)
. DIRECTORY_SEPARATOR
. implode(
DIRECTORY_SEPARATOR,
[
'_files',
'SetupInstall',
str_replace('Magento_', '', $moduleName),
'db_schema.xml'
]
);
$expectedSchema = $this->getSchemaDocument($expectedSchemaFileName);
$this->assertEquals($expectedSchema->saveXML(), $generatedSchema->saveXML());
}
}
/**
* Convert file content in the DOM document.
*
* @param $schemaFileName
* @return \DOMDocument
*/
private function getSchemaDocument($schemaFileName): \DOMDocument
{
$schemaDocument = new \DOMDocument();
$schemaDocument->preserveWhiteSpace = false;
$schemaDocument->formatOutput = true;
$schemaDocument->loadXML(file_get_contents($schemaFileName));
return $schemaDocument;
}
}
@@ -0,0 +1,173 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Developer\Console\Command;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\SetupTestCase;
/**
* Test for Upgrade command.
*/
class SetupUpgradeTest extends SetupTestCase
{
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var ComponentRegistrar
*/
private $componentRegistrar;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->cliCommand = $objectManager->get(CliCommand::class);
$this->moduleManager = $objectManager->get(TestModuleManager::class);
$this->componentRegistrar = $objectManager->create(
ComponentRegistrar::class
);
}
/**
* @moduleName Magento_TestSetupDeclarationModule8
* @moduleName Magento_TestSetupDeclarationModule9
* @throws \Exception
*/
public function testUpgradeWithConverting()
{
$modules = [
'Magento_TestSetupDeclarationModule8',
'Magento_TestSetupDeclarationModule9',
];
foreach ($modules as $moduleName) {
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'InstallSchema.php',
'Setup'
);
}
$this->cliCommand->install($modules, ['convert-old-scripts' => true]);
foreach ($modules as $moduleName) {
$this->assertInstallScriptChanges($moduleName);
}
foreach ($modules as $moduleName) {
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'UpgradeSchema.php',
'Setup'
);
$this->moduleManager->updateRevision(
$moduleName,
'setup_install_with_converting',
'module.xml',
'etc'
);
}
$this->cliCommand->upgrade(['convert-old-scripts' => true]);
foreach ($modules as $moduleName) {
$this->assertUpgradeScriptChanges($moduleName);
}
}
/**
* Convert file content in the DOM document.
*
* @param string $schemaFileName
* @return \DOMDocument
*/
private function getSchemaDocument(string $schemaFileName): \DOMDocument
{
$schemaDocument = new \DOMDocument();
$schemaDocument->preserveWhiteSpace = false;
$schemaDocument->formatOutput = true;
$schemaDocument->loadXML(file_get_contents($schemaFileName));
return $schemaDocument;
}
/**
* @param string $moduleName
*/
private function assertInstallScriptChanges(string $moduleName): void
{
$generatedSchema = $this->getGeneratedSchema($moduleName);
$expectedSchema = $this->getSchemaDocument($this->getSchemaFixturePath($moduleName, 'install'));
$this->assertEquals($expectedSchema->saveXML(), $generatedSchema->saveXML());
}
/**
* @param string $moduleName
*/
private function assertUpgradeScriptChanges(string $moduleName): void
{
$generatedSchema = $this->getGeneratedSchema($moduleName);
$expectedSchema = $this->getSchemaDocument($this->getSchemaFixturePath($moduleName, 'upgrade'));
$this->assertEquals($expectedSchema->saveXML(), $generatedSchema->saveXML());
}
/**
* @param string $moduleName
* @return \DOMDocument
*/
private function getGeneratedSchema(string $moduleName): \DOMDocument
{
$modulePath = $this->componentRegistrar->getPath('module', $moduleName);
$schemaFileName = $modulePath
. DIRECTORY_SEPARATOR
. \Magento\Framework\Module\Dir::MODULE_ETC_DIR
. DIRECTORY_SEPARATOR
. 'db_schema.xml';
return $this->getSchemaDocument($schemaFileName);
}
/**
* @param string $moduleName
* @param string $suffix
* @return string
*/
private function getSchemaFixturePath(string $moduleName, string $suffix): string
{
$schemaFixturePath = dirname(__DIR__, 2)
. DIRECTORY_SEPARATOR
. implode(
DIRECTORY_SEPARATOR,
[
'_files',
'SetupUpgrade',
str_replace('Magento_', '', $moduleName),
'db_schema_' . $suffix . '.xml'
]
);
return $schemaFixturePath;
}
}
@@ -0,0 +1,132 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Developer\Console\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Magento\TestFramework\TestCase\SetupTestCase;
use Magento\Framework\Console\Cli;
use Magento\TestFramework\Deploy\CliCommand;
use Magento\TestFramework\Deploy\TestModuleManager;
/**
* The purpose of this test is to verify the declaration:generate:whitelist command.
*/
class TablesWhitelistGenerateCommandTest extends SetupTestCase
{
/**
* @var CommandTester
*/
private $tester;
/**
* @var \Magento\Developer\Console\Command\TablesWhitelistGenerateCommand
*/
private $command;
/**
* @var \Magento\Framework\Component\ComponentRegistrar
*/
private $componentRegistrar;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var CliCommand
*/
private $cliCommand;
/**
* @var TestModuleManager
*/
private $moduleManager;
/**
* {@inheritdoc}
*/
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->command = $this->objectManager->create(
\Magento\Developer\Console\Command\TablesWhitelistGenerateCommand::class
);
$this->componentRegistrar = $this->objectManager->create(
\Magento\Framework\Component\ComponentRegistrar::class
);
$this->cliCommand = $this->objectManager->get(CliCommand::class);
$this->tester = new CommandTester($this->command);
$this->moduleManager = $this->objectManager->get(TestModuleManager::class);
}
/**
* Execute generate command for whitelist.
*
* @moduleName Magento_TestSetupDeclarationModule1
* @moduleName Magento_TestSetupDeclarationModule8
* @throws \Exception
*/
public function testExecute()
{
$modules = [
'Magento_TestSetupDeclarationModule1',
'Magento_TestSetupDeclarationModule8',
];
$this->cliCommand->install($modules);
foreach ($modules as $moduleName) {
$this->moduleManager->updateRevision(
$moduleName,
'whitelist_upgrade',
'db_schema.xml',
'etc'
);
}
foreach ($modules as $moduleName) {
$this->checkWhitelistFile($moduleName);
}
}
/**
* @param string $moduleName
*/
private function checkWhitelistFile(string $moduleName)
{
$modulePath = $this->componentRegistrar->getPath('module', $moduleName);
$whiteListFileName = $modulePath
. DIRECTORY_SEPARATOR
. \Magento\Framework\Module\Dir::MODULE_ETC_DIR
. DIRECTORY_SEPARATOR
. \Magento\Framework\Setup\Declaration\Schema\Diff\Diff::GENERATED_WHITELIST_FILE_NAME;
//run bin/magento declaration:generate:whitelist Magento_TestSetupDeclarationModule1 command.
$this->tester->execute(['--module-name' => $moduleName], ['interactive' => false]);
$this->assertSame(Cli::RETURN_SUCCESS, $this->tester->getStatusCode());
$this->assertFileExists($whiteListFileName);
$this->assertEmpty($this->tester->getDisplay());
$whitelistFileContent = file_get_contents($whiteListFileName);
$expectedWhitelistContent = file_get_contents(
dirname(__DIR__, 2)
. DIRECTORY_SEPARATOR
. implode(
DIRECTORY_SEPARATOR,
[
'_files',
'WhitelistGenerate',
str_replace('Magento_', '', $moduleName),
'db_schema_whitelist.json'
]
)
);
$this->assertEquals($expectedWhitelistContent, $whitelistFileContent);
}
}