/** * {@inheritdoc} * * @throws \InvalidArgumentException If the report subject does not have a renderer. */ public function render(ReportInterface $subject, Data $data) { if (null === ($type = $subject->getRenderer())) { throw new \InvalidArgumentException('Cannot render data for ReportInterface instance without renderer defined.'); } $renderer = $this->registry->get($type); return $renderer->render($subject, $data); }
function it_renders_data_with_given_configuration(ReportInterface $report, Data $reportData, $templating) { $reportData->getData()->willReturn(array('month1' => '50', 'month2' => '40')); $renderData = array('report' => $report, 'values' => array('month1' => '50', 'month2' => '40'), 'labels' => array('month1', 'month2')); $report->getRendererConfiguration()->willReturn(array('template' => 'SyliusReportBundle:Chart:default.html.twig')); $templating->render('SyliusReportBundle:Chart:default.html.twig', array('data' => $renderData, 'configuration' => array('template' => 'SyliusReportBundle:Chart:default.html.twig')))->willReturn('<div>Chart Report</div>'); $this->render($report, $reportData)->shouldReturn('<div>Chart Report</div>'); }
/** * {@inheritdoc} */ public function render(ReportInterface $report, Data $data) { if (null !== $data->getData()) { $data = array('report' => $report, 'values' => $data->getData(), 'labels' => $data->getLabels(), 'fields' => array_keys($data->getData())); $rendererConfiguration = $report->getRendererConfiguration(); return $this->templating->render($rendererConfiguration["template"], array('data' => $data, 'configuration' => $rendererConfiguration)); } return $this->templating->render("SyliusReportBundle::noDataTemplate.html.twig", array('report' => $report)); }
/** * {@inheritdoc} * * @throws \InvalidArgumentException If the report does not have a data fetcher. */ public function fetch(ReportInterface $report, array $configuration = []) { if (null === ($type = $report->getDataFetcher())) { throw new \InvalidArgumentException('Cannot fetch data for ReportInterface instance without DataFetcher defined.'); } $dataFetcher = $this->registry->get($type); $configuration = empty($configuration) ? $report->getDataFetcherConfiguration() : $configuration; return $dataFetcher->fetch($configuration); }
/** * {@inheritdoc} */ public function render(ReportInterface $report, Data $data) { if (null !== $data->getData()) { $rendererData = ['report' => $report, 'values' => $data->getData(), 'labels' => array_keys($data->getData())]; $rendererConfiguration = $report->getRendererConfiguration(); return $this->templating->render($rendererConfiguration['template'], ['data' => $rendererData, 'configuration' => $rendererConfiguration]); } return $this->templating->render('SyliusReportBundle::noDataTemplate.html.twig', ['report' => $report]); }
function it_renders_data_with_given_configuration(ReportInterface $report, Response $response, Data $reportData, $templating) { $reportData->getLabels()->willReturn(array('month', 'user_total')); $reportData->getData()->willReturn(array('month1' => '50', 'month2' => '40')); $renderData = array('report' => $report, 'values' => array('month1' => '50', 'month2' => '40'), 'labels' => array('month', 'user_total'), 'fields' => array('month1', 'month2')); $report->getRendererConfiguration()->willReturn(array('template' => 'SyliusReportBundle:Table:default.html.twig')); $templating->renderResponse('SyliusReportBundle:Table:default.html.twig', array('data' => $renderData, 'configuration' => array('template' => 'SyliusReportBundle:Table:default.html.twig')))->willReturn($response); $this->render($report, $reportData)->shouldReturn($response); }
function it_renders_data_with_given_configuration(ReportInterface $report, Data $reportData, $templating) { $reportData->getLabels()->willReturn(['month', 'user_total']); $reportData->getData()->willReturn(['month1' => '50', 'month2' => '40']); $renderData = ['report' => $report, 'values' => ['month1' => '50', 'month2' => '40'], 'labels' => ['month', 'user_total'], 'fields' => ['month1', 'month2']]; $report->getRendererConfiguration()->willReturn(['template' => 'SyliusReportBundle:Table:default.html.twig']); $templating->render('SyliusReportBundle:Table:default.html.twig', ['data' => $renderData, 'configuration' => ['template' => 'SyliusReportBundle:Table:default.html.twig']])->willReturn('<div>Table Report</div>'); $this->render($report, $reportData)->shouldReturn('<div>Table Report</div>'); }
function it_adds_configuration_fields_in_pre_set_data($factory, ReportInterface $report, FormEvent $event, Form $form, Form $field) { $report->getDataFetcher()->willReturn('test_data_fetcher'); $report->getDataFetcherConfiguration()->willReturn(array()); $event->getData()->willReturn($report); $event->getForm()->willReturn($form); $factory->createNamed('dataFetcherConfiguration', 'sylius_data_fetcher_test_type', Argument::cetera())->willReturn($field); $form->add($field)->shouldBeCalled(); $this->preSetData($event); }
public function it_should_throw_exception_if_report_has_no_renderer_defined(ReportInterface $subject, Data $data) { $subject->getRenderer()->willReturn(null); $this->shouldThrow(new \InvalidArgumentException('Cannot render data for ReportInterface instance without renderer defined.'))->duringRender($subject, $data); }
public function it_should_complain_if_report_has_no_data_fetcher_defined(ReportInterface $subject) { $subject->getDataFetcher()->willReturn(null); $this->shouldThrow(new \InvalidArgumentException('Cannot fetch data for ReportInterface instance without DataFetcher defined.'))->duringFetch($subject); }