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)); }
public function testCreateByPath() { $path = 'design/head/default_title'; $backendModelType = 'Magento\\Theme\\Model\\Design\\Backend\\Exceptions'; $backendModel = $this->getMockBuilder($backendModelType)->disableOriginalConstructor()->getMock(); $this->metadataProviderMock->expects($this->once())->method('get')->willReturn(['head_default_title' => ['path' => $path, 'backend_model' => $backendModelType]]); $this->objectManagerMock->expects($this->once())->method('create')->with($backendModelType, ['data' => []])->willReturn($backendModel); $this->assertEquals($backendModel, $this->model->createByPath($path)); }
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])); }
/** * Retrieve backend model by field code * * @param string $code * @return File * @throws LocalizedException */ protected function getBackendModel($code) { $metadata = $this->metadataProvider->get(); if (!(isset($metadata[$code]) && isset($metadata[$code]['backend_model']))) { throw new LocalizedException(__('Backend model is not specified for %1', $code)); } return $this->backendModelFactory->createByPath($metadata[$code]['path']); }
public function testSaveToTmp() { $path = 'design/header/logo_src'; $fieldCode = 'header_logo_src'; $metadata = [$fieldCode => ['path' => $path, 'backend_model' => 'Magento\\Theme\\Model\\Design\\Backend\\Image']]; $this->metadataProvider->expects($this->once())->method('get')->willReturn($metadata); $this->backendModelFactory->expects($this->once())->method('createByPath')->with($path)->willReturn($this->backendModel); $this->uploaderFactory->expects($this->once())->method('create')->with(['fileId' => $fieldCode])->willReturn($this->uploader); $this->uploader->expects($this->once())->method('setAllowRenameFiles')->with(true); $this->uploader->expects($this->once())->method('setFilesDispersion')->with(false); $this->backendModel->expects($this->once())->method('getAllowedExtensions')->willReturn(['png', 'jpg']); $this->uploader->expects($this->once())->method('setAllowedExtensions')->with(['png', 'jpg']); $this->uploader->expects($this->once())->method('addValidateCallback')->with('size', $this->backendModel, 'validateMaxSize'); $this->imageConfig->expects($this->once())->method('getAbsoluteTmpMediaPath')->willReturn('absolute/path/to/tmp/media'); $this->uploader->expects($this->once())->method('save')->with('absolute/path/to/tmp/media')->willReturn(['file' => 'file.jpg', 'size' => '234234']); $this->imageConfig->expects($this->once())->method('getTmpMediaUrl')->with('file.jpg')->willReturn('http://magento2.com/pub/media/tmp/file.jpg'); $this->assertEquals(['file' => 'file.jpg', 'size' => '234234', 'url' => 'http://magento2.com/pub/media/tmp/file.jpg'], $this->imageProcessor->saveToTmp($fieldCode)); }
/** * Delete design configuration from storage * * @param DesignConfigInterface $designConfig * @return void */ public function delete(DesignConfigInterface $designConfig) { $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData(); /* @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 (!$backendModel->isObjectNew()) { $deleteTransaction->addObject($backendModel); } } $deleteTransaction->delete(); }
public function testDelete() { $scope = 'website'; $scopeId = 1; $backendModel = $this->getMockBuilder('Magento\\Framework\\App\\Config\\Value')->disableOriginalConstructor()->getMock(); $this->designConfig->expects($this->once())->method('getExtensionAttributes')->willReturn($this->designConfigExtension); $this->designConfigExtension->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]); $this->transactionFactoryMock->expects($this->once())->method('create')->willReturn($this->transactionMock); $this->designConfigData->expects($this->once())->method('getValue')->willReturn('value'); $this->designConfigData->expects($this->once())->method('getFieldConfig')->willReturn([]); $this->designConfig->expects($this->once())->method('getScope')->willReturn($scope); $this->designConfig->expects($this->once())->method('getScopeId')->willReturn($scopeId); $this->backendModelFactoryMock->expects($this->once())->method('create')->with(['value' => 'value', 'scope' => $scope, 'scopeId' => $scopeId, 'config' => []])->willReturn($backendModel); $this->transactionMock->expects($this->once())->method('addObject')->with($backendModel); $this->transactionMock->expects($this->once())->method('delete'); $this->model->delete($this->designConfig); }
/** * Process value * * @param string $value * @param string $scope * @param string $scopeId * @param array $fieldConfig * @return mixed */ public function process($value, $scope, $scopeId, array $fieldConfig) { $backendModel = $this->backendModelFactory->createByPath($fieldConfig['path'], ['value' => $value, 'field_config' => $fieldConfig, 'scope' => $scope, 'scope_id' => $scopeId]); $backendModel->afterLoad(); return $backendModel->getValue(); }
/** * Process value * * @param string $value * @param string $path * @return mixed */ public function process($value, $path) { $backendModel = $this->backendModelFactory->createByPath($path, ['value' => $value]); $backendModel->afterLoad(); return $backendModel->getValue(); }