75 private $resourceMock;
90 private $cacheManager;
95 private $eventDispatcher;
100 private $attributeOptionFactoryMock;
105 private $dataObjectProcessorMock;
110 private $dataObjectHelperMock;
115 private $indexerRegistryMock;
120 private $extensionAttributesFactory;
125 private $dateTimeFormatter;
130 private $attributeMetadataCacheMock;
138 $objectManagerHelper =
new ObjectManagerHelper($this);
139 $this->contextMock = $this->getMockBuilder(\
Magento\Framework\Model\Context::class)
140 ->disableOriginalConstructor()
142 $this->registryMock = $this->getMockBuilder(\
Magento\Framework\Registry::class)
144 $this->extensionAttributesFactory = $this->getMockBuilder(
145 \
Magento\Framework\Api\ExtensionAttributesFactory::class
147 ->disableOriginalConstructor()
149 $this->attributeValueFactoryMock = $this->getMockBuilder(\
Magento\Framework\Api\AttributeValueFactory::class)
150 ->disableOriginalConstructor()
152 $this->configMock = $this->getMockBuilder(\
Magento\Eav\Model\Config::class)
153 ->disableOriginalConstructor()
155 $this->typeFactoryMock = $this->getMockBuilder(\
Magento\Eav\Model\Entity\TypeFactory::class)
156 ->disableOriginalConstructor()
158 $this->storeManagerMock = $this->getMockBuilder(\
Magento\Store\Model\StoreManagerInterface::class)
161 ->disableOriginalConstructor()
163 $this->universalFactoryMock = $this->getMockBuilder(\
Magento\Framework\
Validator\UniversalFactory::class)
164 ->disableOriginalConstructor()
166 $this->attributeOptionFactoryMock =
167 $this->getMockBuilder(\
Magento\Eav\Api\Data\AttributeOptionInterfaceFactory::class)
168 ->disableOriginalConstructor()
170 $this->dataObjectProcessorMock = $this->getMockBuilder(\
Magento\Framework\Reflection\DataObjectProcessor::class)
171 ->disableOriginalConstructor()
173 $this->dataObjectHelperMock = $this->getMockBuilder(\
Magento\Framework\Api\DataObjectHelper::class)
174 ->disableOriginalConstructor()
176 $this->timezoneMock = $this->getMockBuilder(\
Magento\Framework\Stdlib\
DateTime\TimezoneInterface::class)
178 $this->reservedAttributeListMock = $this->getMockBuilder(
179 \
Magento\Catalog\Model\Product\ReservedAttributeList::class
181 ->disableOriginalConstructor()
183 $this->resolverMock = $this->getMockBuilder(\
Magento\Framework\Locale\ResolverInterface::class)
185 $this->dateTimeFormatter = $this->createMock(
189 $this->resourceMock = $this->getMockBuilder(\
Magento\Framework\Model\
ResourceModel\AbstractResource::class)
190 ->setMethods([
'_construct',
'getConnection',
'getIdFieldName',
'saveInSetIncluding'])
191 ->getMockForAbstractClass();
192 $this->cacheManager = $this->getMockBuilder(\
Magento\Framework\
App\CacheInterface::class)
194 $this->eventDispatcher = $this->getMockBuilder(\
Magento\Framework\Event\ManagerInterface::class)
198 ->expects($this->any())
199 ->method(
'getCacheManager')
200 ->willReturn($this->cacheManager);
202 ->expects($this->any())
203 ->method(
'getEventDispatcher')
204 ->willReturn($this->eventDispatcher);
206 $this->indexerRegistryMock = $this->getMockBuilder(\
Magento\Framework\Indexer\IndexerRegistry::class)
207 ->disableOriginalConstructor()
209 $this->attributeMetadataCacheMock = $this->getMockBuilder(AttributeMetadataCache::class)
210 ->disableOriginalConstructor()
212 $this->attribute = $objectManagerHelper->getObject(
215 'context' => $this->contextMock,
216 'registry' => $this->registryMock,
217 'extensionFactory' => $this->extensionAttributesFactory,
218 'attributeValueFactory' => $this->attributeValueFactoryMock,
219 'eavConfig' => $this->configMock,
220 'typeFactory' => $this->typeFactoryMock,
221 'storeManager' => $this->storeManagerMock,
222 'helper' => $this->helperMock,
223 'universalFactory' => $this->universalFactoryMock,
224 'attributeOptionFactory' => $this->attributeOptionFactoryMock,
225 'dataObjectProcessor' => $this->dataObjectProcessorMock,
226 'dataObjectHelper' => $this->dataObjectHelperMock,
227 'timezone' => $this->timezoneMock,
228 'reservedAttributeList' => $this->reservedAttributeListMock,
229 'resolver' => $this->resolverMock,
230 'dateTimeFormatter' => $this->dateTimeFormatter,
231 'indexerRegistry' => $this->indexerRegistryMock,
232 'resource' => $this->resourceMock,
233 'attributeMetadataCache' => $this->attributeMetadataCacheMock
241 ->expects($this->once())
243 $this->attributeMetadataCacheMock
244 ->expects($this->once())
246 $this->attribute->afterSave();
252 ->expects($this->once())
254 $this->attributeMetadataCacheMock
255 ->expects($this->once())
257 $this->attribute->afterDelete();
260 public function testInvalidate()
263 $indexerMock = $this->getMockBuilder(\
Magento\Framework\Indexer\IndexerInterface::class)
264 ->getMockForAbstractClass();
266 $this->indexerRegistryMock->expects($this->once())
269 ->willReturn($indexerMock);
271 $indexerMock->expects($this->once())
272 ->method(
'invalidate');
274 $this->attribute->invalidate();
285 $this->attribute->setData(
'is_searchable_in_grid', $isSearchableInGrid);
288 $this->assertEquals(
$result, $this->attribute->canBeSearchableInGrid());
298 [0,
'textarea',
false],
300 [1,
'textarea',
true],
302 [1,
'boolean',
false],
303 [1,
'select',
false],
304 [1,
'media_image',
false],
305 [1,
'gallery',
false],
306 [1,
'multiselect',
false],
309 [1,
'weight',
false],
321 $this->attribute->setData(
'is_filterable_in_grid', $isFilterableInGrid);
324 $this->assertEquals(
$result, $this->attribute->canBeFilterableInGrid());
335 [0,
'select',
false],
336 [0,
'boolean',
false],
340 [1,
'boolean',
true],
341 [1,
'textarea',
false],
342 [1,
'media_image',
false],
343 [1,
'gallery',
false],
344 [1,
'multiselect',
false],
347 [1,
'weight',
false],
testCanBeSearchableInGrid($isSearchableInGrid, $frontendInput, $result)
$reservedAttributeListMock
dataProviderCanBeFilterableInGrid()
testCanBeFilterableInGrid($isFilterableInGrid, $frontendInput, $result)
$attributeValueFactoryMock
const CUSTOMER_GRID_INDEXER_ID
dataProviderCanBeSearchableInGrid()
testAfterDeleteEavCache()