예제 #1
0
 /**
  * @param boolean $cacheEnabled
  * @param int $loadCalls
  * @param string $cachedValue
  * @dataProvider getAttributeCacheDataProvider
  * @return void
  */
 public function testGetAttributeCache($cacheEnabled, $loadCalls, $cachedValue)
 {
     $attributeCollectionMock = $this->getMockBuilder('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Collection')->disableOriginalConstructor()->setMethods(['getData', 'setEntityTypeFilter'])->getMock();
     $attributeCollectionMock->expects($this->any())->method('setEntityTypeFilter')->will($this->returnSelf());
     $attributeCollectionMock->expects($this->any())->method('getData')->willReturn([]);
     $entityAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['setData'])->disableOriginalConstructor()->getMock();
     $factoryCalls = [['Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Collection', [], $attributeCollectionMock], ['Magento\\Eav\\Model\\Entity\\Attribute', [], $entityAttributeMock]];
     $this->stateMock->expects($this->atLeastOnce())->method('isEnabled')->with(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER)->willReturn($cacheEnabled);
     $this->cacheMock->expects($this->exactly($loadCalls))->method('load')->with(Config::ATTRIBUTES_CACHE_ID)->willReturn($cachedValue);
     $collectionStub = new DataObject([['entity_type_code' => 'type_code_1', 'entity_type_id' => 1]]);
     $this->collectionFactoryMock->expects($this->any())->method('create')->willReturn($collectionStub);
     $this->typeFactoryMock->expects($this->any())->method('create')->willReturn(new DataObject(['id' => 101]));
     $this->universalFactoryMock->expects($this->atLeastOnce())->method('create')->will($this->returnValueMap($factoryCalls));
     $entityType = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Type')->setMethods(['getEntity', 'setData', 'getData'])->disableOriginalConstructor()->getMock();
     $this->config->getAttribute($entityType, 'attribute_code_1');
 }
예제 #2
0
 /**
  * Initialize all entity types data
  *
  * @return $this
  */
 protected function _initEntityTypes()
 {
     if (is_array($this->_entityTypeData)) {
         return $this;
     }
     \Magento\Framework\Profiler::start('EAV: ' . __METHOD__, ['group' => 'EAV', 'method' => __METHOD__]);
     if ($this->isCacheEnabled() && ($cache = $this->_cache->load(self::ENTITIES_CACHE_ID))) {
         $this->_entityTypeData = unserialize($cache);
         foreach ($this->_entityTypeData as $typeCode => $data) {
             $typeId = $data['entity_type_id'];
             $this->_addEntityTypeReference($typeId, $typeCode);
         }
         \Magento\Framework\Profiler::stop('EAV: ' . __METHOD__);
         return $this;
     }
     $entityTypesData = $this->entityTypeCollectionFactory->create()->getData();
     foreach ($entityTypesData as $typeData) {
         if (!isset($typeData['attribute_model'])) {
             $typeData['attribute_model'] = 'Magento\\Eav\\Model\\Entity\\Attribute';
         }
         $typeCode = $typeData['entity_type_code'];
         $typeId = $typeData['entity_type_id'];
         $this->_addEntityTypeReference($typeId, $typeCode);
         $this->_entityTypeData[$typeCode] = $typeData;
     }
     if ($this->isCacheEnabled()) {
         $this->_cache->save(serialize($this->_entityTypeData), self::ENTITIES_CACHE_ID, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     }
     \Magento\Framework\Profiler::stop('EAV: ' . __METHOD__);
     return $this;
 }