/** * 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()); }
/** * 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)); }
/** * @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'); }
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()); }
/** * 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()); } }
/** * 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(); }
/** * @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]); }