|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\ResourceBundle\Grid\Renderer; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; |
|
18
|
|
|
use Sylius\Bundle\ResourceBundle\Grid\Parser\OptionsParserInterface; |
|
19
|
|
|
use Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView; |
|
20
|
|
|
use Sylius\Component\Grid\Definition\Action; |
|
21
|
|
|
use Sylius\Component\Grid\Renderer\BulkActionGridRendererInterface; |
|
22
|
|
|
use Sylius\Component\Grid\Renderer\GridRendererInterface; |
|
23
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
24
|
|
|
|
|
25
|
|
|
final class TwigBulkActionGridRendererSpec extends ObjectBehavior |
|
26
|
|
|
{ |
|
27
|
|
|
function let(\Twig_Environment $twig, OptionsParserInterface $optionsParser): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->beConstructedWith( |
|
30
|
|
|
$twig, |
|
31
|
|
|
$optionsParser, |
|
32
|
|
|
['delete' => 'SyliusGridBundle:BulkAction:_delete.html.twig'] |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_is_a_bulk_action_grid_renderer(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->shouldImplement(BulkActionGridRendererInterface::class); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function it_uses_twig_to_render_the_bulk_action( |
|
42
|
|
|
\Twig_Environment $twig, |
|
43
|
|
|
OptionsParserInterface $optionsParser, |
|
44
|
|
|
ResourceGridView $gridView, |
|
45
|
|
|
Action $bulkAction, |
|
46
|
|
|
RequestConfiguration $requestConfiguration, |
|
47
|
|
|
Request $request |
|
48
|
|
|
): void { |
|
49
|
|
|
$bulkAction->getType()->willReturn('delete'); |
|
50
|
|
|
$bulkAction->getOptions()->willReturn([]); |
|
51
|
|
|
|
|
52
|
|
|
$gridView->getRequestConfiguration()->willReturn($requestConfiguration); |
|
53
|
|
|
$requestConfiguration->getRequest()->willReturn($request); |
|
54
|
|
|
|
|
55
|
|
|
$optionsParser->parseOptions([], $request, null)->shouldBeCalled(); |
|
56
|
|
|
|
|
57
|
|
|
$twig |
|
58
|
|
|
->render('SyliusGridBundle:BulkAction:_delete.html.twig', [ |
|
59
|
|
|
'grid' => $gridView, |
|
60
|
|
|
'action' => $bulkAction, |
|
61
|
|
|
'data' => null, |
|
62
|
|
|
'options' => [], |
|
63
|
|
|
]) |
|
64
|
|
|
->willReturn('<a href="#">Delete</a>') |
|
65
|
|
|
; |
|
66
|
|
|
|
|
67
|
|
|
$this->renderBulkAction($gridView, $bulkAction)->shouldReturn('<a href="#">Delete</a>'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
function it_throws_an_exception_if_template_is_not_configured_for_given_bulk_action_type( |
|
71
|
|
|
ResourceGridView $gridView, |
|
72
|
|
|
Action $bulkAction |
|
73
|
|
|
): void { |
|
74
|
|
|
$bulkAction->getType()->willReturn('foo'); |
|
75
|
|
|
|
|
76
|
|
|
$this |
|
77
|
|
|
->shouldThrow(new \InvalidArgumentException('Missing template for bulk action type "foo".')) |
|
78
|
|
|
->during('renderBulkAction', [$gridView, $bulkAction]) |
|
79
|
|
|
; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|