9
9
use Magento \Framework \App \Filesystem \DirectoryList ;
10
10
use Magento \Framework \Exception \SerializationException ;
11
11
use Magento \Framework \Filesystem ;
12
- use Magento \Framework \Filesystem \Directory \ReadInterface ;
12
+ use Magento \Framework \Filesystem \Directory \WriteInterface ;
13
13
use Magento \Framework \Filesystem \DriverPool ;
14
14
15
15
/**
@@ -25,9 +25,9 @@ class FileTest extends \PHPUnit_Framework_TestCase
25
25
protected $ objectManager ;
26
26
27
27
/**
28
- * @var ReadInterface |\PHPUnit_Framework_MockObject_MockObject
28
+ * @var WriteInterface |\PHPUnit_Framework_MockObject_MockObject
29
29
*/
30
- protected $ rootDirectory ;
30
+ protected $ mediaDirectory ;
31
31
32
32
/**
33
33
* @var \Magento\MediaStorage\Helper\File\Storage\Database|\PHPUnit_Framework_MockObject_MockObject
@@ -67,13 +67,13 @@ protected function setUp()
67
67
->disableOriginalConstructor ()
68
68
->getMock ();
69
69
70
- $ this ->rootDirectory = $ this ->getMockBuilder (ReadInterface ::class)
70
+ $ this ->mediaDirectory = $ this ->getMockBuilder (WriteInterface ::class)
71
71
->getMock ();
72
72
73
73
$ this ->filesystemMock ->expects ($ this ->any ())
74
- ->method ('getDirectoryRead ' )
74
+ ->method ('getDirectoryWrite ' )
75
75
->with (DirectoryList::MEDIA , DriverPool::FILE )
76
- ->willReturn ($ this ->rootDirectory );
76
+ ->willReturn ($ this ->mediaDirectory );
77
77
78
78
$ this ->serializer = $ this ->getMockBuilder (\Magento \Framework \Serialize \Serializer \Json::class)
79
79
->disableOriginalConstructor ()
@@ -95,7 +95,7 @@ protected function setUp()
95
95
96
96
$ this ->coreFileStorageDatabase = $ this ->getMock (
97
97
\Magento \MediaStorage \Helper \File \Storage \Database::class,
98
- ['copyFile ' ],
98
+ ['copyFile ' , ' checkDbUsage ' ],
99
99
[],
100
100
'' ,
101
101
false
@@ -166,7 +166,7 @@ public function testGetCustomizedView()
166
166
);
167
167
}
168
168
169
- public function testCopyQuoteToOrder ()
169
+ public function testCopyQuoteToOrderWithDbUsage ()
170
170
{
171
171
$ optionMock = $ this ->getMockBuilder (OptionInterface::class)
172
172
->disableOriginalConstructor ()
@@ -187,25 +187,29 @@ function ($value) {
187
187
}
188
188
);
189
189
190
- $ optionMock ->expects ($ this ->any ())
190
+ $ optionMock ->expects ($ this ->once ())
191
191
->method ('getValue ' )
192
192
->will ($ this ->returnValue ($ quoteValue ));
193
193
194
- $ this ->rootDirectory ->expects ($ this ->any ())
194
+ $ this ->mediaDirectory ->expects ($ this ->once ())
195
195
->method ('isFile ' )
196
196
->with ($ this ->equalTo ($ quotePath ))
197
197
->will ($ this ->returnValue (true ));
198
198
199
- $ this ->rootDirectory ->expects ($ this ->any ())
199
+ $ this ->mediaDirectory ->expects ($ this ->once ())
200
200
->method ('isReadable ' )
201
201
->with ($ this ->equalTo ($ quotePath ))
202
202
->will ($ this ->returnValue (true ));
203
203
204
- $ this ->rootDirectory ->expects ($ this ->any ( ))
204
+ $ this ->mediaDirectory ->expects ($ this ->exactly ( 2 ))
205
205
->method ('getAbsolutePath ' )
206
206
->will ($ this ->returnValue ('/file.path ' ));
207
207
208
- $ this ->coreFileStorageDatabase ->expects ($ this ->any ())
208
+ $ this ->coreFileStorageDatabase ->expects ($ this ->once ())
209
+ ->method ('checkDbUsage ' )
210
+ ->willReturn (true );
211
+
212
+ $ this ->coreFileStorageDatabase ->expects ($ this ->once ())
209
213
->method ('copyFile ' )
210
214
->will ($ this ->returnValue ('true ' ));
211
215
@@ -218,6 +222,62 @@ function ($value) {
218
222
);
219
223
}
220
224
225
+ public function testCopyQuoteToOrderWithoutUsage ()
226
+ {
227
+ $ optionMock = $ this ->getMockBuilder (OptionInterface::class)
228
+ ->disableOriginalConstructor ()
229
+ ->setMethods (['getValue ' ])
230
+ ->getMockForAbstractClass ();
231
+
232
+ $ quotePath = '/quote/path/path/uploaded.file ' ;
233
+ $ orderPath = '/order/path/path/uploaded.file ' ;
234
+
235
+ $ quoteValue = "{ \"quote_path \": \"$ quotePath \", \"order_path \": \"$ orderPath \"} " ;
236
+
237
+ $ this ->serializer ->expects ($ this ->once ())
238
+ ->method ('unserialize ' )
239
+ ->with ($ quoteValue )
240
+ ->willReturnCallback (
241
+ function ($ value ) {
242
+ return json_decode ($ value , true );
243
+ }
244
+ );
245
+
246
+ $ optionMock ->expects ($ this ->once ())
247
+ ->method ('getValue ' )
248
+ ->will ($ this ->returnValue ($ quoteValue ));
249
+
250
+ $ this ->mediaDirectory ->expects ($ this ->once ())
251
+ ->method ('isFile ' )
252
+ ->with ($ this ->equalTo ($ quotePath ))
253
+ ->will ($ this ->returnValue (true ));
254
+
255
+ $ this ->mediaDirectory ->expects ($ this ->once ())
256
+ ->method ('isReadable ' )
257
+ ->with ($ this ->equalTo ($ quotePath ))
258
+ ->will ($ this ->returnValue (true ));
259
+
260
+ $ this ->mediaDirectory ->expects ($ this ->never ())
261
+ ->method ('getAbsolutePath ' )
262
+ ->will ($ this ->returnValue ('/file.path ' ));
263
+
264
+ $ this ->coreFileStorageDatabase ->expects ($ this ->once ())
265
+ ->method ('checkDbUsage ' )
266
+ ->willReturn (false );
267
+
268
+ $ this ->coreFileStorageDatabase ->expects ($ this ->any ())
269
+ ->method ('copyFile ' )
270
+ ->willReturn (false );
271
+
272
+ $ fileObject = $ this ->getFileObject ();
273
+ $ fileObject ->setData ('configuration_item_option ' , $ optionMock );
274
+
275
+ $ this ->assertInstanceOf (
276
+ \Magento \Catalog \Model \Product \Option \Type \File::class,
277
+ $ fileObject ->copyQuoteToOrder ()
278
+ );
279
+ }
280
+
221
281
public function testGetFormattedOptionValue ()
222
282
{
223
283
$ resultValue = ['result ' ];
0 commit comments