Esempio n. 1
0
 /**
  * @param boolean $cacheEnabled
  * @param int $loadCalls
  * @param string $cachedValue
  * @param array $factoryCalls
  * @dataProvider getAttributeCacheDataProvider
  * @return void
  */
 public function testGetAttributeCache($cacheEnabled, $loadCalls, $cachedValue, $factoryCalls)
 {
     $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 Object([['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 Object(['id' => 101]));
     $this->universalFactoryMock->expects($this->exactly(count($factoryCalls)))->method('create')->will($this->returnValueMap($factoryCalls));
     $entityType = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Type')->setMethods(['getEntity'])->disableOriginalConstructor()->getMock();
     $this->config->getAttribute($entityType, 'attribute_code_1');
 }
Esempio n. 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;
 }