Exemplo n.º 1
0
 /**
  * @inheritDoc
  */
 protected function _afterLoad()
 {
     foreach ($this->_items as $item) {
         $item->setData('value', $this->valueProcessor->process($item->getData('value'), $this->getData('scope'), $this->getData('scope_id'), $item->getData('path')));
     }
     parent::_afterLoad();
 }
 /**
  * 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;
 }
Exemplo n.º 3
0
 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'));
 }
Exemplo n.º 5
0
 /**
  * Test loadData
  *
  * @return void
  */
 public function testLoadData()
 {
     $this->scopeTreeMock->expects($this->any())->method('get')->willReturn(['scope' => ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 'scope_id' => null, 'scopes' => [['scope' => ScopeInterface::SCOPE_WEBSITE, 'scope_id' => 1, 'scopes' => [['scope' => ScopeInterface::SCOPE_GROUP, 'scope_id' => 1, 'scopes' => [['scope' => ScopeInterface::SCOPE_STORE, 'scope_id' => 1, 'scopes' => []]]]]]]]);
     $this->metadataProviderMock->expects($this->any())->method('get')->willReturn(['first_field' => ['path' => 'first/field/path', 'use_in_grid' => 0], 'second_field' => ['path' => 'second/field/path', 'use_in_grid' => true], 'third_field' => ['path' => 'third/field/path']]);
     $this->appConfigMock->expects($this->any())->method('getValue')->willReturnMap([['second/field/path', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, 'DefaultValue'], ['second/field/path', ScopeInterface::SCOPE_WEBSITE, 1, 'WebsiteValue'], ['second/field/path', ScopeInterface::SCOPE_STORE, 1, 'WebsiteValue']]);
     $this->valueProcessor->expects($this->atLeastOnce())->method('process')->withConsecutive(['DefaultValue', 'default', null, ['path' => 'second/field/path', 'use_in_grid' => 1]], ['WebsiteValue', 'website', 1, ['path' => 'second/field/path', 'use_in_grid' => 1]], ['WebsiteValue', 'store', 1, ['path' => 'second/field/path', 'use_in_grid' => 1]])->willReturnOnConsecutiveCalls('DefaultValue', 'WebsiteValue', 'WebsiteValue');
     $expectedResult = [new \Magento\Framework\DataObject(['store_website_id' => null, 'store_group_id' => null, 'store_id' => null, 'second_field' => 'DefaultValue']), new \Magento\Framework\DataObject(['store_website_id' => 1, 'store_group_id' => null, 'store_id' => null, 'second_field' => 'WebsiteValue']), new \Magento\Framework\DataObject(['store_website_id' => 1, 'store_group_id' => 1, 'store_id' => 1, 'second_field' => 'WebsiteValue'])];
     $this->assertEquals($expectedResult, $this->collection->getItems());
 }
 public function testProcess()
 {
     $path = 'design/head/logo';
     $value = 'path/to/logo';
     $this->backendModelFactory->expects($this->once())->method('createByPath')->with($path, ['value' => $value])->willReturn($this->backendModel);
     $this->backendModel->expects($this->once())->method('afterLoad');
     $this->backendModel->expects($this->once())->method('getValue')->willReturn($value);
     $this->assertEquals($value, $this->valueProcessor->process($value, $path));
 }
Exemplo n.º 7
0
 public function testProcess()
 {
     $path = 'design/head/logo';
     $value = 'path/to/logo';
     $scope = 'websites';
     $scopeId = 1;
     $this->backendModelFactory->expects($this->once())->method('createByPath')->with($path, ['value' => $value, 'field_config' => ['path' => $path], 'scope' => $scope, 'scope_id' => $scopeId])->willReturn($this->backendModel);
     $this->backendModel->expects($this->once())->method('afterLoad');
     $this->backendModel->expects($this->once())->method('getValue')->willReturn($value);
     $this->assertEquals($value, $this->valueProcessor->process($value, $scope, $scopeId, ['path' => $path]));
 }
 /**
  * Load design config from storage
  *
  * @param string $scope
  * @param mixed $scopeId
  * @return DesignConfigInterface
  */
 public function load($scope, $scopeId)
 {
     $designConfig = $this->configFactory->create($scope, $scopeId);
     $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData();
     foreach ($fieldsData as &$fieldData) {
         $value = $this->valueProcessor->process($this->scopeConfig->getValue($fieldData->getPath(), $scope, $scopeId), $fieldData->getPath());
         if ($value !== null) {
             $fieldData->setValue($value);
         }
     }
     return $designConfig;
 }
 /**
  * Retrieve fields metadata
  *
  * @param string $scope
  * @param int $scopeId
  * @return array
  */
 protected function getMetadataValues($scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = null)
 {
     $result = [];
     foreach ($this->metadataProvider->get() as $itemName => $itemData) {
         if (isset($itemData['use_in_grid']) && (bool) $itemData['use_in_grid']) {
             $result[$itemName] = $this->valueProcessor->process($this->appConfig->getValue($itemData['path'], $scope, $scopeId), $itemData['path']);
         }
     }
     return $result;
 }
 public function testLoad()
 {
     $scope = 'website';
     $scopeId = 1;
     $this->configFactory->expects($this->once())->method('create')->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('getPath')->willReturn('path');
     $this->scopeConfig->expects($this->once())->method('getValue')->with('path', $scope, $scopeId)->willReturn('value');
     $this->valueProcessor->expects($this->once())->method('process')->with('value', 'path')->willReturnArgument(0);
     $this->designConfigData->expects($this->once())->method('setValue')->with('value');
     $this->assertSame($this->designConfig, $this->model->load($scope, $scopeId));
 }