@@ -273,7 +273,13 @@ public function testGetLinkForWrongCustomer()
273
273
$ this ->assertEquals ($ this ->response , $ this ->link ->execute ());
274
274
}
275
275
276
- public function testExceptionInUpdateLinkStatus ()
276
+ /**
277
+ * @param string $mimeType
278
+ * @param string $disposition
279
+ * @dataProvider downloadTypesDataProvider
280
+ * @return void
281
+ */
282
+ public function testExceptionInUpdateLinkStatus ($ mimeType , $ disposition )
277
283
{
278
284
$ this ->objectManager ->expects ($ this ->at (0 ))
279
285
->method ('get ' )
@@ -303,7 +309,7 @@ public function testExceptionInUpdateLinkStatus()
303
309
$ this ->linkPurchasedItem ->expects ($ this ->once ())->method ('getLinkType ' )->willReturn ('url ' );
304
310
$ this ->linkPurchasedItem ->expects ($ this ->once ())->method ('getLinkUrl ' )->willReturn ('link_url ' );
305
311
306
- $ this ->processDownload ('link_url ' , 'url ' );
312
+ $ this ->processDownload ('link_url ' , 'url ' , $ mimeType , $ disposition );
307
313
308
314
$ this ->linkPurchasedItem ->expects ($ this ->any ())->method ('setNumberOfDownloadsUsed ' )->willReturnSelf ();
309
315
$ this ->linkPurchasedItem ->expects ($ this ->any ())->method ('setStatus ' )->with ('expired ' )->willReturnSelf ();
@@ -317,8 +323,18 @@ public function testExceptionInUpdateLinkStatus()
317
323
$ this ->assertEquals ($ this ->response , $ this ->link ->execute ());
318
324
}
319
325
320
- private function processDownload ($ resource , $ resourceType )
326
+ /**
327
+ * @param string $resource
328
+ * @param string $resourceType
329
+ * @param string $mimeType
330
+ * @param string $disposition
331
+ * @return void
332
+ */
333
+ private function processDownload ($ resource , $ resourceType , $ mimeType , $ disposition )
321
334
{
335
+ $ fileSize = 58493 ;
336
+ $ fileName = 'link.jpg ' ;
337
+
322
338
$ this ->objectManager ->expects ($ this ->at (3 ))
323
339
->method ('get ' )
324
340
->with (\Magento \Downloadable \Helper \Download::class)
@@ -327,30 +343,23 @@ private function processDownload($resource, $resourceType)
327
343
->method ('setResource ' )
328
344
->with ($ resource , $ resourceType )
329
345
->willReturnSelf ();
330
- $ this ->downloadHelper ->expects ($ this ->once ())->method ('getFilename ' )->willReturn (' file_name ' );
331
- $ this ->downloadHelper ->expects ($ this ->once ())->method ('getContentType ' )->willReturn (' content_type ' );
346
+ $ this ->downloadHelper ->expects ($ this ->once ())->method ('getFilename ' )->willReturn ($ fileName );
347
+ $ this ->downloadHelper ->expects ($ this ->once ())->method ('getContentType ' )->willReturn ($ mimeType );
332
348
$ this ->response ->expects ($ this ->once ())->method ('setHttpResponseCode ' )->with (200 )->willReturnSelf ();
333
- $ this ->response -> expects ( $ this -> at ( 1 ))-> method ( ' setHeader ' )-> with ( ' Pragma ' , ' public ' , true )-> willReturnSelf ();
334
- $ this -> response -> expects ($ this ->at ( 2 ))
349
+ $ this ->response
350
+ -> expects ($ this ->any ( ))
335
351
->method ('setHeader ' )
336
- ->with ('Cache-Control ' , 'must-revalidate, post-check=0, pre-check=0 ' , true )
337
- ->willReturnSelf ();
338
- $ this ->response ->expects ($ this ->at (3 ))
339
- ->method ('setHeader ' )
340
- ->with ('Content-type ' , 'content_type ' , true )
341
- ->willReturnSelf ();
342
- $ this ->downloadHelper ->expects ($ this ->once ())->method ('getFileSize ' )->willReturn ('file_size ' );
343
- $ this ->response ->expects ($ this ->at (4 ))
344
- ->method ('setHeader ' )
345
- ->with ('Content-Length ' , 'file_size ' )
346
- ->willReturnSelf ();
347
- $ this ->downloadHelper ->expects ($ this ->once ())
348
- ->method ('getContentDisposition ' )
349
- ->willReturn ('content_disposition ' );
350
- $ this ->response ->expects ($ this ->at (5 ))
351
- ->method ('setHeader ' )
352
- ->with ('Content-Disposition ' , 'content_disposition; filename=file_name ' )
352
+ ->withConsecutive (
353
+ ['Pragma ' , 'public ' , true ],
354
+ ['Cache-Control ' , 'must-revalidate, post-check=0, pre-check=0 ' , true ],
355
+ ['Content-type ' , $ mimeType , true ],
356
+ ['Content-Length ' , $ fileSize ],
357
+ ['Content-Disposition ' , $ disposition . '; filename= ' . $ fileName ]
358
+ )
353
359
->willReturnSelf ();
360
+
361
+ $ this ->downloadHelper ->expects ($ this ->once ())->method ('getContentDisposition ' )->willReturn ($ disposition );
362
+ $ this ->downloadHelper ->expects ($ this ->once ())->method ('getFileSize ' )->willReturn ($ fileSize );
354
363
$ this ->response ->expects ($ this ->once ())->method ('clearBody ' )->willReturnSelf ();
355
364
$ this ->response ->expects ($ this ->once ())->method ('sendHeaders ' )->willReturnSelf ();
356
365
$ this ->downloadHelper ->expects ($ this ->once ())->method ('output ' );
@@ -406,4 +415,15 @@ public function linkNotAvailableDataProvider()
406
415
['addError ' , 'wrong_status ' , 'Something went wrong while getting the requested content. ' ]
407
416
];
408
417
}
418
+
419
+ /**
420
+ * @return array
421
+ */
422
+ public function downloadTypesDataProvider ()
423
+ {
424
+ return [
425
+ ['mimeType ' => 'text/html ' , 'disposition ' => \Zend_Mime::DISPOSITION_ATTACHMENT ],
426
+ ['mimeType ' => 'image/jpeg ' , 'disposition ' => \Zend_Mime::DISPOSITION_INLINE ],
427
+ ];
428
+ }
409
429
}
0 commit comments