@@ -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 ))
335
- ->method ('setHeader ' )
336
- ->with ('Cache-Control ' , 'must-revalidate, post-check=0, pre-check=0 ' , true )
337
- ->willReturnSelf ();
338
- $ this ->response ->expects ($ this ->at (3 ))
349
+ $ this ->response
350
+ ->expects ($ this ->any ())
339
351
->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 ' );
@@ -394,6 +403,76 @@ public function testLinkNotAvailable($messageType, $status, $notice)
394
403
$ this ->assertEquals ($ this ->response , $ this ->link ->execute ());
395
404
}
396
405
406
+ /**
407
+ * @param string $mimeType
408
+ * @param string $disposition
409
+ * @dataProvider downloadTypesDataProvider
410
+ * @return void
411
+ */
412
+ public function testContentDisposition ($ mimeType , $ disposition )
413
+ {
414
+ $ this ->objectManager ->expects ($ this ->any ())
415
+ ->method ('get ' )
416
+ ->willReturnMap ([
417
+ [
418
+ \Magento \Customer \Model \Session::class,
419
+ $ this ->session ,
420
+ ],
421
+ [
422
+ \Magento \Downloadable \Helper \Data::class,
423
+ $ this ->helperData ,
424
+ ],
425
+ [
426
+ \Magento \Downloadable \Helper \Download::class,
427
+ $ this ->downloadHelper ,
428
+ ],
429
+ ]);
430
+
431
+ $ this ->request ->expects ($ this ->once ())->method ('getParam ' )->with ('id ' , 0 )->willReturn ('some_id ' );
432
+ $ this ->objectManager ->expects ($ this ->at (1 ))
433
+ ->method ('create ' )
434
+ ->with (\Magento \Downloadable \Model \Link \Purchased \Item::class)
435
+ ->willReturn ($ this ->linkPurchasedItem );
436
+ $ this ->linkPurchasedItem ->expects ($ this ->once ())
437
+ ->method ('load ' )
438
+ ->with ('some_id ' , 'link_hash ' )
439
+ ->willReturnSelf ();
440
+ $ this ->linkPurchasedItem ->expects ($ this ->once ())->method ('getId ' )->willReturn (5 );
441
+ $ this ->helperData ->expects ($ this ->once ())
442
+ ->method ('getIsShareable ' )
443
+ ->with ($ this ->linkPurchasedItem )
444
+ ->willReturn (true );
445
+ $ this ->linkPurchasedItem ->expects ($ this ->any ())->method ('getNumberOfDownloadsBought ' )->willReturn (10 );
446
+ $ this ->linkPurchasedItem ->expects ($ this ->any ())->method ('getNumberOfDownloadsUsed ' )->willReturn (9 );
447
+ $ this ->linkPurchasedItem ->expects ($ this ->once ())->method ('getStatus ' )->willReturn ('available ' );
448
+ $ this ->linkPurchasedItem ->expects ($ this ->once ())->method ('getLinkType ' )->willReturn ('url ' );
449
+ $ this ->linkPurchasedItem ->expects ($ this ->once ())->method ('getLinkUrl ' )->willReturn ('link_url ' );
450
+
451
+ $ fileSize = 58493 ;
452
+ $ fileName = 'link.jpg ' ;
453
+
454
+ $ this ->downloadHelper ->expects ($ this ->once ())
455
+ ->method ('setResource ' )
456
+ ->with ('link_url ' , 'url ' )
457
+ ->willReturnSelf ();
458
+ $ this ->downloadHelper ->expects ($ this ->once ())->method ('getFilename ' )->willReturn ($ fileName );
459
+ $ this ->downloadHelper ->expects ($ this ->once ())->method ('getContentType ' )->willReturn ($ mimeType );
460
+ $ this ->response ->expects ($ this ->once ())->method ('setHttpResponseCode ' )->with (200 )->willReturnSelf ();
461
+ $ this ->response
462
+ ->expects ($ this ->any ())
463
+ ->method ('setHeader ' )
464
+ ->withConsecutive (
465
+ ['Pragma ' , 'public ' , true ],
466
+ ['Cache-Control ' , 'must-revalidate, post-check=0, pre-check=0 ' , true ],
467
+ ['Content-type ' , $ mimeType , true ],
468
+ ['Content-Length ' , $ fileSize ],
469
+ ['Content-Disposition ' , $ disposition . '; filename= ' . $ fileName ]
470
+ )
471
+ ->willReturnSelf ();
472
+
473
+ $ this ->assertEquals ($ this ->response , $ this ->link ->execute ());
474
+ }
475
+
397
476
/**
398
477
* @return array
399
478
*/
@@ -406,4 +485,15 @@ public function linkNotAvailableDataProvider()
406
485
['addError ' , 'wrong_status ' , 'Something went wrong while getting the requested content. ' ]
407
486
];
408
487
}
488
+
489
+ /**
490
+ * @return array
491
+ */
492
+ public function downloadTypesDataProvider ()
493
+ {
494
+ return [
495
+ ['mimeType ' => 'text/html ' , 'disposition ' => \Zend_Mime::DISPOSITION_ATTACHMENT ],
496
+ ['mimeType ' => 'image/jpeg ' , 'disposition ' => \Zend_Mime::DISPOSITION_INLINE ],
497
+ ];
498
+ }
409
499
}
0 commit comments