コード例 #1
0
 /**
  * @dataProvider dataForExecute
  */
 public function testExecute($fileResult, $expectedResult)
 {
     $this->uploaderFactoryMock->expects($this->once())->method('create')->willReturn($this->uploaderMock);
     $this->adapterFactoryMock->expects($this->once())->method('create')->willReturn($this->adapterMock);
     $this->filesystemMock->expects($this->once())->method('getDirectoryRead')->with('media')->willReturn($this->mediaDirectoryMock);
     $this->uploaderMock->expects($this->once())->method('save')->willReturn($fileResult);
     $this->configMock->expects($this->once())->method('getTmpMediaUrl')->with($fileResult['file'])->willReturn('http://domain.com/tpm_dir/m/a/magento.png');
     $this->swatchHelperMock->expects($this->once())->method('moveImageFromTmp')->with('/m/a/magento.png.tmp')->willReturn('/m/a/magento.png');
     $this->swatchHelperMock->expects($this->once())->method('generateSwatchVariations');
     $this->swatchHelperMock->expects($this->once())->method('getSwatchMediaUrl')->willReturn('http://domain.com/media/path/');
     $this->responseMock->expects($this->once())->method('setBody')->willReturn(json_encode($expectedResult));
     $this->controller->execute();
 }
コード例 #2
0
 /**
  * Set up
  */
 public function setUp()
 {
     $this->contextMock = $this->getMock('\\Magento\\Backend\\App\\Action\\Context', [], [], '', false);
     $this->rawFactoryMock = $this->getMock('\\Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false);
     $response = $this->getMock('\\Magento\\Framework\\Controller\\Result\\Raw', [], [], '', false);
     $this->rawFactoryMock->expects($this->once())->method('create')->willReturn($response);
     $this->configMock = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Media\\Config', [], [], '', false);
     $this->filesystemMock = $this->getMock('\\Magento\\Framework\\Filesystem', [], [], '', false);
     $this->adapterMock = $this->getMock('\\Magento\\Framework\\Image', [], [], '', false);
     $this->adapterFactoryMock = $this->getMock('\\Magento\\Framework\\Image\\AdapterFactory', ['create'], [], '', false);
     $this->abstractAdapter = $this->getMock('\\Magento\\Framework\\Image\\Adapter\\AbstractAdapter', [], [], '', false);
     $this->adapterFactoryMock->expects($this->once())->method('create')->willReturn($this->abstractAdapter);
     $this->curlMock = $this->getMock('\\Magento\\Framework\\HTTP\\Adapter\\Curl', [], [], '', false);
     $this->storageFileMock = $this->getMock('\\Magento\\MediaStorage\\Model\\ResourceModel\\File\\Storage\\File', [], [], '', false);
     $this->request = $this->getMock('\\Magento\\Framework\\App\\RequestInterface');
     $this->contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->image = $objectManager->getObject('\\Magento\\ProductVideo\\Controller\\Adminhtml\\Product\\Gallery\\RetrieveImage', ['context' => $this->contextMock, 'resultRawFactory' => $this->rawFactoryMock, 'mediaConfig' => $this->configMock, 'fileSystem' => $this->filesystemMock, 'imageAdapterFactory' => $this->adapterFactoryMock, 'curl' => $this->curlMock, 'fileUtility' => $this->storageFileMock]);
 }
コード例 #3
0
 protected function prepareExecuteTest()
 {
     $directiveParam = 'e3ttZWRpYSB1cmw9Ind5c2l3eWcvYnVubnkuanBnIn19';
     $directive = '{{media url="wysiwyg/image.jpg"}}';
     $this->requestMock->expects($this->once())->method('getParam')->with('___directive')->willReturn($directiveParam);
     $this->urlDecoderMock->expects($this->once())->method('decode')->with($directiveParam)->willReturn($directive);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Template\\Filter')->willReturn($this->templateFilterMock);
     $this->templateFilterMock->expects($this->once())->method('filter')->with($directive)->willReturn(self::IMAGE_PATH);
     $this->objectManagerMock->expects($this->any())->method('get')->willReturnMap([['Magento\\Framework\\Image\\AdapterFactory', $this->imageAdapterFactoryMock], ['Magento\\Cms\\Model\\Wysiwyg\\Config', $this->wysiwygConfigMock], ['Psr\\Log\\LoggerInterface', $this->loggerMock]]);
     $this->imageAdapterFactoryMock->expects($this->once())->method('create')->willReturn($this->imageAdapterMock);
 }
コード例 #4
0
 /**
  * cover \Magento\Theme\Model\Wysiwyg\Storage::_createThumbnail
  * cover \Magento\Theme\Model\Wysiwyg\Storage::uploadFile
  */
 public function testUploadFile()
 {
     $uploader = $this->_prepareUploader();
     $uploader->expects($this->once())->method('save')->will($this->returnValue(['not_empty']));
     $this->_helperStorage->expects($this->once())->method('getStorageType')->will($this->returnValue(\Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE));
     /** Prepare filesystem */
     $this->directoryWrite->expects($this->any())->method('isFile')->will($this->returnValue(true));
     $this->directoryWrite->expects($this->once())->method('isReadable')->will($this->returnValue(true));
     /** Prepare image */
     $image = $this->getMock('Magento\\Framework\\Image\\Adapter\\Gd2', [], [], '', false);
     $image->expects($this->once())->method('open')->will($this->returnValue(true));
     $image->expects($this->once())->method('keepAspectRatio')->will($this->returnValue(true));
     $image->expects($this->once())->method('resize')->will($this->returnValue(true));
     $image->expects($this->once())->method('save')->will($this->returnValue(true));
     $this->_imageFactory->expects($this->at(0))->method('create')->will($this->returnValue($image));
     /** Prepare session */
     $session = $this->getMock('Magento\\Backend\\Model\\Session', [], [], '', false);
     $this->_helperStorage->expects($this->any())->method('getSession')->will($this->returnValue($session));
     $expectedResult = ['not_empty', 'cookie' => ['name' => null, 'value' => null, 'lifetime' => null, 'path' => null, 'domain' => null]];
     $this->assertEquals($expectedResult, $this->_storageModel->uploadFile($this->_storageRoot));
 }