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,141 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Developer\Console\Command;
use Magento\TestFramework\Helper\Bootstrap;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class SourceThemeDeployCommandTest
*
* @see \Magento\Developer\Console\Command\SourceThemeDeployCommand
*/
class SourceThemeDeployCommandTest extends \PHPUnit\Framework\TestCase
{
const PUB_STATIC_DIRECTORY = 'pub/static';
const AREA_TEST_VALUE = 'frontend';
const LOCALE_TEST_VALUE = 'en_US';
const THEME_TEST_VALUE = 'Magento/luma';
const TYPE_TEST_VALUE = 'less';
/**
* @var SourceThemeDeployCommand
*/
private $command;
/**
* @var string
*/
private $pubStatic;
/**
* @var array
*/
private $compiledFiles = ['css/styles-m', 'css/styles-l'];
/**
* Set up
*/
protected function setUp(): void
{
global $installDir;
$this->pubStatic = $installDir . DIRECTORY_SEPARATOR . self::PUB_STATIC_DIRECTORY;
$this->command = Bootstrap::getObjectManager()->get(SourceThemeDeployCommand::class);
}
/**
* Run test for execute method
*/
public function testExecute()
{
$error = [];
/** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject $outputMock */
$outputMock = $this->getMockBuilder(OutputInterface::class)
->getMockForAbstractClass();
$this->clearStaticDirectory();
$this->command->run($this->getInputMock(), $outputMock);
/** @var \SplFileInfo $file */
foreach ($this->collectFiles($this->pubStatic) as $file) {
$fileInfo = pathinfo($file->getFilename());
if (!in_array('css/' . $fileInfo['filename'], $this->compiledFiles, true)
&& !$file->isLink()
) {
$error[] = 'Bad file -> ' . $file->getFilename() . PHP_EOL;
}
}
$this->clearStaticDirectory();
self::assertEmpty($error, implode($error));
}
/**
* @return void
*/
private function clearStaticDirectory()
{
if (is_dir($this->pubStatic)) {
/** @var \SplFileInfo $file */
foreach ($this->collectFiles($this->pubStatic) as $file) {
@unlink($file->getPathname());
}
}
}
/**
* @param string $path
* @return \RegexIterator|array
*/
private function collectFiles($path)
{
$flags = \FilesystemIterator::CURRENT_AS_FILEINFO
| \FilesystemIterator::SKIP_DOTS;
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, $flags));
return new \RegexIterator(
$iterator,
'#\.less$#',
\RegexIterator::MATCH,
\RegexIterator::USE_KEY
);
}
/**
* @return InputInterface|\PHPUnit\Framework\MockObject\MockObject
*/
private function getInputMock()
{
$inputMock = $this->getMockBuilder(InputInterface::class)
->getMockForAbstractClass();
$inputMock->expects(self::exactly(4))
->method('getOption')
->willReturnMap(
[
['area', self::AREA_TEST_VALUE],
['locale', self::LOCALE_TEST_VALUE],
['theme', self::THEME_TEST_VALUE],
['type', self::TYPE_TEST_VALUE]
]
);
$inputMock->expects(self::once())
->method('getArgument')
->with('file')
->willReturn($this->compiledFiles);
return $inputMock;
}
}
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Developer\Helper;
use \Laminas\Stdlib\Parameters;
class DataTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Developer\Helper\Data
*/
protected $helper = null;
protected function setUp(): void
{
$this->helper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Developer\Helper\Data::class
);
}
/**
* @magentoAppIsolation enabled
*/
public function testIsDevAllowedDefault()
{
$this->assertTrue($this->helper->isDevAllowed());
}
/**
* @magentoConfigFixture current_store dev/restrict/allow_ips 192.168.0.1
* @magentoAppIsolation enabled
*/
public function testIsDevAllowedTrue()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\TestFramework\Request $request */
$request = $objectManager->get(\Magento\TestFramework\Request::class);
$request->setServer(new Parameters(['REMOTE_ADDR' => '192.168.0.1']));
$this->assertTrue($this->helper->isDevAllowed());
}
/**
* @magentoConfigFixture current_store dev/restrict/allow_ips 192.168.0.1
* @magentoAppIsolation enabled
*/
public function testIsDevAllowedFalse()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\TestFramework\Request $request */
$request = $objectManager->get(\Magento\TestFramework\Request::class);
$request->setServer(new Parameters(['REMOTE_ADDR' => '192.168.0.3']));
$this->assertFalse($this->helper->isDevAllowed());
}
}
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Developer\Model\Config\Backend;
class AllowedIpsTest extends \PHPUnit\Framework\TestCase
{
/**
* @param string $value
* @param string $expected
* @magentoDbIsolation enabled
* @dataProvider fieldDataProvider
*/
public function testSaveWithEscapeHtml($value, $expected)
{
/**
* @var \Magento\Developer\Model\Config\Backend\AllowedIps
*/
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Developer\Model\Config\Backend\AllowedIps::class
);
$model->setValue($value);
$model->setPath('path');
$model->beforeSave();
$model->save();
$this->assertEquals($expected, $model->getValue());
}
/**
* @return array
*/
public function fieldDataProvider()
{
return [
['<'.'script>alert(\'XSS\')</script>', '' ],
['10.64.202.22, <'.'script>alert(\'XSS\')</script>', '10.64.202.22' ]
];
}
}
@@ -0,0 +1,242 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Developer\Model\Logger\Handler;
use Magento\Config\Setup\ConfigOptionsList;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\State;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\Logger\Monolog;
use Magento\Framework\Shell;
use Magento\Setup\Mvc\Bootstrap\InitParamListener;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\ObjectManager;
use Psr\Log\LoggerInterface;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @magentoAppIsolation enabled
*/
class DebugTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Monolog
*/
private $logger;
/**
* @var WriteInterface
*/
private $etcDirectory;
/**
* @var ObjectManager
*/
private $objectManager;
/**
* @var Shell
*/
private $shell;
/**
* @var DeploymentConfig
*/
private $deploymentConfig;
/**
* @var string
*/
private $debugLogPath = '';
/**
* @var string
*/
private static $backupFile = 'env.base.php';
/**
* @var string
*/
private static $configFile = 'env.php';
/**
* @var Debug
*/
private $debugHandler;
/**
* @inheritdoc
* @throws \Magento\Framework\Exception\FileSystemException
* @throws \Exception
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->shell = $this->objectManager->get(Shell::class);
$this->logger = $this->objectManager->get(LoggerInterface::class);
$this->deploymentConfig = $this->objectManager->get(DeploymentConfig::class);
/** @var Filesystem $filesystem */
$filesystem = $this->objectManager->create(Filesystem::class);
$this->etcDirectory = $filesystem->getDirectoryWrite(DirectoryList::CONFIG);
$this->etcDirectory->copyFile(self::$configFile, self::$backupFile);
}
/**
* @inheritdoc
* @throws \Magento\Framework\Exception\FileSystemException
*/
protected function tearDown(): void
{
$this->reinitDeploymentConfig();
$this->etcDirectory->delete(self::$backupFile);
}
/**
* @param bool $flag
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function enableDebugging(bool $flag)
{
$this->shell->execute(
PHP_BINARY . ' -f %s setup:config:set -n --%s=%s --%s=%s',
[
BP . '/bin/magento',
ConfigOptionsList::INPUT_KEY_DEBUG_LOGGING,
(int)$flag,
InitParamListener::BOOTSTRAP_PARAM,
urldecode(http_build_query(Bootstrap::getInstance()->getAppInitParams())),
]
);
$this->deploymentConfig->resetData();
$this->assertSame((int)$flag, $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DEBUG_LOGGING));
}
/**
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function testDebugInProductionMode()
{
$message = 'test message';
$this->reinitDebugHandler(State::MODE_PRODUCTION);
$this->removeDebugLog();
$this->logger->debug($message);
$this->assertFileDoesNotExist($this->getDebuggerLogPath());
$this->assertNull($this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DEBUG_LOGGING));
$this->checkCommonFlow($message);
$this->reinitDeploymentConfig();
}
/**
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function testDebugInDeveloperMode()
{
$message = 'test message';
$this->reinitDebugHandler(State::MODE_DEVELOPER);
$this->deploymentConfig->resetData();
$this->removeDebugLog();
$this->logger->debug($message);
$this->assertFileExists($this->getDebuggerLogPath());
$this->assertStringContainsString($message, file_get_contents($this->getDebuggerLogPath()));
$this->assertNull($this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DEBUG_LOGGING));
$this->checkCommonFlow($message);
$this->reinitDeploymentConfig();
}
/**
* @return string
*/
private function getDebuggerLogPath()
{
if (!$this->debugLogPath) {
foreach ($this->logger->getHandlers() as $handler) {
if ($handler instanceof Debug) {
$this->debugLogPath = $handler->getUrl();
}
}
}
return $this->debugLogPath;
}
/**
* @throws \Magento\Framework\Exception\FileSystemException
*/
private function reinitDeploymentConfig()
{
$this->etcDirectory->delete(self::$configFile);
$this->etcDirectory->copyFile(self::$backupFile, self::$configFile);
$this->deploymentConfig->resetData();
}
/**
* @param string $instanceMode
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function reinitDebugHandler(string $instanceMode)
{
$this->debugHandler = $this->objectManager->create(
Debug::class,
[
'filePath' => Bootstrap::getInstance()->getAppTempDir(),
'state' => $this->objectManager->create(
State::class,
[
'mode' => $instanceMode,
]
),
]
);
$this->logger->setHandlers(
[
$this->debugHandler,
]
);
}
/**
* @return void
*/
private function detachLogger()
{
$this->debugHandler->close();
}
/**
* @return void
*/
private function removeDebugLog()
{
$this->detachLogger();
if (file_exists($this->getDebuggerLogPath())) {
unlink($this->getDebuggerLogPath());
}
}
/**
* @param string $message
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function checkCommonFlow(string $message)
{
$this->enableDebugging(true);
$this->removeDebugLog();
$this->logger->debug($message);
$this->assertFileExists($this->getDebuggerLogPath());
$this->assertStringContainsString($message, file_get_contents($this->getDebuggerLogPath()));
$this->enableDebugging(false);
$this->removeDebugLog();
$this->logger->debug($message);
$this->assertFileDoesNotExist($this->getDebuggerLogPath());
}
}