74 private $validatorMock;
79 private $fileDriverMock;
86 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
87 $this->contextMock = $this->createMock(\
Magento\Backend\
App\Action\Context::class);
88 $this->validatorMock = $this
89 ->createMock(\
Magento\MediaStorage\Model\File\
Validator\NotProtectedExtension::class);
90 $this->rawFactoryMock =
91 $this->createPartialMock(\
Magento\Framework\Controller\Result\RawFactory::class, [
'create']);
92 $response = new \Magento\Framework\DataObject();
93 $this->rawFactoryMock->expects($this->once())->method(
'create')->willReturn(
$response);
94 $this->configMock = $this->createMock(\
Magento\Catalog\Model\Product\Media\Config::class);
95 $this->filesystemMock = $this->createMock(\
Magento\Framework\Filesystem::class);
97 $this->createMock(\
Magento\Framework\Image::class);
98 $this->adapterFactoryMock =
99 $this->createPartialMock(\
Magento\Framework\Image\AdapterFactory::class, [
'create']);
100 $this->abstractAdapter = $this->createMock(\
Magento\Framework\Image\Adapter\AbstractAdapter::class);
101 $this->adapterFactoryMock->expects($this->once())->method(
'create')->willReturn($this->abstractAdapter);
102 $this->curlMock = $this->createMock(\
Magento\Framework\HTTP\Adapter\Curl::class);
103 $this->storageFileMock = $this->createMock(\
Magento\MediaStorage\Model\
ResourceModel\File\Storage\File::class);
104 $this->request = $this->createMock(\
Magento\Framework\
App\RequestInterface::class);
105 $this->fileDriverMock = $this->createMock(\
Magento\Framework\Filesystem\DriverInterface::class);
106 $this->contextMock->expects($this->any())->method(
'getRequest')->will($this->returnValue($this->request));
107 $managerMock = $this->getMockBuilder(\
Magento\Framework\ObjectManagerInterface::class)
108 ->disableOriginalConstructor()
109 ->setMethods([
'get'])
110 ->getMockForAbstractClass();
111 $this->contextMock->expects($this->any())->method(
'getRequest')->will($this->returnValue($this->request));
112 $this->contextMock->expects($this->any())->method(
'getObjectManager')->willReturn($managerMock);
115 \
Magento\ProductVideo\Controller\Adminhtml\Product\Gallery\RetrieveImage::class,
117 'context' => $this->contextMock,
118 'resultRawFactory' => $this->rawFactoryMock,
119 'mediaConfig' => $this->configMock,
120 'fileSystem' => $this->filesystemMock,
121 'imageAdapterFactory' => $this->adapterFactoryMock,
122 'curl' => $this->curlMock,
123 'fileUtility' => $this->storageFileMock,
125 'extensionValidator' => $this->validatorMock,
126 'fileDriver' => $this->fileDriverMock,
136 $this->request->expects($this->any())->method(
'getParam')->willReturn(
137 'https://example.com/test.jpg' 139 $readInterface = $this->createMock(
140 \
Magento\Framework\Filesystem\Directory\ReadInterface::class
142 $writeInterface = $this->createMock(
143 \
Magento\Framework\Filesystem\Directory\WriteInterface::class
145 $this->filesystemMock->expects($this->any())->method(
'getDirectoryRead')->willReturn($readInterface);
146 $readInterface->expects($this->any())->method(
'getAbsolutePath')->willReturn(
'');
147 $this->abstractAdapter->expects($this->any())->method(
'validateUploadFile')->willReturn(
'true');
148 $this->validatorMock->expects($this->once())->method(
'isValid')->with(
'jpg')->willReturn(
'true');
149 $this->filesystemMock->expects($this->once())->method(
'getDirectoryWrite')->willReturn($writeInterface);
150 $this->curlMock->expects($this->once())->method(
'read')->willReturn(
'testimage');
152 $this->image->execute();
160 $this->request->expects($this->any())->method(
'getParam')->willReturn(
161 'https://example.com/test.jpg' 163 $readInterface = $this->createMock(
164 \
Magento\Framework\Filesystem\Directory\ReadInterface::class,
170 $writeInterface = $this->createMock(
171 \
Magento\Framework\Filesystem\Directory\WriteInterface::class,
177 $this->filesystemMock->expects($this->any())->method(
'getDirectoryRead')->willReturn($readInterface);
178 $readInterface->expects($this->any())->method(
'getAbsolutePath')->willReturn(
'');
179 $this->abstractAdapter->expects($this->any())
180 ->method(
'validateUploadFile')
181 ->willThrowException(
new \Exception(
'Invalid File.'));
182 $this->validatorMock->expects($this->once())->method(
'isValid')->with(
'jpg')->willReturn(
'true');
183 $this->curlMock->expects($this->once())->method(
'read')->willReturn(
'testimage');
184 $this->filesystemMock->expects($this->once())->method(
'getDirectoryWrite')->willReturn($writeInterface);
185 $writeInterface->expects($this->once())->method(
'isExist')->willReturn(
'true');
186 $writeInterface->expects($this->once())->method(
'delete')->willReturn(
'false');
188 $this->image->execute();
196 $this->request->expects($this->any())->method(
'getParam')->willReturn(
197 'https://example.com/test.php' 199 $readInterface = $this->createMock(
200 \
Magento\Framework\Filesystem\Directory\ReadInterface::class,
206 $writeInterface = $this->createMock(
207 \
Magento\Framework\Filesystem\Directory\WriteInterface::class,
213 $this->filesystemMock->expects($this->any())->method(
'getDirectoryRead')->willReturn($readInterface);
214 $readInterface->expects($this->any())->method(
'getAbsolutePath')->willReturn(
'');
215 $this->abstractAdapter->expects($this->never())->method(
'validateUploadFile');
216 $this->validatorMock->expects($this->once())->method(
'isValid')->with(
'php')->willReturn(
false);
217 $this->filesystemMock->expects($this->once())->method(
'getDirectoryWrite')->willReturn($writeInterface);
218 $writeInterface->expects($this->never())->method(
'isExist');
220 $this->image->execute();
testExecuteInvalidFileImage()
testExecuteInvalidFileType()