/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testGetPurchaseChartView() { $from = new DateTime(); $expectedArrayData = [['label' => 'orocrm.magento.dashboard.purchase_chart.visited', 'value' => 10, 'isNozzle' => false], ['label' => 'orocrm.magento.dashboard.purchase_chart.deeply_visited', 'value' => 5, 'isNozzle' => false], ['label' => 'orocrm.magento.dashboard.purchase_chart.added_to_cart', 'value' => 30, 'isNozzle' => false], ['label' => 'orocrm.magento.dashboard.purchase_chart.purchased', 'value' => 13, 'isNozzle' => true]]; $expectedOptions = ['name' => 'flow_chart', 'settings' => ['quarterDate' => $from], 'data_schema' => ['label' => ['field_name' => 'label', 'label' => null, 'type' => 'string'], 'value' => ['field_name' => 'value', 'label' => null, 'type' => 'integer'], 'isNozzle' => ['field_name' => 'isNozzle', 'label' => null, 'type' => 'boolean']]]; $chartConfig = ['data_schema' => $expectedOptions['data_schema']]; $this->trackingVisitProvider->expects($this->once())->method('getVisitedCount')->will($this->returnValue(10)); $this->trackingVisitProvider->expects($this->once())->method('getDeeplyVisitedCount')->will($this->returnValue(5)); $cartRepository = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\CartRepository')->disableOriginalConstructor()->getMock(); $cartRepository->expects($this->once())->method('getCustomersCountWhatMakeCarts')->will($this->returnValue(30)); $this->registry->expects($this->at(0))->method('getRepository')->with('OroCRMMagentoBundle:Cart')->will($this->returnValue($cartRepository)); $orderRepository = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\OrderRepository')->disableOriginalConstructor()->getMock(); $orderRepository->expects($this->once())->method('getUniqueBuyersCount')->will($this->returnValue(13)); $this->registry->expects($this->at(1))->method('getRepository')->with('OroCRMMagentoBundle:Order')->will($this->returnValue($orderRepository)); $chartView = $this->getMockBuilder('Oro\\Bundle\\ChartBundle\\Model\\ChartView')->disableOriginalConstructor()->getMock(); $chartViewBuilder = $this->getMockBuilder('Oro\\Bundle\\ChartBundle\\Model\\ChartViewBuilder')->disableOriginalConstructor()->getMock(); $chartViewBuilder->expects($this->once())->method('setOptions')->with($expectedOptions)->will($this->returnSelf()); $chartViewBuilder->expects($this->once())->method('setArrayData')->with($expectedArrayData)->will($this->returnSelf()); $chartViewBuilder->expects($this->once())->method('getView')->will($this->returnValue($chartView)); $this->configProvider->expects($this->once())->method('getChartConfig')->with('purchase_chart')->will($this->returnValue($chartConfig)); $this->dataProvider->getPurchaseChartView($chartViewBuilder, $from, new DateTime()); }
/** * @param ChartViewBuilder $viewBuilder * @param DateTime $from * @param DateTime $to * * @return ChartView */ public function getPurchaseChartView(ChartViewBuilder $viewBuilder, DateTime $from, DateTime $to) { $items = [['label' => $this->translator->trans('orocrm.magento.dashboard.purchase_chart.visited'), 'value' => $this->trackingVisitProvider->getVisitedCount($from, $to), 'isNozzle' => false], ['label' => $this->translator->trans('orocrm.magento.dashboard.purchase_chart.deeply_visited'), 'value' => $this->trackingVisitProvider->getDeeplyVisitedCount($from, $to), 'isNozzle' => false], ['label' => $this->translator->trans('orocrm.magento.dashboard.purchase_chart.added_to_cart'), 'value' => $this->getCartRepository()->getCustomersCountWhatMakeCarts($this->aclHelper, $from, $to), 'isNozzle' => false], ['label' => $this->translator->trans('orocrm.magento.dashboard.purchase_chart.purchased'), 'value' => $this->getOrderRepository()->getUniqueBuyersCount($this->aclHelper, $from, $to), 'isNozzle' => true]]; $chartOptions = array_merge_recursive(['name' => 'flow_chart', 'settings' => ['quarterDate' => $from]], $this->configProvider->getChartConfig('purchase_chart')); return $viewBuilder->setOptions($chartOptions)->setArrayData($items)->getView(); }