Example #1
0
 /**
  * Retrieve configuration metadata
  *
  * @return array
  */
 public function getData()
 {
     $scope = $this->request->getParam('scope');
     $scopeId = $this->request->getParam('scope_id');
     $data = [];
     if ($scope) {
         $showFallbackReset = false;
         list($fallbackScope, $fallbackScopeId) = $this->scopeFallbackResolver->getFallbackScope($scope, $scopeId);
         if ($fallbackScope && !$this->storeManager->isSingleStoreMode()) {
             $scope = $fallbackScope;
             $scopeId = $fallbackScopeId;
             $showFallbackReset = true;
         }
         $designConfig = $this->designConfigRepository->getByScope($scope, $scopeId);
         $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData();
         foreach ($fieldsData as $fieldData) {
             $element =& $data;
             foreach (explode('/', $fieldData->getFieldConfig()['fieldset']) as $fieldset) {
                 if (!isset($element[$fieldset]['children'])) {
                     $element[$fieldset]['children'] = [];
                 }
                 $element =& $element[$fieldset]['children'];
             }
             $fieldName = $fieldData->getFieldConfig()['field'];
             $element[$fieldName]['arguments']['data']['config']['default'] = $fieldData->getValue();
             $element[$fieldName]['arguments']['data']['config']['showFallbackReset'] = $showFallbackReset;
         }
     }
     return $data;
 }
 /**
  * Check whether value differs from parent scope's one
  *
  * @param string $value
  * @param string $scope
  * @param int $scopeId
  * @param string $path
  * @return bool
  */
 public function isDifferentFromDefault($value, $scope, $scopeId, $path)
 {
     list($scope, $scopeId) = $this->fallbackResolver->getFallbackScope($scope, $scopeId);
     if ($scope) {
         return !$this->isEqual($this->valueProcessor->process($value, $path), $this->valueProcessor->process($this->appConfig->getValue($path, $scope, $scopeId), $path));
     }
     return true;
 }
 public function testIsDifferentFromDefaultWithArrays()
 {
     $path = 'design/head/default_title';
     $this->fallbackResolver->expects($this->once())->method('getFallbackScope')->with('website', 1)->willReturn(['default', 0]);
     $this->appConfig->expects($this->once())->method('getValue')->with($path, 'default', 0)->willReturn([['qwe' => 123]]);
     $this->valueProcessor->expects($this->atLeastOnce())->method('process')->willReturnArgument(0);
     $this->assertTrue($this->valueChecker->isDifferentFromDefault([['sdf' => 1]], 'website', 1, ['path' => $path]));
 }
 public function testIsDifferentFromDefaultWithWebsiteScope()
 {
     $valueChecker = new ValueChecker($this->fallbackResolver, $this->appConfig, $this->valueProcessor);
     $this->fallbackResolver->expects($this->once())->method('getFallbackScope')->with('website', 1)->willReturn(['default', 0]);
     $this->appConfig->expects($this->once())->method('getValue')->with('design/head/default_title', 'default', 0)->willReturn('');
     $this->valueProcessor->expects($this->atLeastOnce())->method('process')->willReturnArgument(0);
     $this->assertTrue($valueChecker->isDifferentFromDefault('value', 'website', 1, 'design/head/default_title'));
 }
 /**
  * @param string $scope
  * @param string $scopeId
  * @param string $showFallbackReset
  * @dataProvider dataProviderGetData
  */
 public function testGetData($scope, $scopeId, $showFallbackReset)
 {
     $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $this->scopeFallbackResolver->expects($this->atLeastOnce())->method('getFallbackScope')->with($scope, $scopeId)->willReturn([$scope, $scopeId]);
     $this->storeManager->expects($this->once())->method('isSingleStoreMode')->willReturn(false);
     $this->designConfigRepository->expects($this->once())->method('getByScope')->with($scope, $scopeId)->willReturn($this->designConfig);
     $this->designConfig->expects($this->once())->method('getExtensionAttributes')->willReturn($this->designConfigExtension);
     $this->designConfigExtension->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]);
     $this->designConfigData->expects($this->atLeastOnce())->method('getFieldConfig')->willReturn(['field' => 'field', 'fieldset' => 'fieldset1']);
     $this->designConfigData->expects($this->once())->method('getValue')->willReturn('value');
     $result = $this->model->getData();
     $expected = ['fieldset1' => ['children' => ['field' => ['arguments' => ['data' => ['config' => ['default' => 'value', 'showFallbackReset' => $showFallbackReset]]]]]]];
     $this->assertEquals($expected, $result);
 }