@@ -39,6 +39,11 @@ class DownloadTest extends \PHPUnit_Framework_TestCase
39
39
*/
40
40
protected $ writeDirectoryMock ;
41
41
42
+ /**
43
+ * @var \PHPUnit_Framework_MockObject_MockObject
44
+ */
45
+ protected $ driverMock ;
46
+
42
47
protected function setUp ()
43
48
{
44
49
$ this ->writeDirectoryMock = $ this ->getMockBuilder ('Magento\Framework\Filesystem\Directory\Write ' )
@@ -49,9 +54,10 @@ protected function setUp()
49
54
->getMock ();
50
55
$ this ->filesystemMock ->expects ($ this ->any ())
51
56
->method ('getDirectoryWrite ' )
52
- ->with (DirectoryList::ROOT )
57
+ ->with (DirectoryList::MEDIA )
53
58
->will ($ this ->returnValue ($ this ->writeDirectoryMock ));
54
59
60
+ $ this ->driverMock = $ this ->getMockForAbstractClass ('Magento\Framework\Filesystem\DriverInterface ' );
55
61
$ this ->storageMock = $ this ->getMockBuilder ('Magento\MediaStorage\Helper\File\Storage\Database ' )
56
62
->disableOriginalConstructor ()
57
63
->getMock ();
@@ -83,17 +89,23 @@ public function testInstanceOf()
83
89
}
84
90
85
91
/**
86
- * @expectedException \Exception
92
+ * @param $realPatchCheck
93
+ * @param $isFile
94
+ * @param $isReadable
95
+ * @expectedException \Magento\Framework\Exception\LocalizedException
96
+ * @dataProvider dataProviderForTestDownloadFileException
87
97
*/
88
- public function testDownloadFileException ()
98
+ public function testDownloadFileException ($ realPatchCheck , $ isFile , $ isReadable )
89
99
{
90
100
$ info = ['order_path ' => 'test/path ' , 'quote_path ' => 'test/path2 ' , 'title ' => 'test title ' ];
91
- $ isFile = true ;
92
- $ isReadable = false ;
93
101
94
102
$ this ->writeDirectoryMock ->expects ($ this ->any ())
95
103
->method ('getAbsolutePath ' )
96
104
->will ($ this ->returnArgument (0 ));
105
+ $ this ->writeDirectoryMock ->expects ($ this ->any ())
106
+ ->method ('getDriver ' )
107
+ ->willReturn ($ this ->driverMock );
108
+ $ this ->driverMock ->expects ($ this ->any ())->method ('getRealPath ' )->willReturn ($ realPatchCheck );
97
109
$ this ->writeDirectoryMock ->expects ($ this ->any ())
98
110
->method ('isFile ' )
99
111
->will ($ this ->returnValue ($ isFile ));
@@ -104,12 +116,25 @@ public function testDownloadFileException()
104
116
$ this ->storageFactoryMock ->expects ($ this ->any ())
105
117
->method ('checkDbUsage ' )
106
118
->will ($ this ->returnValue (false ));
119
+ $ this ->httpFileFactoryMock ->expects ($ this ->never ())->method ('create ' );
107
120
108
121
$ this ->model ->downloadFile ($ info );
109
122
}
110
123
111
124
/**
112
- * @expectedException \Exception
125
+ * @return array
126
+ */
127
+ public function dataProviderForTestDownloadFileException ()
128
+ {
129
+ return [
130
+ [1 , true , false ],
131
+ [1 , false , true ],
132
+ [false , true , true ],
133
+ ];
134
+ }
135
+
136
+ /**
137
+ * @expectedException \Magento\Framework\Exception\LocalizedException
113
138
*/
114
139
public function testDownloadFileNoStorage ()
115
140
{
@@ -120,6 +145,11 @@ public function testDownloadFileNoStorage()
120
145
$ this ->writeDirectoryMock ->expects ($ this ->any ())
121
146
->method ('getAbsolutePath ' )
122
147
->will ($ this ->returnArgument (0 ));
148
+ $ this ->writeDirectoryMock ->expects ($ this ->any ())
149
+ ->method ('getDriver ' )
150
+ ->willReturn ($ this ->driverMock );
151
+ $ this ->driverMock ->expects ($ this ->any ())->method ('getRealPath ' )->willReturn (true );
152
+
123
153
$ this ->writeDirectoryMock ->expects ($ this ->any ())
124
154
->method ('isFile ' )
125
155
->will ($ this ->returnValue ($ isFile ));
@@ -130,9 +160,6 @@ public function testDownloadFileNoStorage()
130
160
$ this ->storageMock ->expects ($ this ->any ())
131
161
->method ('checkDbUsage ' )
132
162
->will ($ this ->returnValue (true ));
133
- $ this ->storageMock ->expects ($ this ->any ())
134
- ->method ('getMediaRelativePath ' )
135
- ->will ($ this ->returnArgument (0 ));
136
163
137
164
$ storageDatabaseMock = $ this ->getMockBuilder ('Magento\MediaStorage\Model\File\Storage\Database ' )
138
165
->disableOriginalConstructor ()
@@ -153,6 +180,7 @@ public function testDownloadFileNoStorage()
153
180
$ this ->storageFactoryMock ->expects ($ this ->any ())
154
181
->method ('create ' )
155
182
->will ($ this ->returnValue ($ storageDatabaseMock ));
183
+ $ this ->httpFileFactoryMock ->expects ($ this ->never ())->method ('create ' );
156
184
157
185
$ this ->model ->downloadFile ($ info );
158
186
}
@@ -178,6 +206,11 @@ public function testDownloadFile()
178
206
$ this ->writeDirectoryMock ->expects ($ this ->any ())
179
207
->method ('getAbsolutePath ' )
180
208
->will ($ this ->returnArgument (0 ));
209
+ $ this ->writeDirectoryMock ->expects ($ this ->any ())
210
+ ->method ('getDriver ' )
211
+ ->willReturn ($ this ->driverMock );
212
+ $ this ->driverMock ->expects ($ this ->any ())->method ('getRealPath ' )->willReturn (true );
213
+
181
214
$ this ->writeDirectoryMock ->expects ($ this ->any ())
182
215
->method ('isFile ' )
183
216
->will ($ this ->returnValue ($ isFile ));
@@ -195,9 +228,6 @@ public function testDownloadFile()
195
228
$ this ->storageMock ->expects ($ this ->any ())
196
229
->method ('checkDbUsage ' )
197
230
->will ($ this ->returnValue (true ));
198
- $ this ->storageMock ->expects ($ this ->any ())
199
- ->method ('getMediaRelativePath ' )
200
- ->will ($ this ->returnArgument (0 ));
201
231
202
232
$ storageDatabaseMock = $ this ->getMockBuilder ('Magento\MediaStorage\Model\File\Storage\Database ' )
203
233
->disableOriginalConstructor ()
@@ -220,7 +250,7 @@ public function testDownloadFile()
220
250
->with (
221
251
$ info ['title ' ],
222
252
['value ' => $ info ['order_path ' ], 'type ' => 'filename ' ],
223
- DirectoryList::ROOT ,
253
+ DirectoryList::MEDIA ,
224
254
'application/octet-stream ' ,
225
255
null
226
256
);
0 commit comments