@@ -83,7 +83,7 @@ protected function setUp()
83
83
84
84
$ this ->coreFileStorageDatabase = $ this ->getMock (
85
85
\Magento \MediaStorage \Helper \File \Storage \Database::class,
86
- ['copyFile ' ],
86
+ ['copyFile ' , ' checkDbUsage ' ],
87
87
[],
88
88
'' ,
89
89
false
@@ -133,7 +133,7 @@ public function testGetCustomizedView()
133
133
);
134
134
}
135
135
136
- public function testCopyQuoteToOrder ()
136
+ public function testCopyQuoteToOrderWithDbUsage ()
137
137
{
138
138
$ optionMock = $ this ->getMockBuilder (OptionInterface::class)
139
139
->disableOriginalConstructor ()
@@ -154,25 +154,29 @@ function ($value) {
154
154
}
155
155
);
156
156
157
- $ optionMock ->expects ($ this ->any ())
157
+ $ optionMock ->expects ($ this ->once ())
158
158
->method ('getValue ' )
159
159
->will ($ this ->returnValue ($ quoteValue ));
160
160
161
- $ this ->mediaDirectory ->expects ($ this ->any ())
161
+ $ this ->mediaDirectory ->expects ($ this ->once ())
162
162
->method ('isFile ' )
163
163
->with ($ this ->equalTo ($ quotePath ))
164
164
->will ($ this ->returnValue (true ));
165
165
166
- $ this ->mediaDirectory ->expects ($ this ->any ())
166
+ $ this ->mediaDirectory ->expects ($ this ->once ())
167
167
->method ('isReadable ' )
168
168
->with ($ this ->equalTo ($ quotePath ))
169
169
->will ($ this ->returnValue (true ));
170
170
171
- $ this ->mediaDirectory ->expects ($ this ->any ( ))
171
+ $ this ->mediaDirectory ->expects ($ this ->exactly ( 2 ))
172
172
->method ('getAbsolutePath ' )
173
173
->will ($ this ->returnValue ('/file.path ' ));
174
174
175
- $ this ->coreFileStorageDatabase ->expects ($ this ->any ())
175
+ $ this ->coreFileStorageDatabase ->expects ($ this ->once ())
176
+ ->method ('checkDbUsage ' )
177
+ ->willReturn (true );
178
+
179
+ $ this ->coreFileStorageDatabase ->expects ($ this ->once ())
176
180
->method ('copyFile ' )
177
181
->will ($ this ->returnValue ('true ' ));
178
182
@@ -185,6 +189,62 @@ function ($value) {
185
189
);
186
190
}
187
191
192
+ public function testCopyQuoteToOrderWithoutUsage ()
193
+ {
194
+ $ optionMock = $ this ->getMockBuilder (OptionInterface::class)
195
+ ->disableOriginalConstructor ()
196
+ ->setMethods (['getValue ' ])
197
+ ->getMockForAbstractClass ();
198
+
199
+ $ quotePath = '/quote/path/path/uploaded.file ' ;
200
+ $ orderPath = '/order/path/path/uploaded.file ' ;
201
+
202
+ $ quoteValue = "{ \"quote_path \": \"$ quotePath \", \"order_path \": \"$ orderPath \"} " ;
203
+
204
+ $ this ->serializer ->expects ($ this ->once ())
205
+ ->method ('unserialize ' )
206
+ ->with ($ quoteValue )
207
+ ->willReturnCallback (
208
+ function ($ value ) {
209
+ return json_decode ($ value , true );
210
+ }
211
+ );
212
+
213
+ $ optionMock ->expects ($ this ->once ())
214
+ ->method ('getValue ' )
215
+ ->will ($ this ->returnValue ($ quoteValue ));
216
+
217
+ $ this ->mediaDirectory ->expects ($ this ->once ())
218
+ ->method ('isFile ' )
219
+ ->with ($ this ->equalTo ($ quotePath ))
220
+ ->will ($ this ->returnValue (true ));
221
+
222
+ $ this ->mediaDirectory ->expects ($ this ->once ())
223
+ ->method ('isReadable ' )
224
+ ->with ($ this ->equalTo ($ quotePath ))
225
+ ->will ($ this ->returnValue (true ));
226
+
227
+ $ this ->mediaDirectory ->expects ($ this ->never ())
228
+ ->method ('getAbsolutePath ' )
229
+ ->will ($ this ->returnValue ('/file.path ' ));
230
+
231
+ $ this ->coreFileStorageDatabase ->expects ($ this ->once ())
232
+ ->method ('checkDbUsage ' )
233
+ ->willReturn (false );
234
+
235
+ $ this ->coreFileStorageDatabase ->expects ($ this ->any ())
236
+ ->method ('copyFile ' )
237
+ ->willReturn (false );
238
+
239
+ $ fileObject = $ this ->getFileObject ();
240
+ $ fileObject ->setData ('configuration_item_option ' , $ optionMock );
241
+
242
+ $ this ->assertInstanceOf (
243
+ \Magento \Catalog \Model \Product \Option \Type \File::class,
244
+ $ fileObject ->copyQuoteToOrder ()
245
+ );
246
+ }
247
+
188
248
public function testGetFormattedOptionValue ()
189
249
{
190
250
$ resultValue = ['result ' ];
0 commit comments