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,99 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model\ResourceModel;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
* @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
*/
class AttributeLoaderTest extends \Magento\TestFramework\Indexer\TestCase
{
/**
* @var AttributeLoader
*/
private $attributeLoader;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$metadataPool = $objectManager->create(
MetadataPool::class,
[
'metadata' => [
'Test\Entity\Type' => [
'entityTableName' => 'test_entity',
'eavEntityType' => 'test',
'identifierField' => 'entity_id',
]
]
]
);
$this->attributeLoader = $objectManager->create(AttributeLoader::class, ['metadataPool' => $metadataPool]);
}
/**
* @param string[] $expectedAttributeCodes
* @param int|null $attributeSetId
* @dataProvider getAttributesDataProvider
*/
public function testGetAttributes($expectedAttributeCodes, $attributeSetId = null)
{
$attributes = $this->attributeLoader->getAttributes('Test\Entity\Type', $attributeSetId);
$this->assertEquals(count($expectedAttributeCodes), count($attributes));
$attributeCodes = [];
foreach ($attributes as $attribute) {
$attributeCodes[] = $attribute->getAttributeCode();
}
$this->assertEquals($expectedAttributeCodes, $attributeCodes);
$attributes2 = $this->attributeLoader->getAttributes('Test\Entity\Type', $attributeSetId);
$this->assertEquals($attributes, $attributes2);
}
public function getAttributesDataProvider()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$entityType = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)
->loadByCode('order');
$attributeSetId = $entityType->getDefaultAttributeSetId();
return [
'all' => [
[
'attribute_for_search_1',
'attribute_for_search_2',
'attribute_for_search_3',
]
],
"$attributeSetId" => [
[
'attribute_for_search_1',
'attribute_for_search_2',
],
$attributeSetId,
]
];
}
/**
* @inheritDoc
*/
protected function tearDown(): void
{
parent::tearDown();
$reflection = new \ReflectionObject($this);
foreach ($reflection->getProperties() as $property) {
if (!$property->isStatic() && 0 !== strpos($property->getDeclaringClass()->getName(), 'PHPUnit')) {
$property->setAccessible(true);
$property->setValue($this, null);
}
}
}
}
@@ -0,0 +1,111 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model\ResourceModel\Entity\Attribute;
class CollectionTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection
*/
protected $_model;
protected function setUp(): void
{
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::class
);
}
/**
* Returns array of set ids, present in collection attributes
*
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $collection
* @return array
*/
protected function _getSets($collection)
{
$collection->addSetInfo();
$sets = [];
foreach ($collection as $attribute) {
foreach (array_keys($attribute->getAttributeSetInfo()) as $setId) {
$sets[$setId] = $setId;
}
}
return array_values($sets);
}
public function testSetAttributeGroupFilter()
{
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::class
);
$groupsPresent = $this->_getGroups($collection);
$includeGroupId = current($groupsPresent);
$this->_model->setAttributeGroupFilter($includeGroupId);
$groups = $this->_getGroups($this->_model);
$this->assertEquals([$includeGroupId], $groups);
}
/**
* Test if getAllIds method return results after using setInAllAttributeSetsFilter method
*
* @covers \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::setInAllAttributeSetsFilter()
* @covers \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::getAllIds()
*/
public function testSetInAllAttributeSetsFilterWithGetAllIds()
{
$sets = [1];
$this->_model->setInAllAttributeSetsFilter($sets);
$attributeIds = $this->_model->getAllIds();
$this->assertGreaterThan(0, count($attributeIds));
}
/**
* Returns array of group ids, present in collection attributes
*
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $collection
* @return array
*/
protected function _getGroups($collection)
{
$collection->addSetInfo();
$groups = [];
foreach ($collection as $attribute) {
foreach ($attribute->getAttributeSetInfo() as $setInfo) {
$groupId = $setInfo['group_id'];
$groups[$groupId] = $groupId;
}
}
return array_values($groups);
}
public function testAddAttributeGrouping()
{
$select = $this->_model->getSelect();
$this->assertEmpty($select->getPart(\Magento\Framework\DB\Select::GROUP));
$this->_model->addAttributeGrouping();
$this->assertEquals(['main_table.attribute_id'], $select->getPart(\Magento\Framework\DB\Select::GROUP));
}
/**
* @inheritDoc
*/
protected function tearDown(): void
{
parent::tearDown();
$reflection = new \ReflectionObject($this);
foreach ($reflection->getProperties() as $property) {
if (!$property->isStatic() && 0 !== strpos($property->getDeclaringClass()->getName(), 'PHPUnit')) {
$property->setAccessible(true);
$property->setValue($this, null);
}
}
}
}
@@ -0,0 +1,80 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model\ResourceModel\UpdateHandler;
use Magento\Catalog\Model\Product;
use Magento\Eav\Model\ResourceModel\UpdateHandler;
use Magento\Eav\Model\ResourceModel\UpdateHandlerAbstract;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
*/
class ExecuteProcessForAllStoresTest extends UpdateHandlerAbstract
{
/**
* @covers \Magento\Eav\Model\ResourceModel\UpdateHandler::execute
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @dataProvider getAllStoresDataProvider
* @param $code
* @param $snapshotValue
* @param $newValue
* @param $expected
* @magentoDbIsolation disabled
*/
public function testExecuteProcessForAllStores($code, $snapshotValue, $newValue, $expected)
{
if ($snapshotValue !== '-') {
$entity = Bootstrap::getObjectManager()->create(Product::class);
$entity->setStoreId(0);
$entity->load(1);
$entity->setData($code, $snapshotValue);
$entity->save();
}
$entity = Bootstrap::getObjectManager()->create(Product::class);
$entity->setStoreId(0);
$entity->load(1);
$updateHandler = Bootstrap::getObjectManager()->create(UpdateHandler::class);
$entityData = array_merge($entity->getData(), [$code => $newValue]);
$updateHandler->execute(\Magento\Catalog\Api\Data\ProductInterface::class, $entityData);
$resultEntity = Bootstrap::getObjectManager()->create(Product::class);
$resultEntity->setStoreId(0);
$resultEntity->load(1);
$this->assertSame($expected, $resultEntity->getData($code));
}
/**
* @return array
*/
public function getAllStoresDataProvider()
{
return [
['description', '', 'not_empty_value', 'not_empty_value'], //0
['description', '', '', null], //1
['description', '', null, null], //2
['description', '', false, null], //3
['description', 'not_empty_value', 'not_empty_value2', 'not_empty_value2'], //4
['description', 'not_empty_value', '', null], //5
['description', 'not_empty_value', null, null], //6
['description', 'not_empty_value', false, null], //7
['description', null, 'not_empty_value', 'not_empty_value'], //8
['description', null, '', null], //9
['description', null, false, null], //10
['description', false, 'not_empty_value', 'not_empty_value'], //11
['description', false, '', null], //12
['description', false, null, null], //13
];
}
}
@@ -0,0 +1,133 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model\ResourceModel\UpdateHandler;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Eav\Model\ResourceModel\UpdateHandlerAbstract;
use Magento\Store\Model\Store;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Eav\Model\ResourceModel\UpdateHandler;
/**
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
*/
class ExecuteProcessForCustomAttributeInCustomStoreTest extends UpdateHandlerAbstract
{
/**
* @covers \Magento\Eav\Model\ResourceModel\UpdateHandler::execute
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @magentoDataFixture Magento/Catalog/_files/dropdown_attribute.php
* @magentoDataFixture Magento/Store/_files/second_store.php
* @dataProvider getCustomAttributeDataProvider
* @param $code
* @param $defaultStoreValue
* @param $snapshotValue
* @param $newValue
* @param $expected
* @magentoDbIsolation disabled
*/
public function testExecuteProcessForCustomAttributeInCustomStore(
$code,
$defaultStoreValue,
$snapshotValue,
$newValue,
$expected
) {
$store = Bootstrap::getObjectManager()->create(Store::class);
$store->load('fixture_second_store', 'code');
$this->reindexAll();
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
Attribute::class
);
$attribute->loadByCode(4, $code);
$options = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::class
);
$options->setAttributeFilter($attribute->getId());
$optionIds = $options->getAllIds();
$entity = Bootstrap::getObjectManager()->create(Product::class);
$entity->setStoreId(0);
$entity->load(1);
$entity->setData($code, $optionIds[$defaultStoreValue]);
$entity->save();
if ($snapshotValue !== '-') {
/** @var $options \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection */
$entity = Bootstrap::getObjectManager()->create(Product::class);
$entity->setStoreId($store->getId());
$entity->load(1);
if ($snapshotValue) {
$snapshotValue = $optionIds[$snapshotValue];
}
$entity->setData($code, $snapshotValue);
$entity->save();
}
$entity = Bootstrap::getObjectManager()->create(Product::class);
$entity->setStoreId($store->getId());
$entity->load(1);
$updateHandler = Bootstrap::getObjectManager()->create(UpdateHandler::class);
if ($newValue) {
$newValue = $optionIds[$newValue];
}
$entityData = array_merge($entity->getData(), [$code => $newValue]);
$updateHandler->execute(\Magento\Catalog\Api\Data\ProductInterface::class, $entityData);
$resultEntity = Bootstrap::getObjectManager()->create(Product::class);
$resultEntity->setStoreId($store->getId());
$resultEntity->load(1);
if ($expected !== null) {
$expected = $optionIds[$expected];
}
$this->assertSame($expected, $resultEntity->getData($code));
}
/**
* @return array
*/
public function getCustomAttributeDataProvider()
{
return [
['dropdown_attribute', 0, '', 1, 1], //0
['dropdown_attribute', 0, '', '', null], //1
['dropdown_attribute', 0, '', null, 0], //2
['dropdown_attribute', 0, '', false, 0], //3
['dropdown_attribute', 0, 1, 2, 2], //4
['dropdown_attribute', 0, 1, '', null], //5
['dropdown_attribute', 0, 1, null, 0], //6
['dropdown_attribute', 0, 1, false, 0], //7
['dropdown_attribute', 0, null, 1, 1], //8
['dropdown_attribute', 0, null, '', null], //9
['dropdown_attribute', 0, null, false, 0], //10
['dropdown_attribute', 0, false, 1, 1], //11
['dropdown_attribute', 0, false, '', null], //12
['dropdown_attribute', 0, false, null, 0], //13
['dropdown_attribute', 0, '-', 1, 1], //14
['dropdown_attribute', 0, '-', '', null], //15
['dropdown_attribute', 0, '-', null, 0], //16
['dropdown_attribute', 0, '-', false, 0], //17
];
}
}
@@ -0,0 +1,88 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model\ResourceModel\UpdateHandler;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Eav\Model\ResourceModel\UpdateHandlerAbstract;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Eav\Model\ResourceModel\UpdateHandler;
/**
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
*/
class ExecuteProcessForCustomStoreTest extends UpdateHandlerAbstract
{
/**
* @covers \Magento\Eav\Model\ResourceModel\UpdateHandler::execute
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @magentoDataFixture Magento/Store/_files/second_store.php
* @dataProvider getCustomStoreDataProvider
* @param $code
* @param $snapshotValue
* @param $newValue
* @param $expected
* @magentoDbIsolation disabled
*/
public function testExecuteProcessForCustomStore($code, $snapshotValue, $newValue, $expected)
{
$store = Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class);
$store->load('fixture_second_store', 'code');
$this->reindexAll();
if ($snapshotValue !== '-') {
$entity = Bootstrap::getObjectManager()->create(Product::class);
$entity->setStoreId($store->getId());
$entity->load(1);
$entity->setData($code, $snapshotValue);
$entity->save();
}
$entity = Bootstrap::getObjectManager()->create(Product::class);
$entity->setStoreId($store->getId());
$entity->load(1);
$updateHandler = Bootstrap::getObjectManager()->create(UpdateHandler::class);
$entityData = array_merge($entity->getData(), [$code => $newValue]);
$updateHandler->execute(ProductInterface::class, $entityData);
$resultEntity = Bootstrap::getObjectManager()->create(Product::class);
$resultEntity->setStoreId($store->getId());
$resultEntity->load(1);
$this->assertSame($expected, $resultEntity->getData($code));
}
/**
* @return array
*/
public function getCustomStoreDataProvider()
{
return [
['description', '', 'not_empty_value', 'not_empty_value'], //0
['description', '', '', null], //1
['description', '', null, 'Description with <b>html tag</b>'], //2
['description', '', false, 'Description with <b>html tag</b>'], //3
['description', 'not_empty_value', 'not_empty_value2', 'not_empty_value2'], //4
['description', 'not_empty_value', '', null], //5
['description', 'not_empty_value', null, 'Description with <b>html tag</b>'], //6
['description', 'not_empty_value', false, 'Description with <b>html tag</b>'], //7
['description', null, 'not_empty_value', 'not_empty_value'], //8
['description', null, '', null], //9
['description', null, false, 'Description with <b>html tag</b>'], //10
['description', false, 'not_empty_value', 'not_empty_value'], //11
['description', false, '', null], //12
['description', false, null, 'Description with <b>html tag</b>'], //13
];
}
}
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model\ResourceModel;
use Magento\CatalogSearch\Model\Indexer\Fulltext\Processor;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Indexer\TestCase;
/**
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
*/
class UpdateHandlerAbstract extends TestCase
{
protected function reindexAll(): void
{
Bootstrap::getObjectManager()
->get(Processor::class)
->reindexAll();
}
/**
* @inheritDoc
*/
protected function tearDown(): void
{
parent::tearDown();
$reflection = new \ReflectionObject($this);
foreach ($reflection->getProperties() as $property) {
if (!$property->isStatic() && 0 !== strpos($property->getDeclaringClass()->getName(), 'PHPUnit')) {
$property->setAccessible(true);
$property->setValue($this, null);
}
}
}
}