Skip to content

Commit 96d5e1b

Browse files
author
vpaladiychuk
committed
MAGETWO-2204: "HEADERS ALREADY SENT" When Controller Action Outputs Directly
1 parent f2a9e05 commit 96d5e1b

File tree

1 file changed

+77
-0
lines changed
  • dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Controller\Adminhtml\Index;
8+
9+
class ViewfileTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @throws \Magento\Framework\App\Action\NotFoundException
13+
* @expectedException \Magento\Framework\App\Action\NotFoundException
14+
*/
15+
public function testExecuteNoParamsShouldThrowException()
16+
{
17+
/** @var \Magento\Customer\Controller\Adminhtml\Index\Viewfile $controller */
18+
$controller = (new \Magento\TestFramework\Helper\ObjectManager($this))
19+
->getObject('Magento\Customer\Controller\Adminhtml\Index\Viewfile');
20+
$controller->execute();
21+
}
22+
23+
public function testExecuteParamFile()
24+
{
25+
$decodedFile = 'decoded_file';
26+
$file = 'file';
27+
$fileName = 'customer/' . $file;
28+
$path = 'path';
29+
30+
$requestMock = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false);
31+
$requestMock->expects($this->atLeastOnce())->method('getParam')->with('file')->willReturn($decodedFile);
32+
33+
$responseMock = $this->getMock('Magento\Framework\App\ResponseInterface', [], [], '', false);
34+
35+
$directoryMock = $this->getMock('Magento\Framework\Filesystem\Directory\ReadInterface', [], [], '', false);
36+
$directoryMock->expects($this->once())->method('getAbsolutePath')->with($fileName)->willReturn($path);
37+
38+
$fileSystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
39+
$fileSystemMock->expects($this->once())->method('getDirectoryRead')
40+
->with(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)
41+
->willReturn($directoryMock);
42+
43+
$storage = $this->getMock('Magento\Core\Helper\File\Storage', [], [], '', false);
44+
$storage->expects($this->once())->method('processStorageFile')->with($path)->willReturn(true);
45+
46+
$objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface', [], [], '', false);
47+
$objectManager->expects($this->at(0))->method('get')->with('Magento\Framework\Filesystem')
48+
->willReturn($fileSystemMock);
49+
$objectManager->expects($this->at(1))->method('get')->with('Magento\Core\Helper\File\Storage')
50+
->willReturn($storage);
51+
52+
$contextMock = $this->getMock('Magento\Backend\App\Action\Context', [], [], '', false);
53+
$contextMock->expects($this->once())->method('getRequest')->willReturn($requestMock);
54+
$contextMock->expects($this->once())->method('getResponse')->willReturn($responseMock);
55+
$contextMock->expects($this->once())->method('getObjectManager')->willReturn($objectManager);
56+
57+
$urlDecoderMock = $this->getMock('Magento\Framework\Url\DecoderInterface', [], [], '', false);
58+
$urlDecoderMock->expects($this->once())->method('decode')->with($decodedFile)->willReturn($file);
59+
60+
$resultRawMock = $this->getMock('Magento\Framework\Controller\Result\Raw', [], [], '', false);
61+
$resultRawFactoryMock = $this->getMock(
62+
'Magento\Framework\Controller\Result\RawFactory',
63+
['create'],
64+
[],
65+
'',
66+
false
67+
);
68+
$resultRawFactoryMock->expects($this->once())->method('create')->willReturn($resultRawMock);
69+
70+
/** @var \Magento\Customer\Controller\Adminhtml\Index\Viewfile $controller */
71+
$controller = (new \Magento\TestFramework\Helper\ObjectManager($this))->getObject(
72+
'Magento\Customer\Controller\Adminhtml\Index\Viewfile',
73+
['context' => $contextMock, 'urlDecoder' => $urlDecoderMock, 'resultRawFactory' => $resultRawFactoryMock]
74+
);
75+
$this->assertSame($resultRawMock, $controller->execute());
76+
}
77+
}

0 commit comments

Comments
 (0)