Exemplo n.º 1
0
 /**
  * @return bool
  */
 private function isAttributeCacheEnabled()
 {
     if ($this->isAttributeCacheEnabled === null) {
         $this->isAttributeCacheEnabled = $this->state->isEnabled(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER);
     }
     return $this->isAttributeCacheEnabled;
 }
Exemplo n.º 2
0
 /**
  * Whether a cache type is enabled
  */
 public function testIsEnabled()
 {
     $this->_cacheState->expects($this->at(0))->method('isEnabled')->with(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER)->will($this->returnValue(true));
     $this->_cacheState->expects($this->at(1))->method('isEnabled')->with(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER)->will($this->returnValue(false));
     $this->assertTrue($this->_model->isEnabled());
     $this->assertFalse($this->_model->isEnabled());
 }
Exemplo n.º 3
0
 /**
  * Test setting all cache types to true
  *
  * Fixture is the same as in previous test, but here the intent to disable all of them.
  * Since only one of them is enabled, the setter should be invoked only once.
  * Also the operation of deactivating cache does not need cleanup (it is relevant when you enable it).
  */
 public function testSetEnabledFalseAll()
 {
     $caches = ['foo', 'bar', 'baz'];
     $cacheStatusMap = [['foo', true], ['bar', false], ['baz', false]];
     $this->cacheState->expects($this->exactly(3))->method('isEnabled')->will($this->returnValueMap($cacheStatusMap));
     $this->cacheState->expects($this->once())->method('setEnabled')->with('foo', false);
     $this->cacheState->expects($this->once())->method('persist');
     $this->frontendPool->expects($this->never())->method('get');
     $this->assertEquals(['foo'], $this->model->setEnabled($caches, false));
 }
Exemplo n.º 4
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');
 }
Exemplo n.º 5
0
 public function testFinish()
 {
     $cacheTypeListArray = array('one', 'two');
     $this->_cache->expects($this->once())->method('clean');
     $this->_config->expects($this->once())->method('reinit');
     $this->_cacheState->expects($this->once())->method('persist');
     $this->_cacheState->expects($this->exactly(count($cacheTypeListArray)))->method('setEnabled');
     $this->_cacheTypeList->expects($this->once())->method('getTypes')->will($this->returnValue($cacheTypeListArray));
     $this->_appState->expects($this->once())->method('setInstallDate')->with($this->greaterThanOrEqual(date('r')));
     $this->_installerConfig->expects($this->once())->method('replaceTmpInstallDate')->with($this->greaterThanOrEqual(date('r')));
     $this->assertSame($this->_model, $this->_model->finish());
 }
