@@ -67,10 +67,99 @@ public function testExecuteParamFile()
67
67
);
68
68
$ resultRawFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ resultRawMock );
69
69
70
+ $ fileResponse = $ this ->getMock ('Magento\Framework\App\ResponseInterface ' , [], [], '' , false );
71
+ $ fileFactoryMock = $ this ->getMock ('Magento\Framework\App\Response\Http\FileFactory ' , [], [], '' , false );
72
+ $ fileFactoryMock ->expects ($ this ->once ())->method ('create ' )->with (
73
+ $ path ,
74
+ ['type ' => 'filename ' , 'value ' => $ fileName ],
75
+ \Magento \Framework \App \Filesystem \DirectoryList::MEDIA
76
+ )->willReturn ($ fileResponse );
77
+
78
+ /** @var \Magento\Customer\Controller\Adminhtml\Index\Viewfile $controller */
79
+ $ controller = (new \Magento \TestFramework \Helper \ObjectManager ($ this ))->getObject (
80
+ 'Magento\Customer\Controller\Adminhtml\Index\Viewfile ' ,
81
+ [
82
+ 'context ' => $ contextMock ,
83
+ 'urlDecoder ' => $ urlDecoderMock ,
84
+ 'resultRawFactory ' => $ resultRawFactoryMock ,
85
+ 'fileFactory ' => $ fileFactoryMock
86
+ ]
87
+ );
88
+ $ this ->assertSame ($ resultRawMock , $ controller ->execute ());
89
+ $ this ->assertSame ($ fileResponse , $ controller ->getResponse ());
90
+ }
91
+
92
+ public function testExecuteGetParamImage ()
93
+ {
94
+ $ decodedFile = 'decoded_file ' ;
95
+ $ file = 'file ' ;
96
+ $ fileName = 'customer/ ' . $ file ;
97
+ $ path = 'path ' ;
98
+ $ stat = ['size ' => 10 , 'mtime ' => 10 ];
99
+
100
+ $ requestMock = $ this ->getMock ('Magento\Framework\App\RequestInterface ' , [], [], '' , false );
101
+ $ requestMock ->expects ($ this ->at (0 ))->method ('getParam ' )->with ('file ' )->willReturn (null );
102
+ $ requestMock ->expects ($ this ->at (1 ))->method ('getParam ' )->with ('image ' )->willReturn ($ decodedFile );
103
+ $ requestMock ->expects ($ this ->at (2 ))->method ('getParam ' )->with ('image ' )->willReturn ($ decodedFile );
104
+
105
+ $ responseMock = $ this ->getMock ('Magento\Framework\App\ResponseInterface ' , [], [], '' , false );
106
+
107
+ $ directoryMock = $ this ->getMock ('Magento\Framework\Filesystem\Directory\ReadInterface ' , [], [], '' , false );
108
+ $ directoryMock ->expects ($ this ->once ())->method ('getAbsolutePath ' )->with ($ fileName )->willReturn ($ path );
109
+ $ directoryMock ->expects ($ this ->once ())->method ('stat ' )->with ($ path )->willReturn ($ stat );
110
+
111
+ $ fileSystemMock = $ this ->getMock ('Magento\Framework\Filesystem ' , [], [], '' , false );
112
+ $ fileSystemMock ->expects ($ this ->once ())->method ('getDirectoryRead ' )
113
+ ->with (\Magento \Framework \App \Filesystem \DirectoryList::MEDIA )
114
+ ->willReturn ($ directoryMock );
115
+
116
+ $ storage = $ this ->getMock ('Magento\Core\Helper\File\Storage ' , [], [], '' , false );
117
+ $ storage ->expects ($ this ->once ())->method ('processStorageFile ' )->with ($ path )->willReturn (true );
118
+
119
+ $ objectManager = $ this ->getMock ('Magento\Framework\ObjectManagerInterface ' , [], [], '' , false );
120
+ $ objectManager ->expects ($ this ->at (0 ))->method ('get ' )->with ('Magento\Framework\Filesystem ' )
121
+ ->willReturn ($ fileSystemMock );
122
+ $ objectManager ->expects ($ this ->at (1 ))->method ('get ' )->with ('Magento\Core\Helper\File\Storage ' )
123
+ ->willReturn ($ storage );
124
+
125
+ $ contextMock = $ this ->getMock ('Magento\Backend\App\Action\Context ' , [], [], '' , false );
126
+ $ contextMock ->expects ($ this ->once ())->method ('getRequest ' )->willReturn ($ requestMock );
127
+ $ contextMock ->expects ($ this ->once ())->method ('getResponse ' )->willReturn ($ responseMock );
128
+ $ contextMock ->expects ($ this ->once ())->method ('getObjectManager ' )->willReturn ($ objectManager );
129
+
130
+ $ urlDecoderMock = $ this ->getMock ('Magento\Framework\Url\DecoderInterface ' , [], [], '' , false );
131
+ $ urlDecoderMock ->expects ($ this ->once ())->method ('decode ' )->with ($ decodedFile )->willReturn ($ file );
132
+
133
+ $ resultRawMock = $ this ->getMock ('Magento\Framework\Controller\Result\Raw ' , [], [], '' , false );
134
+ $ resultRawMock ->expects ($ this ->once ())->method ('setHttpResponseCode ' )->with (200 )->willReturnSelf ();
135
+ $ resultRawMock ->expects ($ this ->at (1 ))->method ('setHeader ' )->with ('Pragma ' , 'public ' , true )->willReturnSelf ();
136
+ $ resultRawMock ->expects ($ this ->at (2 ))->method ('setHeader ' )
137
+ ->with ('Content-type ' , 'application/octet-stream ' , true )
138
+ ->willReturnSelf ();
139
+ $ resultRawMock ->expects ($ this ->at (3 ))->method ('setHeader ' )
140
+ ->with ('Content-Length ' , $ stat ['size ' ])
141
+ ->willReturnSelf ();
142
+ $ resultRawMock ->expects ($ this ->at (4 ))->method ('setHeader ' )
143
+ ->with ('Last-Modified ' , date ('r ' , $ stat ['mtime ' ]))
144
+ ->willReturnSelf ();
145
+
146
+ $ resultRawFactoryMock = $ this ->getMock (
147
+ 'Magento\Framework\Controller\Result\RawFactory ' ,
148
+ ['create ' ],
149
+ [],
150
+ '' ,
151
+ false
152
+ );
153
+ $ resultRawFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ resultRawMock );
154
+
70
155
/** @var \Magento\Customer\Controller\Adminhtml\Index\Viewfile $controller */
71
156
$ controller = (new \Magento \TestFramework \Helper \ObjectManager ($ this ))->getObject (
72
157
'Magento\Customer\Controller\Adminhtml\Index\Viewfile ' ,
73
- ['context ' => $ contextMock , 'urlDecoder ' => $ urlDecoderMock , 'resultRawFactory ' => $ resultRawFactoryMock ]
158
+ [
159
+ 'context ' => $ contextMock ,
160
+ 'urlDecoder ' => $ urlDecoderMock ,
161
+ 'resultRawFactory ' => $ resultRawFactoryMock
162
+ ]
74
163
);
75
164
$ this ->assertSame ($ resultRawMock , $ controller ->execute ());
76
165
}
0 commit comments