-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathShippingExportDownloadLabelActionSpec.php
75 lines (65 loc) · 2.33 KB
/
ShippingExportDownloadLabelActionSpec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace spec\BitBag\SyliusShippingExportPlugin\Controller;
use BitBag\SyliusShippingExportPlugin\Controller\ShippingExportDownloadLabelAction;
use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface;
use BitBag\SyliusShippingExportPlugin\Repository\ShippingExportRepositoryInterface;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
final class ShippingExportDownloadLabelActionSpec extends ObjectBehavior
{
function let(
Filesystem $filesystem,
ShippingExportRepositoryInterface $repository
): void {
$this->beConstructedWith(
$filesystem,
$repository,
'/var/www/shipping_labels'
);
}
function it_is_initializable(): void
{
$this->shouldHaveType(ShippingExportDownloadLabelAction::class);
}
function it_should_not_allow_directory_travelsal(
Request $request,
ShippingExportRepositoryInterface $repository,
ShippingExportInterface $shippingExport
): void {
$request->get('id')->willReturn(1);
$shippingExport->getLabelPath()
->willReturn('/var/www/shipping_labels/../.env')
;
$repository->find(1)->willReturn($shippingExport);
$this->shouldThrow(NotFoundHttpException::class)
->during('__invoke', [$request])
;
}
function it_returns_a_streamed_response_for_label(
Filesystem $filesystem,
Request $request,
ShippingExportRepositoryInterface $repository,
ShippingExportInterface $shippingExport
): void {
$request->get('id')
->willReturn(1)
;
$shippingExport->getLabelPath()
->willReturn('/var/www/shipping_labels/label.pdf')
;
$repository->find(1)
->willReturn($shippingExport)
;
$filesystem->exists('/var/www/shipping_labels/label.pdf')->willReturn(true);
$this->__invoke($request)
->shouldBeAnInstanceOf(StreamedResponse::class)
;
$this->__invoke($request)
->headers->get('Content-Disposition')
->shouldReturn('attachment; filename=label.pdf')
;
}
}