1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Odiseo\SyliusReportPlugin\Renderer; |
4
|
|
|
|
5
|
|
|
use Odiseo\SyliusReportPlugin\DataFetcher\Data; |
6
|
|
|
use Odiseo\SyliusReportPlugin\Form\Type\Renderer\TableConfigurationType; |
7
|
|
|
use Odiseo\SyliusReportPlugin\Model\ReportInterface; |
8
|
|
|
use Odiseo\SyliusReportPlugin\Renderer\RendererInterface; |
9
|
|
|
use Odiseo\SyliusReportPlugin\Renderer\TableRenderer; |
10
|
|
|
use PhpSpec\ObjectBehavior; |
11
|
|
|
use Symfony\Component\Templating\EngineInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Mateusz Zalewski <[email protected]> |
15
|
|
|
* @author Łukasz Chruściel <[email protected]> |
16
|
|
|
* @author Diego D'amico <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
final class TableRendererSpec extends ObjectBehavior |
19
|
|
|
{ |
20
|
|
|
function let(EngineInterface $templating) |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$this->beConstructedWith($templating); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
function it_is_initializable() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this->shouldHaveType(TableRenderer::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function it_should_implement_renderer_interface() |
31
|
|
|
{ |
32
|
|
|
$this->shouldImplement(RendererInterface::class); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_renders_data_with_given_configuration(ReportInterface $report, Data $reportData, EngineInterface $templating) |
36
|
|
|
{ |
37
|
|
|
$reportData->getLabels()->willReturn(['month', 'user_total']); |
38
|
|
|
$reportData->getData()->willReturn(['month1' => '50', 'month2' => '40']); |
39
|
|
|
|
40
|
|
|
$renderData = [ |
41
|
|
|
'report' => $report, |
42
|
|
|
'values' => ['month1' => '50', 'month2' => '40'], |
43
|
|
|
'labels' => ['month', 'user_total'], |
44
|
|
|
'fields' => ['month1', 'month2'], |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
$report->getRendererConfiguration()->willReturn(['template' => '@OdiseoSyliusReportPlugin/Table/default.html.twig']); |
48
|
|
|
|
49
|
|
|
$templating->render('@OdiseoSyliusReportPlugin/Table/default.html.twig', [ |
50
|
|
|
'data' => $renderData, |
51
|
|
|
'configuration' => ['template' => '@OdiseoSyliusReportPlugin/Table/default.html.twig'], |
52
|
|
|
])->willReturn('<div>Table Report</div>'); |
53
|
|
|
|
54
|
|
|
$this->render($report, $reportData)->shouldReturn('<div>Table Report</div>'); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
function it_renders_a_no_data_with_given_configuration(ReportInterface $report, Data $reportData, EngineInterface $templating) |
58
|
|
|
{ |
59
|
|
|
$reportData->getLabels()->willReturn(['month', 'user_total']); |
60
|
|
|
$reportData->getData()->willReturn(null); |
61
|
|
|
|
62
|
|
|
$report->getRendererConfiguration()->willReturn(['template' => '@OdiseoSyliusReportPlugin/noDataTemplate.html.twig']); |
63
|
|
|
|
64
|
|
|
$templating->render('@OdiseoSyliusReportPlugin/noDataTemplate.html.twig', [ |
65
|
|
|
'report' => $report, |
66
|
|
|
])->willReturn('<div>No Data</div>'); |
67
|
|
|
|
68
|
|
|
$this->render($report, $reportData)->shouldReturn('<div>No Data</div>'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
function it_is_a_table_type() |
72
|
|
|
{ |
73
|
|
|
$this->getType()->shouldReturn(TableConfigurationType::class); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.