This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,85 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model\Attribute;
use Magento\Eav\Api\AttributeGroupRepositoryInterface;
use Magento\Eav\Model\Entity\Attribute\Set;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\Api\SortOrderBuilder;
use Magento\TestFramework\Helper\Bootstrap;
class GroupRepositoryTest extends \PHPUnit\Framework\TestCase
{
/**
* @var AttributeGroupRepositoryInterface
*/
private $repository;
protected function setUp(): void
{
$this->repository = Bootstrap::getObjectManager()->create(AttributeGroupRepositoryInterface::class);
}
/**
* @magentoDataFixture Magento/Eav/_files/attribute_group_for_search.php
*/
public function testGetList()
{
/** @var Set $attributeSet */
$attributeSet = Bootstrap::getObjectManager()->create(Set::class)
->load('attribute_set_1_for_search', 'attribute_set_name');
/** @var FilterBuilder $filterBuilder */
$filterBuilder = Bootstrap::getObjectManager()->create(FilterBuilder::class);
$filter1 = $filterBuilder->setField('attribute_set_id')
->setValue($attributeSet->getId())
->create();
$filter2 = $filterBuilder->setField('default_id')
->setValue(0)
->setConditionType('eq')
->create();
$filter3 = $filterBuilder->setField('sort_order')
->setValue(10)
->setConditionType('gteq')
->create();
$filter4 = $filterBuilder->setField('sort_order')
->setValue(30)
->setConditionType('lteq')
->create();
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class);
$searchCriteriaBuilder->addFilters([$filter1, $filter2]);
$searchCriteriaBuilder->addFilters([$filter3, $filter4]);
/** @var SortOrderBuilder $sortOrderBuilder */
$sortOrderBuilder = Bootstrap::getObjectManager()->create(SortOrderBuilder::class);
/** @var SortOrder $sortOrder */
$sortOrder = $sortOrderBuilder->setField('attribute_group_code')
->setDirection(SortOrder::SORT_ASC)
->create();
$searchCriteriaBuilder->setSortOrders([$sortOrder]);
$searchCriteriaBuilder->setPageSize(1);
$searchCriteriaBuilder->setCurrentPage(1);
$searchCriteria = $searchCriteriaBuilder->create();
$searchResult = $this->repository->getList($searchCriteria);
$this->assertEquals(2, $searchResult->getTotalCount());
$items = array_values($searchResult->getItems());
$this->assertCount(1, $items);
$this->assertEquals('attribute_group_3_for_search', $items[0]['attribute_group_code']);
}
}
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model;
class AttributeManagementTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Eav\Api\AttributeManagementInterface
*/
private $model;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->model = $this->objectManager->create(\Magento\Eav\Api\AttributeManagementInterface::class);
}
/**
* Verify that collection in service used correctly
*/
public function testGetList()
{
$productAttributeSetId = $this->getAttributeSetId(
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE
);
$productAttributes = $this->model->getAttributes(
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
$productAttributeSetId
);
// Verify that result contains only product attributes
$this->verifyAttributeSetIds($productAttributes, $productAttributeSetId);
$categoryAttributeSetId = $this->getAttributeSetId(
\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE
);
$categoryAttributes = $this->model->getAttributes(
\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE,
$categoryAttributeSetId
);
// Verify that result contains only category attributes
$this->verifyAttributeSetIds($categoryAttributes, $categoryAttributeSetId);
}
/**
* @param string $entityTypeCode
* @return int
*/
private function getAttributeSetId($entityTypeCode)
{
/** @var \Magento\Eav\Model\Config $eavConfig */
$eavConfig = $this->objectManager->create(\Magento\Eav\Model\Config::class);
return $eavConfig->getEntityType($entityTypeCode)->getDefaultAttributeSetId();
}
/**
* @param array $items
* @param string $attributeSetId
* @return void
*/
private function verifyAttributeSetIds(array $items, $attributeSetId)
{
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $item */
foreach ($items as $item) {
$this->assertEquals($attributeSetId, $item->getAttributeSetId());
}
}
}
@@ -0,0 +1,74 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\Api\SortOrderBuilder;
use Magento\TestFramework\Helper\Bootstrap;
class AttributeRepositoryTest extends \PHPUnit\Framework\TestCase
{
/**
* @var AttributeRepositoryInterface
*/
private $repository;
protected function setUp(): void
{
$this->repository = Bootstrap::getObjectManager()->create(AttributeRepositoryInterface::class);
}
/**
* @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
*/
public function testGetList()
{
/** @var FilterBuilder $filterBuilder */
$filterBuilder = Bootstrap::getObjectManager()->create(FilterBuilder::class);
$filter1 = $filterBuilder->setField('backend_type')
->setValue('varchar')
->create();
$filter2 = $filterBuilder->setField('is_user_defined')
->setValue(true)
->create();
$filter3 = $filterBuilder->setField('is_required')
->setValue(true)
->create();
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class);
$searchCriteriaBuilder->addFilters([$filter1, $filter2]);
$searchCriteriaBuilder->addFilters([$filter3]);
/** @var SortOrderBuilder $sortOrderBuilder */
$sortOrderBuilder = Bootstrap::getObjectManager()->create(SortOrderBuilder::class);
/** @var SortOrder $sortOrder */
$sortOrder = $sortOrderBuilder->setField('attribute_code')
->setDirection(SortOrder::SORT_ASC)
->create();
$searchCriteriaBuilder->setSortOrders([$sortOrder]);
$searchCriteriaBuilder->setPageSize(2);
$searchCriteriaBuilder->setCurrentPage(2);
$searchCriteria = $searchCriteriaBuilder->create();
$searchResult = $this->repository->getList('test', $searchCriteria);
$this->assertEquals(3, $searchResult->getTotalCount());
$items = array_values($searchResult->getItems());
$this->assertCount(1, $items);
$this->assertEquals('attribute_for_search_3', $items[0]['attribute_code']);
}
}
@@ -0,0 +1,207 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model;
use Magento\Framework\App\Config\MutableScopeConfigInterface;
use Magento\Framework\DataObject;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\CacheCleaner;
/**
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
class ConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Config
*/
private $config;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->config = $objectManager->get(Config::class);
}
/**
* @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
*/
public function testGetEntityAttributeCodes()
{
$entityType = 'test';
$entityAttributeCodes1 = $this->config->getEntityAttributeCodes($entityType);
$this->assertEquals(
[
'attribute_for_search_1',
'attribute_for_search_2',
'attribute_for_search_3',
'attribute_for_search_4',
'attribute_for_search_5',
],
$entityAttributeCodes1
);
$entityAttributeCodes2 = $this->config->getEntityAttributeCodes($entityType);
$this->assertEquals($entityAttributeCodes1, $entityAttributeCodes2);
}
/**
* @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
*/
public function testGetEntityAttributeCodesWithObject()
{
$entityType = 'test';
/** @var \Magento\Eav\Model\Entity\Type $testEntityType */
$testEntityType = Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Entity\Type::class)
->loadByCode('test');
$attributeSetId = $testEntityType->getDefaultAttributeSetId();
$object = new DataObject(
[
'attribute_set_id' => $attributeSetId,
'store_id' => 0
]
);
$entityAttributeCodes1 = $this->config->getEntityAttributeCodes($entityType, $object);
$this->assertEquals(
[
'attribute_for_search_1',
'attribute_for_search_2',
],
$entityAttributeCodes1
);
$entityAttributeCodes2 = $this->config->getEntityAttributeCodes($entityType, $object);
$this->assertEquals($entityAttributeCodes1, $entityAttributeCodes2);
}
/**
* @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
*/
public function testGetAttributes()
{
$entityType = 'test';
$attributes1 = $this->config->getAttributes($entityType);
$expectedAttributeCodes = [
'attribute_for_search_1',
'attribute_for_search_2',
'attribute_for_search_3',
'attribute_for_search_4',
'attribute_for_search_5',
];
$this->assertEquals(count($expectedAttributeCodes), count($attributes1));
$attributeCodes = [];
foreach ($attributes1 as $attribute) {
$attributeCodes[] = $attribute->getAttributeCode();
}
$this->assertEquals($expectedAttributeCodes, $attributeCodes);
$attributes2 = $this->config->getAttributes($entityType);
$this->assertEquals($attributes1, $attributes2);
}
/**
* @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
*/
public function testGetAttribute()
{
$entityType = 'test';
$attribute1 = $this->config->getAttribute($entityType, 'attribute_for_search_1');
$this->assertEquals('attribute_for_search_1', $attribute1->getAttributeCode());
$this->assertEquals('varchar', $attribute1->getBackendType());
$this->assertEquals(1, $attribute1->getIsRequired());
$this->assertEquals(1, $attribute1->getIsUserDefined());
$this->assertEquals(0, $attribute1->getIsUnique());
$attribute2 = $this->config->getAttribute($entityType, 'attribute_for_search_1');
$this->assertEquals($attribute1, $attribute2);
}
/**
* @magentoDataFixture Magento/Eav/_files/attribute_for_caching.php
*/
public function testGetAttributeWithCacheUserDefinedAttribute()
{
/** @var MutableScopeConfigInterface $mutableScopeConfig */
$mutableScopeConfig = Bootstrap::getObjectManager()->get(MutableScopeConfigInterface::class);
$mutableScopeConfig->setValue('dev/caching/cache_user_defined_attributes', 1);
$entityType = 'catalog_product';
$attribute = $this->config->getAttribute($entityType, 'foo');
$this->assertEquals('foo', $attribute->getAttributeCode());
$this->assertEquals('foo', $attribute->getFrontendLabel());
$this->assertEquals('varchar', $attribute->getBackendType());
$this->assertEquals(1, $attribute->getIsRequired());
$this->assertEquals(1, $attribute->getIsUserDefined());
$this->assertEquals(0, $attribute->getIsUnique());
// Update attribute
$eavSetupFactory = Bootstrap::getObjectManager()->create(\Magento\Eav\Setup\EavSetupFactory::class);
/** @var \Magento\Eav\Setup\EavSetup $eavSetup */
$eavSetup = $eavSetupFactory->create();
$eavSetup->updateAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'foo',
[
'frontend_label' => 'bar',
]
);
// Check that attribute data has not changed
$config = Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Config::class);
$updatedAttribute = $config->getAttribute($entityType, 'foo');
$this->assertEquals('foo', $updatedAttribute->getFrontendLabel());
CacheCleaner::clean(['eav']);
$config = Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Config::class);
// Check that attribute data has changed
$updatedAttributeAfterCacheClean = $config->getAttribute($entityType, 'foo');
$this->assertEquals('bar', $updatedAttributeAfterCacheClean->getFrontendLabel());
$mutableScopeConfig->setValue('dev/caching/cache_user_defined_attributes', 0);
}
/**
* @magentoDataFixture Magento/Eav/_files/attribute_for_caching.php
*/
public function testGetAttributeWithInitUserDefinedAttribute()
{
/** @var MutableScopeConfigInterface $mutableScopeConfig */
$mutableScopeConfig = Bootstrap::getObjectManager()->get(MutableScopeConfigInterface::class);
$mutableScopeConfig->setValue('dev/caching/cache_user_defined_attributes', 0);
$entityType = 'catalog_product';
$attribute = $this->config->getAttribute($entityType, 'foo');
$this->assertEquals('foo', $attribute->getAttributeCode());
$this->assertEquals('foo', $attribute->getFrontendLabel());
$this->assertEquals('varchar', $attribute->getBackendType());
$this->assertEquals(1, $attribute->getIsRequired());
$this->assertEquals(1, $attribute->getIsUserDefined());
$this->assertEquals(0, $attribute->getIsUnique());
// Update attribute
$eavSetupFactory = Bootstrap::getObjectManager()->create(\Magento\Eav\Setup\EavSetupFactory::class);
/** @var \Magento\Eav\Setup\EavSetup $eavSetup */
$eavSetup = $eavSetupFactory->create();
$eavSetup->updateAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'foo',
[
'frontend_label' => 'bar',
]
);
// Check that attribute data has changed
$config = Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Config::class);
$updatedAttributeAfterCacheClean = $config->getAttribute($entityType, 'foo');
$this->assertEquals('bar', $updatedAttributeAfterCacheClean->getFrontendLabel());
}
/**
* @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,119 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Eav\Model\Entity\Attribute\Frontend;
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Store\ExecuteInStoreContext;
use PHPUnit\Framework\TestCase;
/**
* Checks Datetime attribute's frontend model
*
* @magentoAppArea frontend
*
* @see \Magento\Eav\Model\Entity\Attribute\Frontend\Datetime
*/
class DatetimeTest extends TestCase
{
/**
* @var int
*/
private const ONE_HOUR_IN_MILLISECONDS = 3600;
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var ProductAttributeRepositoryInterface
*/
private $attributeRepository;
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @var DateTime
*/
private $dateTime;
/**
* @var ExecuteInStoreContext
*/
private $executeInStoreContext;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->objectManager = Bootstrap::getObjectManager();
$this->attributeRepository = $this->objectManager->get(ProductAttributeRepositoryInterface::class);
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
$this->productRepository->cleanCache();
$this->dateTime = $this->objectManager->create(DateTime::class);
$this->executeInStoreContext = $this->objectManager->get(ExecuteInStoreContext::class);
}
/**
* @magentoDbIsolation disabled
*
* @magentoDataFixture Magento/Catalog/_files/product_two_websites.php
* @magentoDataFixture Magento/Catalog/_files/product_datetime_attribute.php
*
* @magentoConfigFixture default_store general/locale/timezone Asia/Tokyo
* @magentoConfigFixture fixture_second_store_store general/locale/timezone Asia/Shanghai
*
* @return void
*/
public function testFrontendValueOnDifferentWebsites(): void
{
$attribute = $this->attributeRepository->get('datetime_attribute');
$product = $this->productRepository->get('simple-on-two-websites');
$product->setDatetimeAttribute($this->dateTime->date('Y-m-d H:i:s'));
$firstWebsiteValue = $this->executeInStoreContext->execute(
'default',
[$attribute->getFrontend(), 'getValue'],
$product
);
$secondWebsiteValue = $this->executeInStoreContext->execute(
'fixture_second_store',
[$attribute->getFrontend(), 'getValue'],
$product
);
$this->assertEquals(
self::ONE_HOUR_IN_MILLISECONDS,
$this->dateTime->gmtTimestamp($firstWebsiteValue) - $this->dateTime->gmtTimestamp($secondWebsiteValue),
'The difference between values per different timezones is incorrect'
);
}
/**
* @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,119 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model\Entity\Attribute\Frontend;
use Magento\Catalog\Model\Product;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\CacheCleaner;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Framework\App\CacheInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Serialize\Serializer\Json as Serializer;
use Magento\Eav\Model\Entity\Attribute;
/**
* @magentoAppIsolation enabled
*/
class DefaultFrontendTest extends \PHPUnit\Framework\TestCase
{
/**
* @var DefaultFrontend
*/
private $defaultFrontend;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var AbstractAttribute
*/
private $attribute;
/**
* @var array
*/
private $options;
/**
* @var CacheInterface
*/
private $cache;
/**
* @var StoreManagerInterface
*/
private $storeManager;
/**
* @var Serializer
*/
private $serializer;
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->defaultFrontend = $this->objectManager->get(DefaultFrontend::class);
$this->cache = $this->objectManager->get(CacheInterface::class);
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
$this->serializer = $this->objectManager->get(Serializer::class);
$this->attribute = $this->objectManager->get(Attribute::class);
$this->attribute->setAttributeCode('store_id');
$this->options = $this->attribute->getSource()->getAllOptions();
$this->defaultFrontend->setAttribute($this->attribute);
}
public function testGetSelectOptions()
{
$this->assertSame($this->options, $this->defaultFrontend->getSelectOptions());
$this->assertSame(
$this->serializer->serialize($this->options),
$this->cache->load($this->getCacheKey())
);
}
/**
* @magentoDataFixture Magento/Catalog/_files/dropdown_attribute.php
*/
public function testAttributeEntityValueNotSet()
{
$entity = $this->objectManager->create(Product::class);
$entity->setStoreId(0);
$entity->load(1);
$frontEnd = $this->attribute->loadByCode('catalog_product', 'dropdown_attribute');
$value = $frontEnd->getFrontend()->getValue($entity);
$this->assertFalse($value);
}
/**
* Cache key generation
* @return string
*/
private function getCacheKey()
{
return 'attribute-navigation-option-' .
$this->defaultFrontend->getAttribute()->getAttributeCode() . '-' .
$this->storeManager->getStore()->getId();
}
/**
* @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,127 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model\Entity;
use Magento\Framework\DataObject;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\CacheCleaner;
/**
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Eav/_files/attribute_for_search.php
*/
class AttributeLoaderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var AttributeLoader
*/
private $attributeLoader;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var \Magento\Eav\Model\Entity\AbstractEntity
*/
private $resource;
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->attributeLoader = $this->objectManager->get(AttributeLoader::class);
$entityType = $this->objectManager->create(\Magento\Eav\Model\Entity\Type::class)
->loadByCode('test');
$context = $this->objectManager->get(\Magento\Eav\Model\Entity\Context::class);
$this->resource = $this->getMockBuilder(\Magento\Eav\Model\Entity\AbstractEntity::class)
->setConstructorArgs([$context])
->setMethods(['getEntityType', 'getLinkField'])
->getMock();
$this->resource->method('getEntityType')
->willReturn($entityType);
$this->resource->method('getLinkField')
->willReturn('link_field');
}
/**
* @param int $expectedNumOfAttributesByCode
* @param int $expectedNumOfAttributesByTable
* @param DataObject|null $object
* @dataProvider loadAllAttributesDataProvider
*/
public function testLoadAllAttributesTheFirstTime(
$expectedNumOfAttributesByCode,
$expectedNumOfAttributesByTable,
$object
) {
// Before load all attributes
$attributesByCode = $this->resource->getAttributesByCode();
$attributesByTable = $this->resource->getAttributesByTable();
$this->assertCount(0, $attributesByCode);
$this->assertCount(0, $attributesByTable);
// Load all attributes
$resource2 = $this->attributeLoader->loadAllAttributes(
$this->resource,
$object
);
$attributesByCode2 = $resource2->getAttributesByCode();
$attributesByTable2 = $resource2->getAttributesByTable();
$this->assertEquals($expectedNumOfAttributesByCode, count($attributesByCode2));
$this->assertEquals($expectedNumOfAttributesByTable, count($attributesByTable2));
}
public function loadAllAttributesDataProvider()
{
/** @var \Magento\Eav\Model\Entity\Type $entityType */
$entityType = Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Entity\Type::class)
->loadByCode('order');
$attributeSetId = $entityType->getDefaultAttributeSetId();
return [
[
13,
2,
null
],
[
10,
1,
new DataObject(
[
'attribute_set_id' => $attributeSetId,
'store_id' => 0
]
),
],
[
10,
1,
new DataObject(
[
'attribute_set_id' => $attributeSetId,
'store_id' => 10
]
),
],
];
}
/**
* @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,140 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Eav\Model\Entity;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Class to test EAV Entity attribute model
*/
class AttributeTest extends TestCase
{
/**
* @var Attribute
*/
private $attribute;
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var ResolverInterface
*/
private $localeResolver;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->attribute = $this->objectManager->get(Attribute::class);
$this->localeResolver = $this->objectManager->get(ResolverInterface::class);
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->attribute = null;
$this->objectManager = null;
$this->localeResolver = null;
$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);
}
}
}
/**
* @param string $defaultValue
* @param string $backendType
* @param string $locale
* @param string $expected
* @dataProvider beforeSaveDataProvider
* @throws
*/
public function testBeforeSave(
string $defaultValue,
string $backendType,
string $frontendInput,
string $locale,
string $expected
) {
$this->attribute->setDefaultValue($defaultValue);
$this->attribute->setBackendType($backendType);
$this->attribute->setFrontendInput($frontendInput);
$this->localeResolver->setLocale($locale);
$this->attribute->beforeSave();
$this->assertEquals($expected, $this->attribute->getDefaultValue());
}
/**
* Data provider for beforeSaveData.
*
* @return array
*/
public function beforeSaveDataProvider()
{
return [
['21/07/18', 'datetime', 'date', 'en_AU', '2018-07-21 00:00:00'],
['07/21/18', 'datetime', 'date', 'en_US', '2018-07-21 00:00:00'],
['21/07/18', 'datetime', 'date', 'fr_FR', '2018-07-21 00:00:00'],
['21/07/18', 'datetime', 'date', 'de_DE', '2018-07-21 00:00:00'],
['21/07/18', 'datetime', 'date', 'uk_UA', '2018-07-21 00:00:00'],
['100.50', 'decimal', 'decimal', 'en_US', '100.50'],
['100,50', 'decimal', 'decimal', 'uk_UA', '100.5'],
['07/21/2019 2:30 PM', 'datetime', 'datetime', 'en_US', '2019-07-21 21:30:00'],
['21.07.2019 14:30', 'datetime', 'datetime', 'uk_UA', '2019-07-21 21:30:00'],
];
}
/**
* @param string $defaultValue
* @param string $backendType
* @param string $locale
* @param string $expected
* @dataProvider beforeSaveErrorDataDataProvider
*/
public function testBeforeSaveErrorData($defaultValue, $backendType, $locale, $expected)
{
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->attribute->setDefaultValue($defaultValue);
$this->attribute->setBackendType($backendType);
$this->localeResolver->setLocale($locale);
$this->attribute->beforeSave();
$this->expectExceptionMessage($expected);
}
/**
* Data provider for beforeSaveData with error result.
*
* @return array
*/
public function beforeSaveErrorDataDataProvider()
{
return [
'wrong date for Australia' => ['32/38', 'datetime', 'en_AU', 'Invalid default date'],
'wrong date for States' => ['32/38', 'datetime', 'en_US', 'Invalid default date'],
'wrong decimal separator for US' => ['100,50', 'decimal', 'en_US', 'Invalid default decimal value'],
'wrong decimal separator for UA' => ['100.50', 'decimal', 'uk_UA', 'Invalid default decimal value'],
];
}
}
@@ -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);
}
}
}
}
@@ -0,0 +1,222 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Eav\Model;
use Magento\TestFramework\Helper\Bootstrap;
class TypeLocatorTest extends \PHPUnit\Framework\TestCase
{
/**
* @var TypeLocator
*/
private $attributeTypeLocator;
protected function setUp(): void
{
$this->attributeTypeLocator = Bootstrap::getObjectManager()->get(TypeLocator::class);
}
/**
* @param string $entityType
* @param string[] $attributeList
* @dataProvider getExpectedAttributeTypesProvider
*/
public function testGetType(
$entityType,
array $attributeList
) {
foreach ($attributeList as $attributeCode => $expectedType) {
$this->assertEquals(
$expectedType,
$this->attributeTypeLocator->getType($attributeCode, $entityType),
"Expected type of '{$attributeCode}' product attribute was '{$expectedType}"
);
}
}
/**
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getExpectedAttributeTypesProvider(): array
{
return [
'product' => [
'catalog_product',
[
'name' => 'string',
'sku' => 'string',
'description' => 'string',
'short_description' => 'string',
'price' => 'double',
'special_price' => 'double',
'special_from_date' => 'string',
'special_to_date' => 'string',
'cost' => 'double',
'weight' => 'double',
'manufacturer' => 'int',
'meta_title' => 'string',
'meta_keyword' => 'string',
'meta_description' => 'string',
'image' => 'string',
'small_image' => 'string',
'thumbnail' => 'string',
'old_id' => 'int',
'tier_price' => 'double',
'color' => 'int',
'news_from_date' => 'string',
'news_to_date' => 'string',
'gallery' => 'string',
'status' => 'int',
'minimal_price' => 'double',
'visibility' => 'int',
'custom_design' => 'string',
'custom_design_from' => 'string',
'custom_design_to' => 'string',
'custom_layout_update' => 'string',
'page_layout' => 'string',
'category_ids' => 'int[]',
'options_container' => 'string',
'required_options' => 'string',
'has_options' => 'string',
'image_label' => 'string',
'small_image_label' => 'string',
'thumbnail_label' => 'string',
'created_at' => 'string',
'updated_at' => 'string',
'country_of_manufacture' => 'string',
'quantity_and_stock_status' => \Magento\CatalogInventory\Api\Data\StockItemInterface::class . '[]',
'custom_layout' => 'string',
'url_key' => 'string',
'url_path' => 'string',
'msrp' => 'double',
'msrp_display_actual_price_type' => 'string',
'price_type' => 'int',
'sku_type' => 'int',
'weight_type' => 'int',
'price_view' => 'int',
'shipment_type' => 'int',
'links_purchased_separately' => 'int',
'samples_title' => 'string',
'links_title' => 'string',
'links_exist' => 'int',
'gift_message_available' => 'string',
'swatch_image' => 'string',
'tax_class_id' => 'int'
]
],
'customer'=> [
'customer',
[
'confirmation' => 'string',
'created_at' => 'string',
'website_id' => 'int',
'store_id' => 'int',
'created_in' => 'string',
'group_id' => 'string',
'disable_auto_group_change' => 'boolean',
'prefix' => 'string',
'firstname' => 'string',
'middlename' => 'string',
'lastname' => 'string',
'suffix' => 'string',
'email' => 'string',
'password_hash' => 'string',
'default_billing' => \Magento\Customer\Api\Data\AddressInterface::class,
'default_shipping' => \Magento\Customer\Api\Data\AddressInterface::class,
'updated_at' => 'string',
'dob' => 'string',
'taxvat' => 'string',
'failures_num' => 'string',
'gender' => 'string',
'first_failure' => 'string',
'rp_token' => 'string',
'rp_token_created_at' => 'string',
'lock_expires' => 'string',
]
],
'customer address' => [
'customer_address',
[
'prefix' => 'string',
'firstname' => 'string',
'middlename' => 'string',
'lastname' => 'string',
'suffix' => 'string',
'company' => 'string',
'street' => 'string',
'city' => 'string',
'country_id' => 'string',
'region' => \Magento\Customer\Api\Data\RegionInterface::class,
'region_id' => 'string',
'postcode' => 'string',
'telephone' => 'string',
'fax' => 'string',
'vat_is_valid' => 'string',
'vat_request_id' => 'string',
'vat_request_date' => 'string',
'vat_request_success' => 'string',
'vat_id' => 'string',
]
],
'category' => [
'catalog_category',
[
'name' => 'string',
'is_active' => 'int',
'url_key' => 'string',
'description' => 'string',
'image' => 'string',
'custom_use_parent_settings' => 'int',
'meta_title' => 'string',
'custom_apply_to_products' => 'int',
'meta_keywords' => 'string',
'meta_description' => 'string',
'display_mode' => 'string',
'custom_design' => 'string',
'include_in_menu' => 'int',
'path' => 'string',
'position' => 'string',
'all_children' => 'string',
'path_in_store' => 'string',
'children' => 'string',
'url_path' => 'string',
'landing_page' => 'int',
'level' => 'string',
'children_count' => 'string',
'is_anchor' => 'int',
'custom_design_from' => 'string',
'custom_design_to' => 'string',
'available_sort_by' => 'string[]',
'page_layout' => 'string',
'default_sort_by' => 'string[]',
'filter_price_range' => 'double',
'custom_layout_update' => 'string',
]
],
'undefined attributes' => [
'catalog_product',
['media_gallery' => 'anyType', 'undefine_attribute' => 'anyType']
]
];
}
/**
* @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,65 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Test for \Magento\Eav\Model\Validator\Attribute\Backend
*/
namespace Magento\Eav\Model\Validator\Attribute;
class BackendTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Eav\Model\Validator\Attribute\Backend
*/
protected $_model;
protected function setUp(): void
{
$this->_model = new \Magento\Eav\Model\Validator\Attribute\Backend();
}
/**
* Test method for \Magento\Eav\Model\Validator\Attribute\Backend::isValid
*
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
public function testIsValid()
{
/** @var $entity \Magento\Customer\Model\Customer */
$entity = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Customer\Model\Customer::class
)->load(
1
);
$this->assertTrue($this->_model->isValid($entity));
$this->assertEmpty($this->_model->getMessages());
$entity->setData('email', null);
$this->assertFalse($this->_model->isValid($entity));
$this->assertArrayHasKey('email', $this->_model->getMessages());
$entity->setData('firstname', null);
$this->assertFalse($this->_model->isValid($entity));
$this->assertArrayHasKey('email', $this->_model->getMessages());
$this->assertArrayHasKey('firstname', $this->_model->getMessages());
}
/**
* @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);
}
}
}
}