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;
 }