/** * @param string $name * @param string $primaryFieldName * @param string $requestFieldName * @param DataProvider\DataLoader $dataLoader * @param DataProvider\MetadataLoader $metadataLoader * @param CollectionFactory $configCollectionFactory * @param array $meta * @param array $data */ public function __construct($name, $primaryFieldName, $requestFieldName, DataProvider\DataLoader $dataLoader, DataProvider\MetadataLoader $metadataLoader, CollectionFactory $configCollectionFactory, array $meta = [], array $data = []) { parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); $this->dataLoader = $dataLoader; $this->metadataLoader = $metadataLoader; $this->collection = $configCollectionFactory->create(); $this->meta = array_merge($this->meta, $this->metadataLoader->getData()); }
public function testCreate() { $scope = 'website'; $scopeId = 1; $data = ['scope' => $scope, 'scopeId' => $scopeId, 'value' => 'value', 'config' => ['path' => 'design/head/default_title', 'backend_model' => 'Magento\\Framework\\App\\Config\\Value']]; $this->metadataProviderMock->expects($this->once())->method('get')->willReturn(['head_default_title' => ['path' => 'design/head/default_title']]); $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collection); $this->collection->expects($this->once())->method('addPathsFilter')->with(['head_default_title' => 'design/head/default_title']); $this->collection->expects($this->once())->method('addFieldToFilter')->with('scope', $scope); $this->collection->expects($this->once())->method('addScopeIdFilter')->with($scopeId); $this->collection->expects($this->once())->method('getData')->willReturn([['config_id' => 1, 'path' => 'design/head/default_title']]); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Config\\Value', ['data' => ['path' => 'design/head/default_title', 'scope' => $scope, 'scope_id' => $scopeId, 'field_config' => $data['config'], 'config_id' => 1]])->willReturn($this->backendModel); $this->backendModel->expects($this->once())->method('setValue')->willReturn('value'); $this->assertSame($this->backendModel, $this->model->create($data)); }
/** * Get stored data for scope and scope id * * @param string $scope * @param string $scopeId * @return array */ protected function getScopeData($scope, $scopeId) { if (!isset($this->storedData[$scope][$scopeId])) { $collection = $this->collectionFactory->create(); $collection->addPathsFilter($this->getMetadata()); $collection->addFieldToFilter('scope', $scope); $collection->addScopeIdFilter($scopeId); $this->storedData[$scope][$scopeId] = $collection->getData(); } return $this->storedData[$scope][$scopeId]; }