Exemplo n.º 6
0
 /**
  * Run test toHtml method
  *
  * @param bool $customerId
  * @return void
  *
  * @dataProvider dataProviderToHtml
  */
 public function testToHtml($customerId)
 {
     $cacheData = false;
     $idQueryParam = 'id-query-param';
     $sessionId = 'session-id';
     $this->additional->setData('cache_lifetime', 789);
     $this->additional->setData('cache_key', 'cache-key');
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('view_block_abstract_to_html_before', ['block' => $this->additional]);
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with('advanced/modules_disable_output/Magento_Persistent', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(false);
     // get cache
     $this->cacheStateMock->expects($this->at(0))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(true);
     // save cache
     $this->cacheStateMock->expects($this->at(1))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(false);
     $this->cacheMock->expects($this->once())->method('load')->willReturn($cacheData);
     $this->sidResolverMock->expects($this->never())->method('getSessionIdQueryParam')->with($this->sessionMock)->willReturn($idQueryParam);
     $this->sessionMock->expects($this->never())->method('getSessionId')->willReturn($sessionId);
     // call protected _toHtml method
     $sessionMock = $this->getMock('Magento\\Persistent\\Model\\Session', ['getCustomerId'], [], '', false);
     $this->persistentSessionHelperMock->expects($this->atLeastOnce())->method('getSession')->willReturn($sessionMock);
     $sessionMock->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($customerId);
     if ($customerId) {
         $this->assertEquals('<span><a  >Not you?</a></span>', $this->additional->toHtml());
     } else {
         $this->assertEquals('', $this->additional->toHtml());
     }
 }
Exemplo n.º 7
0
 /**
  * Check EAV cache availability
  *
  * @return bool
  */
 public function isCacheEnabled()
 {
     if ($this->_isCacheEnabled === null) {
         $this->_isCacheEnabled = $this->_cacheState->isEnabled(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER);
     }
     return $this->_isCacheEnabled;
 }
Exemplo n.º 8
0
 /**
  * Disable some cache types in VDE mode
  *
  * @return void
  */
 protected function _disableCache()
 {
     foreach ($this->_dataHelper->getDisabledCacheTypes() as $cacheCode) {
         if ($this->_cacheState->isEnabled($cacheCode)) {
             $this->_cacheState->setEnabled($cacheCode, false);
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Updates cache status for the requested types
  *
  * @param string[] $types
  * @param bool $isEnabled
  * @return array List of types with changed status
  */
 public function setEnabled(array $types, $isEnabled)
 {
     $changedStatusTypes = [];
     $isUpdated = false;
     foreach ($types as $type) {
         if ($this->cacheState->isEnabled($type) === $isEnabled) {
             // no need to poke it, if is not going to change
             continue;
         }
         $this->cacheState->setEnabled($type, $isEnabled);
         $isUpdated = true;
         $changedStatusTypes[] = $type;
     }
     if ($isUpdated) {
         $this->cacheState->persist();
     }
     return $changedStatusTypes;
 }
Exemplo n.º 10
0
 /**
  * @return $this
  */
 public function finish()
 {
     $this->_setAppInstalled();
     $this->_refreshConfig();
     /* Enable all cache types */
     foreach (array_keys($this->_cacheTypeList->getTypes()) as $cacheTypeCode) {
         $this->_cacheState->setEnabled($cacheTypeCode, true);
     }
     $this->_cacheState->persist();
     return $this;
 }
 /**
  * Toggle cache
  *
  */
 public function execute()
 {
     $allTypes = array_keys($this->_cacheTypeList->getTypes());
     $updatedTypes = 0;
     $disable = true;
     $enable = true;
     foreach ($allTypes as $code) {
         if ($this->_cacheState->isEnabled($code) && $disable) {
             $this->_cacheState->setEnabled($code, false);
             $updatedTypes++;
             $enable = false;
         }
         if (!$this->_cacheState->isEnabled($code) && $enable) {
             $this->_cacheState->setEnabled($code, true);
             $updatedTypes++;
             $disable = false;
         }
         if ($disable) {
             $this->_cacheTypeList->cleanType($code);
         }
     }
     if ($updatedTypes > 0) {
         $this->_cacheState->persist();
         $this->messageManager->addSuccess(__("%1 cache type(s) disabled.", $updatedTypes));
     }
 }
Exemplo n.º 12
0
 /**
  * Save block content to cache storage
  *
  * @param string $data
  * @return $this
  */
 protected function _saveCache($data)
 {
     if ($this->getCacheLifetime() === null || !$this->_cacheState->isEnabled(self::CACHE_GROUP)) {
         return false;
     }
     $cacheKey = $this->getCacheKey();
     $data = str_replace($this->_sidResolver->getSessionIdQueryParam($this->_session) . '=' . $this->_session->getSessionId(), $this->_getSidPlaceholder($cacheKey), $data);
     $this->_cache->save($data, $cacheKey, $this->getCacheTags(), $this->getCacheLifetime());
     return $this;
 }
Exemplo n.º 13
0
 /**
  * Whether a cache type is enabled at the moment or not
  *
  * @return bool
  */
 protected function _isEnabled()
 {
     return $this->_cacheState->isEnabled($this->_identifier);
 }
Exemplo n.º 14
0
 /**
  * @param \Magento\Framework\App\CacheInterface $cache
  * @param \Magento\Framework\App\Cache\StateInterface $cacheState
  */
 public function __construct(\Magento\Framework\App\CacheInterface $cache, \Magento\Framework\App\Cache\StateInterface $cacheState)
 {
     $this->cache = $cache;
     $this->isCacheEnabled = $cacheState->isEnabled(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER);
 }
Exemplo n.º 15
0
 /**
  * Whether a cache type is enabled in Cache Management Grid
  *
  * @return bool
  * @api
  */
 public function isEnabled()
 {
     return $this->_cacheState->isEnabled(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER);
 }
Exemplo n.º 16
0
 /**
  * Whether a cache type is enabled
  */
 public function testIsEnabled()
 {
     $this->_cacheState->setEnabled(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER, true);
     $this->_cacheState->expects($this->once())->method('isEnabled')->with(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER)->will($this->returnValue(true));
     $this->_model->isEnabled();
 }
Exemplo n.º 17
0
 /**
  * @param bool $cacheEnabledFlag
  * @return \Magento\Catalog\Plugin\Model\ResourceModel\Config
  */
 protected function getConfig($cacheEnabledFlag)
 {
     $this->cacheState->expects($this->any())->method('isEnabled')->with(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER)->willReturn($cacheEnabledFlag);
     return (new ObjectManager($this))->getObject('Magento\\Catalog\\Plugin\\Model\\ResourceModel\\Config', ['cache' => $this->cache, 'cacheState' => $this->cacheState]);
 }
 /**
  * @param $block
  * @return bool
  */
 protected function getCacheState($block)
 {
     return $this->_cacheState->isEnabled($block::CACHE_GROUP);
 }