/** * @param bool $fixtureResultOne * @param bool $fixtureResultTwo * @param bool $expectedResult * @dataProvider cleanModeMatchingAnyTagDataProvider */ public function testCleanModeMatchingAnyTag($fixtureResultOne, $fixtureResultTwo, $expectedResult) { $this->frontendMock->expects($this->at(0))->method('clean')->with(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, ['test_tag_one', \Magento\Framework\App\Cache\Type\Config::CACHE_TAG])->will($this->returnValue($fixtureResultOne)); $this->frontendMock->expects($this->at(1))->method('clean')->with(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, ['test_tag_two', \Magento\Framework\App\Cache\Type\Config::CACHE_TAG])->will($this->returnValue($fixtureResultTwo)); $actualResult = $this->model->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, ['test_tag_one', 'test_tag_two']); $this->assertEquals($expectedResult, $actualResult); }
/** * Remove configuration data after delete store * * @param \Magento\Framework\Model\AbstractModel $model * @return $this */ protected function _afterDelete(\Magento\Framework\Model\AbstractModel $model) { $where = ['scope = ?' => \Magento\Store\Model\ScopeInterface::SCOPE_STORES, 'scope_id = ?' => $model->getStoreId()]; $this->getConnection()->delete($this->getTable('core_config_data'), $where); $this->configCache->clean(); return $this; }
/** * @param $area * @dataProvider loadDataProvider */ public function testLoad($area) { $configData = ['some' => 'config', 'data' => 'value']; $this->_cacheMock->expects($this->once())->method('load')->with($area . '::DiConfig')->will($this->returnValue(false)); $this->_readerMock->expects($this->once())->method('read')->with($area)->will($this->returnValue($configData)); $this->assertEquals($configData, $this->_model->load($area)); }
/** * Test for getAllOptions method * * @param $cachedDataSrl * @param $cachedDataUnsrl * * @dataProvider testGetAllOptionsDataProvider */ public function testGetAllOptions($cachedDataSrl, $cachedDataUnsrl) { $this->storeMock->expects($this->once())->method('getCode')->will($this->returnValue('store_code')); $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock)); $this->cacheConfig->expects($this->once())->method('load')->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code'))->will($this->returnValue($cachedDataSrl)); $countryOfManufacture = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Countryofmanufacture', ['storeManager' => $this->storeManagerMock, 'configCacheType' => $this->cacheConfig]); $this->assertEquals($cachedDataUnsrl, $countryOfManufacture->getAllOptions()); }
public function testGetTotalUnserializeCachedCollectorCodes() { $total = $this->getMockForAbstractClass('Magento\\Sales\\Model\\Order\\Total\\AbstractTotal'); $this->salesConfig->expects($this->any())->method('getGroupTotals')->will($this->returnValue(['some_code' => ['instance' => 'Magento\\Sales\\Model\\Order\\Total\\AbstractTotal', 'sort_order' => 1903], 'other_code' => ['instance' => 'Magento\\Sales\\Model\\Order\\Total\\AbstractTotal', 'sort_order' => 1723]])); $this->orderTotalFactory->expects($this->any())->method('create')->with('Magento\\Sales\\Model\\Order\\Total\\AbstractTotal')->will($this->returnValue($total)); $this->configCacheType->expects($this->once())->method('load')->with('sorted_collectors')->will($this->returnValue('a:2:{i:0;s:10:"other_code";i:1;s:9:"some_code";}')); $this->configCacheType->expects($this->never())->method('save'); $this->assertSame(['other_code' => $total, 'some_code' => $total], $this->object->getTotalModels()); }
/** * @return void */ protected function tearDown() { $this->configCacheType->save('', \Magento\Backend\Model\Menu\Config::CACHE_MENU_OBJECT); $reflection = new \ReflectionClass('Magento\\Framework\\Component\\ComponentRegistrar'); $paths = $reflection->getProperty('paths'); $paths->setAccessible(true); $paths->setValue($this->backupRegistrar); $paths->setAccessible(false); }
/** * @param \Magento\Framework\App\Config\Initial\Reader $reader * @param \Magento\Framework\App\Cache\Type\Config $cache */ public function __construct(\Magento\Framework\App\Config\Initial\Reader $reader, \Magento\Framework\App\Cache\Type\Config $cache) { $data = $cache->load(self::CACHE_ID); if (!$data) { $data = $reader->read(); $cache->save(serialize($data), self::CACHE_ID); } else { $data = unserialize($data); } $this->_data = $data['data']; $this->_metadata = $data['metadata']; }
/** * Get list of all available countries * * @return array */ public function getAllOptions() { $cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $this->_storeManager->getStore()->getCode(); if ($cache = $this->_configCacheType->load($cacheKey)) { $options = unserialize($cache); } else { $collection = $this->_countryFactory->create()->getResourceCollection()->loadByStore(); $options = $collection->toOptionArray(); $this->_configCacheType->save(serialize($options), $cacheKey); } return $options; }
/** * Return integrations loaded from cache if enabled or from files merged previously * * @return array * @api */ public function getIntegrations() { if (null === $this->_integrations) { $integrations = $this->_configCacheType->load(self::CACHE_ID); if ($integrations && is_string($integrations)) { $this->_integrations = unserialize($integrations); } else { $this->_integrations = $this->_configReader->read(); $this->_configCacheType->save(serialize($this->_integrations), self::CACHE_ID, [Type::CACHE_TAG]); } } return $this->_integrations; }
/** * Class constructor * * @param \Smile\ElasticsuiteCore\Model\Search\Request\RelevanceConfig\Reader\Initial $reader The reader * @param \Magento\Framework\App\Cache\Type\Config $cache Cache instance */ public function __construct(Reader $reader, \Magento\Framework\App\Cache\Type\Config $cache) { $data = $cache->load(self::CACHE_ID); if (!$data) { $data = serialize($reader->read()); $cache->save($data, self::CACHE_ID); } $data = unserialize($data); if (isset($data['data'])) { $this->data = $data['data']; } if (isset($data['metadata'])) { $this->metadata = $data['metadata']; } }
/** * Retrieve regions data json * * @return string */ public function getRegionJson() { \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]); if (!$this->_regionJson) { $cacheKey = 'DIRECTORY_REGIONS_JSON_STORE' . $this->_storeManager->getStore()->getId(); $json = $this->_configCacheType->load($cacheKey); if (empty($json)) { $countryIds = []; foreach ($this->getCountryCollection() as $country) { $countryIds[] = $country->getCountryId(); } $collection = $this->_regCollectionFactory->create(); $collection->addCountryFilter($countryIds)->load(); $regions = ['config' => ['show_all_regions' => $this->isShowNonRequiredState(), 'regions_required' => $this->getCountriesWithStatesRequired()]]; foreach ($collection as $region) { /** @var $region \Magento\Directory\Model\Region */ if (!$region->getRegionId()) { continue; } $regions[$region->getCountryId()][$region->getRegionId()] = ['code' => $region->getCode(), 'name' => (string) __($region->getName())]; } $json = $this->jsonHelper->jsonEncode($regions); if ($json === false) { $json = 'false'; } $this->_configCacheType->save($json, $cacheKey); } $this->_regionJson = $json; } \Magento\Framework\Profiler::stop('TEST: ' . __METHOD__); return $this->_regionJson; }
/** * Add Link to Head * * @return void */ protected function addHeadInclude() { $styleContent = ''; foreach ($this->moduleList->getNames() as $moduleName) { $fileName = substr($moduleName, strpos($moduleName, "_") + 1) . '/styles.css'; $fileName = $this->fixtureHelper->getPath($fileName); if (!$fileName) { continue; } $style = file_get_contents($fileName); $styleContent .= preg_replace('/^\\/\\*[\\s\\S]+\\*\\//', '', $style); } if (empty($styleContent)) { return; } $mediaDir = $this->directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA); file_put_contents("{$mediaDir}/styles.css", $styleContent); $linkTemplate = '<link rel="stylesheet" type="text/css" media="all" href="%sstyles.css" />'; $baseUrl = $this->baseUrl->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]); $linkText = sprintf($linkTemplate, $baseUrl); $miscScriptsNode = 'design/head/includes'; $miscScripts = $this->scopeConfig->getValue($miscScriptsNode); if (!$miscScripts || strpos($miscScripts, $linkText) === false) { $this->configWriter->save($miscScriptsNode, $miscScripts . $linkText); $this->configCacheType->clean(); } }
public function add($contentFile, $cssFile) { $styleContent = preg_replace('/^\\/\\*[\\s\\S]+\\*\\//', '', file_get_contents($contentFile)); if (empty($styleContent)) { return; } $mediaDir = $this->directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA); file_put_contents("{$mediaDir}/{$cssFile}", $styleContent, FILE_APPEND); $linkText = sprintf('<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}%s" />', $cssFile); $miscScriptsNode = 'design/head/includes'; $miscScripts = $this->scopeConfig->getValue($miscScriptsNode); if (!$miscScripts || strpos($miscScripts, $linkText) === false) { $this->configWriter->save($miscScriptsNode, $miscScripts . $linkText); $this->configCacheType->clean(); } }
/** * @return mixed */ public function getCountryOptions() { $options = false; $cacheId = 'DIRECTORY_COUNTRY_SELECT_STORE_' . $this->_storeManager->getStore()->getCode(); if ($optionsCache = $this->_configCacheType->load($cacheId)) { $options = unserialize($optionsCache); } if ($options == false) { $options = $this->getCountryCollection()->toOptionArray(); $this->_configCacheType->save(serialize($options), $cacheId); } return $options; }
/** * {@inheritdoc} */ public function run() { $this->logger->log('Installing multiple wishlists:'); $multipleEnabledConfig = 'wishlist/general/multiple_enabled'; if (!$this->config->isSetFlag($multipleEnabledConfig)) { $this->configWriter->save($multipleEnabledConfig, 1); $this->configCacheType->clean(); } $fixtureFiles = ['Wishlist/wishlist.csv', 'MultipleWishlist/wishlist.csv']; foreach ($fixtureFiles as $fixtureFile) { $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile); /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */ $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']); foreach ($csvReader as $row) { /** @var \Magento\Customer\Model\Customer $customer */ $customer = $this->wishlistHelper->getCustomerByEmail($row['customer_email']); if (!$customer) { continue; } $wishlistName = $row['name']; /** @var \Magento\Wishlist\Model\Resource\Wishlist\Collection $wishlistCollection */ $wishlistCollection = $this->wishlistColFactory->create(); $wishlistCollection->filterByCustomerId($customer->getId())->addFieldToFilter('name', $wishlistName); /** @var \Magento\Wishlist\Model\Wishlist $wishlist */ $wishlist = $wishlistCollection->fetchItem(); if ($wishlist) { continue; } $wishlist = $this->wishlistEditor->edit($customer->getId(), $wishlistName, true); if (!$wishlist->getId()) { continue; } $productSkuList = explode("\n", $row['product_list']); $this->wishlistHelper->addProductsToWishlist($wishlist, $productSkuList); $this->logger->logInline('.'); } } }
/** * Initialize menu object * * @return void */ protected function _initMenu() { if (!$this->_menu) { $this->_menu = $this->_menuFactory->create(); $cache = $this->_configCacheType->load(self::CACHE_MENU_OBJECT); if ($cache) { $this->_menu->unserialize($cache); return; } $this->_director->direct($this->_configReader->read($this->_appState->getAreaCode()), $this->_menuBuilder, $this->_logger); $this->_menu = $this->_menuBuilder->getResult($this->_menu); $this->_configCacheType->save($this->_menu->serialize(), self::CACHE_MENU_OBJECT); } }
/** * @return string */ public function getRegionHtmlSelect() { \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]); $cacheKey = 'DIRECTORY_REGION_SELECT_STORE' . $this->_storeManager->getStore()->getId(); $cache = $this->_configCacheType->load($cacheKey); if ($cache) { $options = unserialize($cache); } else { $options = $this->getRegionCollection()->toOptionArray(); $this->_configCacheType->save(serialize($options), $cacheKey); } $html = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setName('region')->setTitle(__('State/Province'))->setId('state')->setClass('required-entry validate-state')->setValue(intval($this->getRegionId()))->setOptions($options)->getHtml(); \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]); return $html; }
/** * Initialize collectors array. * Collectors array is array of total models ordered based on configuration settings * * @return $this */ protected function _initCollectors() { $sortedCodes = []; $cachedData = $this->_configCacheType->load($this->_collectorsCacheKey); if ($cachedData) { $sortedCodes = unserialize($cachedData); } if (!$sortedCodes) { $sortedCodes = $this->_getSortedCollectorCodes($this->_modelsConfig); $this->_configCacheType->save(serialize($sortedCodes), $this->_collectorsCacheKey); } foreach ($sortedCodes as $code) { $this->_collectors[$code] = $this->_models[$code]; } return $this; }
/** * Retrieve regions data json * * @return string */ public function getRegionJson() { \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]); if (!$this->_regionJson) { $cacheKey = 'DIRECTORY_REGIONS_JSON_STORE' . $this->_storeManager->getStore()->getId(); $json = $this->_configCacheType->load($cacheKey); if (empty($json)) { $regions = $this->getRegionData(); $json = $this->jsonHelper->jsonEncode($regions); if ($json === false) { $json = 'false'; } $this->_configCacheType->save($json, $cacheKey); } $this->_regionJson = $json; } \Magento\Framework\Profiler::stop('TEST: ' . __METHOD__); return $this->_regionJson; }
/** * Checkout with PayPal image URL getter * Spares API calls of getting "pal" variable, by putting it into cache per store view * * @return string */ public function getCheckoutShortcutImageUrl() { // get "pal" thing from cache or lookup it via API $pal = null; if ($this->_config->areButtonsDynamic()) { $cacheId = self::PAL_CACHE_ID . $this->_storeManager->getStore()->getId(); $pal = $this->_configCacheType->load($cacheId); if (self::PAL_CACHE_ID == $pal) { $pal = null; } elseif (!$pal) { $pal = null; $this->_getApi(); try { $this->_api->callGetPalDetails(); $pal = $this->_api->getPal(); $this->_configCacheType->save($pal, $cacheId); } catch (\Exception $e) { $this->_configCacheType->save(self::PAL_CACHE_ID, $cacheId); $this->_logger->critical($e); } } } return $this->_config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale(), $this->_quote->getBaseGrandTotal(), $pal); }
/** * Rewrite in order to clear configuration cache * * @return $this */ public function afterDelete() { parent::afterDelete(); $this->_configCacheType->clean(); return $this; }
/** * Rewrite in order to clear configuration cache * * @return $this */ public function afterDelete() { parent::afterDelete(); $this->_configCacheType->clean(); if ($this->getId() === $this->getGroup()->getDefaultStoreId()) { $ids = $this->getGroup()->getStoreIds(); if (!empty($ids) && count($ids) > 1) { unset($ids[$this->getId()]); $defaultId = current($ids); } else { $defaultId = null; } $this->getGroup()->setDefaultStoreId($defaultId); $this->getGroup()->save(); } return $this; }
/** * @return void */ protected function tearDown() { $this->configCacheType->save('', \Magento\Backend\Model\Menu\Config::CACHE_MENU_OBJECT); }
/** * Rewrite in order to clear configuration cache * * @return $this */ protected function _afterDelete() { parent::_afterDelete(); $this->_configCacheType->clean(); return $this; }
/** * Save services into the cache * * @param string $data serialized version of the webapi registry * @return $this */ protected function _saveToCache($data) { $this->_configCacheType->save($data, self::CACHE_ID, array(\Magento\Webapi\Model\Cache\Type::CACHE_TAG)); return $this; }