15
15
use Magento \Framework \Filesystem ;
16
16
use Magento \Framework \Filesystem \Directory \Read ;
17
17
use Magento \Framework \Filesystem \Directory \WriteInterface ;
18
+ use Magento \Framework \Filesystem \DriverPool ;
18
19
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
19
20
use Magento \MediaStorage \App \Media ;
20
21
use Magento \MediaStorage \Model \File \Storage \Config ;
@@ -74,7 +75,12 @@ class MediaTest extends TestCase
74
75
/**
75
76
* @var Read|MockObject
76
77
*/
77
- private $ directoryMock ;
78
+ private $ directoryMediaMock ;
79
+
80
+ /**
81
+ * @var \Magento\Framework\Filesystem\Directory\Read|\PHPUnit_Framework_MockObject_MockObject
82
+ */
83
+ private $ directoryPubMock ;
78
84
79
85
protected function setUp ()
80
86
{
@@ -96,12 +102,30 @@ protected function setUp()
96
102
->will ($ this ->returnValue ($ this ->sync ));
97
103
98
104
$ this ->filesystemMock = $ this ->createMock (Filesystem::class);
99
- $ this ->directoryMock = $ this ->getMockForAbstractClass (WriteInterface::class);
100
-
105
+ $ this ->directoryPubMock = $ this ->getMockForAbstractClass (
106
+ WriteInterface::class,
107
+ [],
108
+ '' ,
109
+ false ,
110
+ true ,
111
+ true ,
112
+ ['isReadable ' , 'getAbsolutePath ' ]
113
+ );
114
+ $ this ->directoryMediaMock = $ this ->getMockForAbstractClass (
115
+ WriteInterface::class,
116
+ [],
117
+ '' ,
118
+ false ,
119
+ true ,
120
+ true ,
121
+ ['getAbsolutePath ' ]
122
+ );
101
123
$ this ->filesystemMock ->expects ($ this ->any ())
102
124
->method ('getDirectoryWrite ' )
103
- ->with (DirectoryList::PUB )
104
- ->will ($ this ->returnValue ($ this ->directoryMock ));
125
+ ->willReturnMap ([
126
+ [DirectoryList::PUB , DriverPool::FILE , $ this ->directoryPubMock ],
127
+ [DirectoryList::MEDIA , DriverPool::FILE , $ this ->directoryMediaMock ],
128
+ ]);
105
129
106
130
$ this ->responseMock = $ this ->createMock (Response::class);
107
131
}
@@ -116,17 +140,17 @@ public function testProcessRequestCreatesConfigFileMediaDirectoryIsNotProvided()
116
140
$ this ->mediaModel = $ this ->getMediaModel ();
117
141
118
142
$ filePath = '/absolute/path/to/test/file.png ' ;
119
- $ this ->directoryMock ->expects ($ this ->any ())
143
+ $ this ->directoryMediaMock ->expects ($ this ->once ())
144
+ ->method ('getAbsolutePath ' )
145
+ ->with (null )
146
+ ->will ($ this ->returnValue (self ::MEDIA_DIRECTORY ));
147
+ $ this ->directoryPubMock ->expects ($ this ->once ())
120
148
->method ('getAbsolutePath ' )
121
- ->will ($ this ->returnValueMap (
122
- [
123
- [null , self ::MEDIA_DIRECTORY ],
124
- [self ::RELATIVE_FILE_PATH , $ filePath ],
125
- ]
126
- ));
149
+ ->with (self ::RELATIVE_FILE_PATH )
150
+ ->will ($ this ->returnValue ($ filePath ));
127
151
$ this ->configMock ->expects ($ this ->once ())->method ('save ' );
128
152
$ this ->sync ->expects ($ this ->once ())->method ('synchronize ' )->with (self ::RELATIVE_FILE_PATH );
129
- $ this ->directoryMock ->expects ($ this ->once ())
153
+ $ this ->directoryPubMock ->expects ($ this ->once ())
130
154
->method ('isReadable ' )
131
155
->with (self ::RELATIVE_FILE_PATH )
132
156
->will ($ this ->returnValue (true ));
@@ -140,18 +164,18 @@ public function testProcessRequestReturnsFileIfItsProperlySynchronized()
140
164
141
165
$ filePath = '/absolute/path/to/test/file.png ' ;
142
166
$ this ->sync ->expects ($ this ->once ())->method ('synchronize ' )->with (self ::RELATIVE_FILE_PATH );
143
- $ this ->directoryMock ->expects ($ this ->once ())
167
+ $ this ->directoryMediaMock ->expects ($ this ->once ())
168
+ ->method ('getAbsolutePath ' )
169
+ ->with (null )
170
+ ->will ($ this ->returnValue (self ::MEDIA_DIRECTORY ));
171
+ $ this ->directoryPubMock ->expects ($ this ->once ())
144
172
->method ('isReadable ' )
145
173
->with (self ::RELATIVE_FILE_PATH )
146
174
->will ($ this ->returnValue (true ));
147
- $ this ->directoryMock ->expects ($ this ->any ())
175
+ $ this ->directoryPubMock ->expects ($ this ->once ())
148
176
->method ('getAbsolutePath ' )
149
- ->will ($ this ->returnValueMap (
150
- [
151
- [null , self ::MEDIA_DIRECTORY ],
152
- [self ::RELATIVE_FILE_PATH , $ filePath ],
153
- ]
154
- ));
177
+ ->with (self ::RELATIVE_FILE_PATH )
178
+ ->will ($ this ->returnValue ($ filePath ));
155
179
$ this ->responseMock ->expects ($ this ->once ())->method ('setFilePath ' )->with ($ filePath );
156
180
$ this ->assertSame ($ this ->responseMock , $ this ->mediaModel ->launch ());
157
181
}
@@ -161,11 +185,11 @@ public function testProcessRequestReturnsNotFoundIfFileIsNotSynchronized()
161
185
$ this ->mediaModel = $ this ->getMediaModel ();
162
186
163
187
$ this ->sync ->expects ($ this ->once ())->method ('synchronize ' )->with (self ::RELATIVE_FILE_PATH );
164
- $ this ->directoryMock ->expects ($ this ->once ())
188
+ $ this ->directoryMediaMock ->expects ($ this ->once ())
165
189
->method ('getAbsolutePath ' )
166
- ->with ()
190
+ ->with (null )
167
191
->will ($ this ->returnValue (self ::MEDIA_DIRECTORY ));
168
- $ this ->directoryMock ->expects ($ this ->once ())
192
+ $ this ->directoryPubMock ->expects ($ this ->once ())
169
193
->method ('isReadable ' )
170
194
->with (self ::RELATIVE_FILE_PATH )
171
195
->will ($ this ->returnValue (false ));
@@ -205,16 +229,10 @@ public function testCatchException($isDeveloper, $setBodyCalls)
205
229
public function testExceptionWhenIsAllowedReturnsFalse ()
206
230
{
207
231
$ this ->mediaModel = $ this ->getMediaModel (false );
208
-
209
- $ filePath = '/absolute/path/to/test/file.png ' ;
210
- $ this ->directoryMock ->expects ($ this ->any ())
232
+ $ this ->directoryMediaMock ->expects ($ this ->once ())
211
233
->method ('getAbsolutePath ' )
212
- ->will ($ this ->returnValueMap (
213
- [
214
- [null , self ::MEDIA_DIRECTORY ],
215
- [self ::RELATIVE_FILE_PATH , $ filePath ],
216
- ]
217
- ));
234
+ ->with (null )
235
+ ->will ($ this ->returnValue (self ::MEDIA_DIRECTORY ));
218
236
$ this ->configMock ->expects ($ this ->once ())->method ('save ' );
219
237
220
238
$ this ->expectException (LogicException::class);
0 commit comments