Completed
Push — scalar-types/resource ( 4814fd )
by Kamil
23:02
created

TwigGridRendererSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\Renderer\TwigGridRenderer;
20
use Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView;
21
use Sylius\Component\Grid\Definition\Action;
22
use Sylius\Component\Grid\Renderer\GridRendererInterface;
23
use Symfony\Component\HttpFoundation\Request;
24
25
/**
26
 * @author Grzegorz Sadowski <[email protected]>
27
 */
28
final class TwigGridRendererSpec extends ObjectBehavior
29
{
30
    function let(
31
        GridRendererInterface $gridRenderer,
32
        \Twig_Environment $twig,
33
        OptionsParserInterface $optionsParser
34
    ): void {
35
        $actionTemplates = [
36
            'link' => 'SyliusGridBundle:Action:_link.html.twig',
37
            'form' => 'SyliusGridBundle:Action:_form.html.twig',
38
        ];
39
40
        $this->beConstructedWith(
41
            $gridRenderer,
42
            $twig,
43
            $optionsParser,
44
            $actionTemplates
45
        );
46
    }
47
48
    function it_is_a_grid_renderer(): void
49
    {
50
        $this->shouldImplement(GridRendererInterface::class);
51
    }
52
53
    function it_uses_twig_to_render_the_action(
54
        \Twig_Environment $twig,
55
        OptionsParserInterface $optionsParser,
56
        ResourceGridView $gridView,
57
        Action $action,
58
        RequestConfiguration $requestConfiguration,
59
        Request $request
60
    ): void {
61
        $action->getType()->willReturn('link');
62
        $action->getOptions()->willReturn([]);
63
64
        $gridView->getRequestConfiguration()->willReturn($requestConfiguration);
65
        $requestConfiguration->getRequest()->willReturn($request);
66
67
        $optionsParser->parseOptions([], $request, null)->shouldBeCalled();
68
69
        $twig
70
            ->render('SyliusGridBundle:Action:_link.html.twig', [
71
                'grid' => $gridView,
72
                'action' => $action,
73
                'data' => null,
74
                'options' => [],
75
            ])
76
            ->willReturn('<a href="#">Action!</a>')
77
        ;
78
79
        $this->renderAction($gridView, $action)->shouldReturn('<a href="#">Action!</a>');
80
    }
81
82
    function it_throws_an_exception_if_template_is_not_configured_for_given_action_type(
83
        ResourceGridView $gridView,
84
        Action $action
85
    ): void {
86
        $action->getType()->willReturn('foo');
87
88
        $this
89
            ->shouldThrow(new \InvalidArgumentException('Missing template for action type "foo".'))
90
            ->during('renderAction', [$gridView, $action])
91
        ;
92
    }
93
}
94