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,70 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Variable\Model\Config\Structure;
use Magento\TestFramework\Helper\Bootstrap;
class DomTest extends \PHPUnit\Framework\TestCase
{
public function testMerge()
{
$availableVariables = new AvailableVariables(
[
'test' => [
'test_section/config/allowed' => '1',
],
],
);
$model = Bootstrap::getObjectManager()->create(
\Magento\Variable\Model\Config\Structure\Dom::class,
[
'xml' => '<config/>',
'availableVariables' => $availableVariables
]
);
$testConfigXml = $this->getConfigXml();
$model->merge($testConfigXml);
$dom = $model->getDom();
$xml = $dom->saveXML();
$this->assertStringContainsString('allowed', $xml);
$this->assertStringNotContainsString('filtered', $xml);
}
/**
* @return string
*/
private function getConfigXml()
{
//phpcs:disable
$configXml = <<<'XML'
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="test_section" translate="label" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Test Section</label>
<tab>catalog</tab>
<resource>Magento_Catalog::catalog</resource>
<group id="config" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Test Config</label>
<field id="allowed" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Allowed Option</label>
</field>
<field id="filtered" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Filtered Option</label>
</field>
</group>
</section>
</system>
</config>
XML;
//phpcs:enable
return $configXml;
}
}
@@ -0,0 +1,96 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Variable\Model;
class VariableTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Variable\Model\Variable
*/
protected $_model;
protected function setUp(): void
{
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Variable\Model\Variable::class
);
}
public function testGetSetStoreId()
{
$this->_model->setStoreId(1);
$this->assertEquals(1, $this->_model->getStoreId());
}
public function testLoadByCode()
{
$this->_model->setData(['code' => 'test_code', 'name' => 'test_name']);
$this->_model->save();
$variable = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Variable\Model\Variable::class
);
$variable->loadByCode('test_code');
$this->assertEquals($this->_model->getName(), $variable->getName());
$this->_model->delete();
}
public function testGetValue()
{
$html = '<p>test</p>';
$text = 'test';
$this->_model->setData(['code' => 'test_code', 'html_value' => $html, 'plain_value' => $text]);
$this->assertEquals($html, $this->_model->getValue());
$this->assertEquals($html, $this->_model->getValue(\Magento\Variable\Model\Variable::TYPE_HTML));
$this->assertEquals($text, $this->_model->getValue(\Magento\Variable\Model\Variable::TYPE_TEXT));
}
public function testValidate()
{
$this->assertNotEmpty($this->_model->validate());
$this->_model->setName('test')->setCode('test');
$this->assertNotEmpty($this->_model->validate());
$this->_model->save();
try {
$this->assertTrue($this->_model->validate());
$this->_model->delete();
} catch (\Exception $e) {
$this->_model->delete();
throw $e;
}
}
public function testGetVariablesOptionArray()
{
$this->assertEquals([], $this->_model->getVariablesOptionArray());
}
public function testCollection()
{
$collection = $this->_model->getCollection();
$collection->setStoreId(1);
$this->assertEquals(1, $collection->getStoreId(), 'Store id setter and getter');
$collection->addValuesToResult();
$this->assertStringContainsString('variable_value', (string)$collection->getSelect());
}
/**
* Test to verify that returned by getVariablesOptionArray()
* custom variable label is HTML escaped.
*/
public function testGetVariablesOptionArrayWithHtmlLabel()
{
$expectedLabel = '&lt;b&gt;HTML Name value&lt;/b&gt;';
$data = [
'code' => 'html_name',
'name' => '<b>HTML Name value</b>'
];
$this->_model->setData($data)->save();
$actualLabel = current(current($this->_model->getVariablesOptionArray())['label']->getArguments());
$this->assertEquals($expectedLabel, $actualLabel);
}
}