Ejemplo n.º 1
0
 public function testExecuteGetParamImage()
 {
     $decodedFile = 'decoded_file';
     $file = 'file';
     $fileName = 'customer/' . $file;
     $path = 'path';
     $stat = ['size' => 10, 'mtime' => 10];
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['file', null, null], ['image', null, $decodedFile]]);
     $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($fileName)->willReturn($path);
     $this->directoryMock->expects($this->once())->method('stat')->with($path)->willReturn($stat);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->with(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->willReturn($this->directoryMock);
     $this->storage->expects($this->once())->method('processStorageFile')->with($path)->willReturn(true);
     $this->objectManager->expects($this->any())->method('get')->willReturnMap([['Magento\\Framework\\Filesystem', $this->fileSystemMock], ['Magento\\MediaStorage\\Helper\\File\\Storage', $this->storage]]);
     $this->urlDecoderMock->expects($this->once())->method('decode')->with($decodedFile)->willReturn($file);
     $this->resultRawMock->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf();
     $this->resultRawMock->expects($this->any())->method('setHeader')->willReturnMap([['Pragma', 'public', true, $this->resultRawMock], ['Content-type', 'application/octet-stream', true, $this->resultRawMock], ['Content-Length', $stat['size'], false, $this->resultRawMock], ['Pragma', 'public', true, $this->resultRawMock]]);
     $this->resultRawFactoryMock = $this->getMock('Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false);
     $this->resultRawFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRawMock);
     /** @var \Magento\Customer\Controller\Adminhtml\Index\Viewfile $controller */
     $controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Viewfile', ['context' => $this->contextMock, 'urlDecoder' => $this->urlDecoderMock, 'resultRawFactory' => $this->resultRawFactoryMock]);
     $this->assertSame($this->resultRawMock, $controller->execute());
 }