Beispiel #1
0
 /**
  * Start environment emulation of the specified store
  *
  * Function returns information about initial store environment and emulates environment of another store
  *
  * @param integer $storeId
  * @param string $area
  * @param bool $force A true value will ensure that environment is always emulated, regardless of current store
  * @return void
  */
 public function startEnvironmentEmulation($storeId, $area = \Magento\Framework\App\Area::AREA_FRONTEND, $force = false)
 {
     // Only allow a single level of emulation
     if ($this->initialEnvironmentInfo !== null) {
         $this->logger->error(__('Environment emulation nesting is not allowed.'));
         return;
     }
     if ($storeId == $this->_storeManager->getStore()->getStoreId() && !$force) {
         return;
     }
     $this->storeCurrentEnvironmentInfo();
     // emulate inline translations
     $this->inlineTranslation->suspend($this->inlineConfig->isActive($storeId));
     // emulate design
     $storeTheme = $this->_viewDesign->getConfigurationDesignTheme($area, ['store' => $storeId]);
     $this->_viewDesign->setDesignTheme($storeTheme, $area);
     if ($area == \Magento\Framework\App\Area::AREA_FRONTEND) {
         $designChange = $this->_design->loadChange($storeId);
         if ($designChange->getData()) {
             $this->_viewDesign->setDesignTheme($designChange->getDesign(), $area);
         }
     }
     // Current store needs to be changed right before locale change and after design change
     $this->_storeManager->setCurrentStore($storeId);
     // emulate locale
     $newLocaleCode = $this->_scopeConfig->getValue($this->_localeResolver->getDefaultLocalePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
     $this->_localeResolver->setLocale($newLocaleCode);
     $this->_translate->setLocale($newLocaleCode);
     $this->_translate->loadData($area);
     return;
 }
Beispiel #2
0
 public function testStartDefaults()
 {
     // Test data
     $inlineTranslate = false;
     $initArea = 'initial area';
     $initTheme = 'initial design theme';
     $initStore = 1;
     $initLocale = 'initial locale code';
     $newInlineTranslate = false;
     $newLocale = 'new locale code';
     $newArea = \Magento\Framework\App\Area::AREA_FRONTEND;
     // Stubs
     $this->inlineTranslationMock->expects($this->any())->method('isEnabled')->willReturn($inlineTranslate);
     $this->viewDesignMock->expects($this->any())->method('getArea')->willReturn($initArea);
     $this->viewDesignMock->expects($this->any())->method('getDesignTheme')->willReturn($initTheme);
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->any())->method('getStoreId')->willReturn($initStore);
     $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn($initLocale);
     $this->inlineConfigMock->expects($this->any())->method('isActive')->willReturn($newInlineTranslate);
     $this->viewDesignMock->expects($this->any())->method('getConfigurationDesignTheme')->willReturn($initTheme);
     $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn($newLocale);
     // Expectations
     $this->storeMock->expects($this->any())->method('getStoreId')->willReturn($initStore);
     $this->inlineTranslationMock->expects($this->any())->method('suspend')->with($newInlineTranslate);
     $this->viewDesignMock->expects($this->any())->method('setDesignTheme')->with($initTheme);
     $this->localeResolverMock->expects($this->any())->method('setLocale')->with($newLocale);
     $this->translateMock->expects($this->any())->method('setLocale')->with($newLocale);
     $this->translateMock->expects($this->any())->method('loadData')->with($newArea);
     $this->storeManagerMock->expects($this->any())->method('setCurrentStore')->with(self::NEW_STORE_ID);
     // Test
     $this->model->startEnvironmentEmulation(self::NEW_STORE_ID, \Magento\Framework\App\Area::AREA_FRONTEND);
 }
 /**
  * @param bool $isEnabled
  * @param bool $isActive
  * @param bool $isDevAllowed
  * @param null|string $scope
  */
 protected function prepareIsAllowed($isEnabled, $isActive, $isDevAllowed, $scope = null)
 {
     $scopeMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface', [], [], '', false);
     $this->stateMock->expects($this->any())->method('isEnabled')->will($this->returnValue($isEnabled));
     $this->scopeResolverMock->expects($this->once())->method('getScope')->with($scope)->will($this->returnValue($scopeMock));
     $this->configMock->expects($this->once())->method('isActive')->with($scopeMock)->will($this->returnValue($isActive));
     $this->configMock->expects($this->exactly((int) $isActive))->method('isDevAllowed')->will($this->returnValue($isDevAllowed));
 }
Beispiel #4
0
 /**
  * Check if Inline Translates is allowed
  *
  * @return bool
  */
 public function isAllowed()
 {
     if ($this->isAllowed === null) {
         if (!$this->scope instanceof \Magento\Framework\App\ScopeInterface) {
             $scope = $this->scopeResolver->getScope($this->scope);
         }
         $this->isAllowed = $this->config->isActive($scope) && $this->config->isDevAllowed($scope);
     }
     return $this->state->isEnabled() && $this->isAllowed;
 }
Beispiel #5
0
 /**
  * Emulate inline translation of the specified store
  *
  * Function disables inline translation if $storeId is null
  *
  * @param integer|null $storeId
  * @return boolean initial inline translation state
  */
 protected function _emulateInlineTranslation($storeId = null)
 {
     if (is_null($storeId)) {
         $newTranslateInline = false;
     } else {
         $newTranslateInline = $this->inlineConfig->isActive($storeId);
     }
     $translateInline = $this->inlineTranslation->isEnabled();
     $this->inlineTranslation->suspend($newTranslateInline);
     return $translateInline;
 }