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'));
 }
 public function testSave()
 {
     $scope = 'website';
     $scopeId = 1;
     $this->transactionFactoryMock->expects($this->exactly(2))->method('create')->willReturn($this->transactionMock);
     $this->designConfigMock->expects($this->once())->method('getExtensionAttributes')->willReturn($this->extensionAttributes);
     $this->extensionAttributes->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]);
     $this->designConfigData->expects($this->atLeastOnce())->method('getValue')->willReturn('value');
     $this->designConfigMock->expects($this->exactly(2))->method('getScope')->willReturn($scope);
     $this->designConfigMock->expects($this->exactly(2))->method('getScopeId')->willReturn($scopeId);
     $this->designConfigData->expects($this->exactly(2))->method('getFieldConfig')->willReturn(['path' => 'design/head/default_title']);
     $this->backendModelFactoryMock->expects($this->once())->method('create')->with(['value' => 'value', 'scope' => $scope, 'scopeId' => $scopeId, 'config' => ['path' => 'design/head/default_title']])->willReturn($this->backendModelMock);
     $this->valueCheckerMock->expects($this->once())->method('isDifferentFromDefault')->with('value', $scope, $scopeId, 'design/head/default_title')->willReturn(true);
     $this->transactionMock->expects($this->once())->method('addObject')->with($this->backendModelMock);
     $this->transactionMock->expects($this->once())->method('save');
     $this->transactionMock->expects($this->once())->method('delete');
     $this->model->save($this->designConfigMock);
 }
 /**
  * Set design config to storage
  *
  * @param DesignConfigInterface $designConfig
  * @return void
  */
 public function save(DesignConfigInterface $designConfig)
 {
     $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData();
     /* @var $saveTransaction \Magento\Framework\DB\Transaction */
     $saveTransaction = $this->transactionFactory->create();
     /* @var $deleteTransaction \Magento\Framework\DB\Transaction */
     $deleteTransaction = $this->transactionFactory->create();
     foreach ($fieldsData as $fieldData) {
         /** @var ValueInterface|Value $backendModel */
         $backendModel = $this->backendModelFactory->create(['value' => $fieldData->getValue(), 'scope' => $designConfig->getScope(), 'scopeId' => $designConfig->getScopeId(), 'config' => $fieldData->getFieldConfig()]);
         if ($fieldData->getValue() !== null && $this->valueChecker->isDifferentFromDefault($fieldData->getValue(), $designConfig->getScope(), $designConfig->getScopeId(), $fieldData->getFieldConfig()['path'])) {
             $saveTransaction->addObject($backendModel);
         } elseif (!$backendModel->isObjectNew()) {
             $deleteTransaction->addObject($backendModel);
         }
     }
     $saveTransaction->save();
     $deleteTransaction->delete();
 }