|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DmFilemanTest\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use DmFileman\Controller\ListController; |
|
6
|
|
|
use DmTest\Controller\Plugin\MockFactory as PluginMockFactory; |
|
7
|
|
|
|
|
8
|
|
|
class ListControllerTest extends \PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var ListController */ |
|
11
|
|
|
protected $sut; |
|
12
|
|
|
|
|
13
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
|
14
|
|
|
protected $fileManagerMock; |
|
15
|
|
|
|
|
16
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
|
17
|
|
|
protected $createDirFormMock; |
|
18
|
|
|
|
|
19
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
|
20
|
|
|
protected $uploadFileFormMock; |
|
21
|
|
|
|
|
22
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
|
23
|
|
|
protected $deleteFileFormMock; |
|
24
|
|
|
|
|
25
|
|
|
/** @var PluginMockFactory */ |
|
26
|
|
|
protected $mockFactory; |
|
27
|
|
|
|
|
28
|
|
|
public function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->fileManagerMock = $this->getMockBuilder('DmFileman\Service\FileManager\FileManager') |
|
31
|
|
|
->setMethods(['setCurrentPath', 'getOrigDir', 'getList']) |
|
32
|
|
|
->disableOriginalConstructor() |
|
33
|
|
|
->getMock(); |
|
34
|
|
|
|
|
35
|
|
|
$this->createDirFormMock = $this->getMockBuilder('DmFileman\Form\CreateDirectoryForm') |
|
36
|
|
|
->setMethods(['build', 'getInputFilter']) |
|
37
|
|
|
->getMock(); |
|
38
|
|
|
|
|
39
|
|
|
$this->uploadFileFormMock = $this->getMockBuilder('DmFileman\Form\UploadFileForm') |
|
40
|
|
|
->setMethods(['build', 'getMessages', 'getInputFilter']) |
|
41
|
|
|
->getMock(); |
|
42
|
|
|
|
|
43
|
|
|
$this->deleteFileFormMock = $this->getMockBuilder('DmFileman\Form\DeleteFileForm') |
|
44
|
|
|
->setMethods(['build', 'getInputFilter']) |
|
45
|
|
|
->getMock(); |
|
46
|
|
|
|
|
47
|
|
|
$this->sut = new ListController( |
|
48
|
|
|
$this->fileManagerMock, |
|
49
|
|
|
$this->createDirFormMock, |
|
50
|
|
|
$this->uploadFileFormMock, |
|
51
|
|
|
$this->deleteFileFormMock |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$this->mockFactory = new PluginMockFactory($this); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @covers DmFileman\Controller\ListController |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testIndexActionRedirectsToListPage() |
|
61
|
|
|
{ |
|
62
|
|
|
$responseMock = $this->mockFactory->getResponseMock(); |
|
63
|
|
|
|
|
64
|
|
|
$redirectMock = $this->mockFactory->getRedirectPluginMock($responseMock); |
|
65
|
|
|
$pluginMock = $this->mockFactory->getPluginMock($redirectMock); |
|
66
|
|
|
|
|
67
|
|
|
$this->sut->setPluginManager($pluginMock); |
|
68
|
|
|
|
|
69
|
|
|
$actualResult = $this->sut->indexAction(); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertEquals($responseMock, $actualResult); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @covers DmFileman\Controller\ListController |
|
76
|
|
|
*/ |
|
77
|
|
|
public function testListActionReturnsViewModel() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->fileManagerMock->expects($this->once())->method('getList'); |
|
80
|
|
|
|
|
81
|
|
|
$this->sut->setCurrentPath(''); |
|
82
|
|
|
|
|
83
|
|
|
$actualResult = $this->sut->listAction(); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertInstanceOf('Zend\View\Model\ViewModel', $actualResult); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @covers DmFileman\Controller\ListController |
|
90
|
|
|
*/ |
|
91
|
|
|
public function testRefreshActionRedirectsToListPage() |
|
92
|
|
|
{ |
|
93
|
|
|
$responseMock = $this->mockFactory->getResponseMock(); |
|
94
|
|
|
|
|
95
|
|
|
$redirectMock = $this->mockFactory->getRedirectPluginMock($responseMock); |
|
96
|
|
|
$pluginMock = $this->mockFactory->getPluginMock($redirectMock); |
|
97
|
|
|
|
|
98
|
|
|
$this->sut->setPluginManager($pluginMock); |
|
99
|
|
|
|
|
100
|
|
|
$actualResult = $this->sut->refreshAction(); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertEquals($responseMock, $actualResult); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|