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));
 }
示例#2
0
 /**
  * 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));
 }
 /**
  * Retrieve metadata
  *
  * @return array
  */
 protected function getMetadata()
 {
     if (!$this->metadata) {
         $this->metadata = $this->metadataProvider->get();
         array_walk($this->metadata, function (&$value) {
             $value = $value['path'];
         });
     }
     return $this->metadata;
 }