Ejemplo n.º 1
0
 /**
  * @return ResultPage|ResultRedirect
  */
 public function execute()
 {
     $scope = $this->getRequest()->getParam('scope');
     $scopeId = $this->getRequest()->getParam('scope_id');
     if (!$this->scopeValidator->isValidScope($scope, $scopeId)) {
         /** @var ResultRedirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('theme/design_config/');
         return $resultRedirect;
     }
     /** @var ResultPage $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $resultPage->setActiveMenu('Magento_Theme::design_config');
     $resultPage->getConfig()->getTitle()->prepend(__('%1', $this->getScopeTitle()));
     return $resultPage;
 }
 public function testScopeRedirect()
 {
     $scope = 'test';
     $scopeId = 1;
     $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $this->scopeValidator->expects($this->once())->method('isValidScope')->with($scope, $scopeId)->willReturn(false);
     $this->resultRedirect->expects($this->once())->method('setPath')->with('theme/design_config/')->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->controller->execute());
 }
Ejemplo n.º 3
0
 public function testCreateInSingleStoreMode()
 {
     $scope = 'default';
     $scopeId = 0;
     $data = ['header_default_title' => 'value'];
     $metadata = ['header_default_title' => ['path' => 'design/header/default_title', 'fieldset' => 'head'], 'head_default_description' => ['path' => 'design/head/default_description', 'fieldset' => 'head']];
     $this->scopeValidator->expects($this->once())->method('isValidScope')->with($scope, $scopeId)->willReturn(true);
     $this->storeManager->expects($this->once())->method('isSingleStoreMode')->willReturn(true);
     $this->storeManager->expects($this->once())->method('getWebsites')->willReturn([$this->website]);
     $this->website->expects($this->once())->method('getId')->willReturn(1);
     $this->designConfigFactory->expects($this->once())->method('create')->willReturn($this->designConfig);
     $this->designConfig->expects($this->once())->method('setScope')->willReturn('websites');
     $this->designConfig->expects($this->once())->method('setScopeId')->willReturn(1);
     $this->metadataProvider->expects($this->once())->method('get')->willReturn($metadata);
     $this->designConfigDataFactory->expects($this->exactly(2))->method('create')->willReturn($this->designConfigData);
     $this->designConfigData->expects($this->exactly(2))->method('setPath')->withConsecutive(['design/header/default_title'], ['design/head/default_description']);
     $this->designConfigData->expects($this->exactly(2))->method('setFieldConfig')->withConsecutive([['path' => 'design/header/default_title', 'fieldset' => 'head', 'field' => 'header_default_title']], [['path' => 'design/head/default_description', 'fieldset' => 'head', 'field' => 'head_default_description']]);
     $this->designConfigData->expects($this->once())->method('setValue')->with('value');
     $this->configExtensionFactory->expects($this->once())->method('create')->willReturn($this->designConfigExtension);
     $this->designConfigExtension->expects($this->once())->method('setDesignConfigData')->with([$this->designConfigData, $this->designConfigData]);
     $this->designConfig->expects($this->once())->method('setExtensionAttributes')->with($this->designConfigExtension);
     $this->assertSame($this->designConfig, $this->factory->create($scope, $scopeId, $data));
 }
 /**
  * Create Design Configuration for scope
  *
  * @param mixed $scope
  * @param int $scopeId
  * @param array $data
  * @return DesignConfigInterface
  * @throws LocalizedException
  */
 public function create($scope, $scopeId, array $data = [])
 {
     if (!$this->scopeValidator->isValidScope($scope, $scopeId)) {
         throw new LocalizedException(__('Invalid scope or scope id'));
     }
     $designConfigData = $this->getDesignConfigData($scope, $scopeId);
     $configData = [];
     foreach ($this->metadataProvider->get() as $name => $metadata) {
         $metadata['field'] = $name;
         /** @var DesignConfigDataInterface $configDataObject */
         $configDataObject = $this->designConfigDataFactory->create();
         $configDataObject->setPath($metadata['path']);
         $configDataObject->setFieldConfig($metadata);
         if (isset($data[$name]) || isset($metadata['default'])) {
             $configDataObject->setValue(isset($data[$name]) ? $data[$name] : $metadata['default']);
         }
         $configData[] = $configDataObject;
     }
     /** @var DesignConfigExtension $designConfigExtension */
     $designConfigExtension = $this->configExtensionFactory->create();
     $designConfigExtension->setDesignConfigData($configData);
     $designConfigData->setExtensionAttributes($designConfigExtension);
     return $designConfigData;
 }