示例#1
0
 public function testGetAverageOrderAmountByCustomerChartView()
 {
     $sourceOrderData = [1 => ['name' => 'First', 'data' => [2014 => [9 => 3]]], 2 => ['name' => 'Second', 'data' => [2014 => [9 => 5]]]];
     $expectedArrayData = ['First' => [['month' => '2014-09-01', 'amount' => 3]], 'Second' => [['month' => '2014-09-01', 'amount' => 5]]];
     $expectedOptions = ['name' => 'multiline_chart', 'data_schema' => ['label' => ['field_name' => 'month', 'label' => null, 'type' => 'month'], 'value' => ['field_name' => 'amount', 'label' => 'orocrm.magento.dashboard.average_order_amount_chart.order_amount.trans', 'type' => 'currency']]];
     $orderRepository = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\OrderRepository')->disableOriginalConstructor()->getMock();
     $orderRepository->expects($this->once())->method('getAverageOrderAmount')->with($this->aclHelper)->will($this->returnValue($sourceOrderData));
     $this->registry->expects($this->once())->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->assertEquals($chartView, $this->dataProvider->getAverageOrderAmountChartView($chartViewBuilder));
 }
示例#2
0
 public function testGetAverageOrderAmountByCustomerChartView()
 {
     $sourceOrderData = ['First' => [['month' => '2014-09-01', 'amount' => 3]], 'Second' => [['month' => '2014-09-01', 'amount' => 5]]];
     $expectedArrayData = ['First' => [['month' => '2014-09-01', 'amount' => 3]], 'Second' => [['month' => '2014-09-01', 'amount' => 5]]];
     $expectedOptions = ['name' => 'multiline_chart', 'data_schema' => ['label' => ['field_name' => 'month', 'label' => 'oro.dashboard.chart.month.label', 'type' => 'month'], 'value' => ['field_name' => 'amount', 'label' => 'orocrm.magento.dashboard.average_order_amount_chart.order_amount', 'type' => 'currency']]];
     $chartConfig = ['data_schema' => ['label' => ['field_name' => 'month', 'label' => 'orocrm.magento.dashboard.average_order_amount_chart.month', 'type' => 'month'], 'value' => ['field_name' => 'amount', 'label' => 'orocrm.magento.dashboard.average_order_amount_chart.order_amount', 'type' => 'currency']]];
     $orderRepository = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\OrderRepository')->disableOriginalConstructor()->getMock();
     $start = new \DateTime('2012-01-01');
     $end = new \DateTime('2015-01-01');
     $dateHelper = $this->getMockBuilder('Oro\\Bundle\\DashboardBundle\\Helper\\DateHelper')->disableOriginalConstructor()->getMock();
     $dateHelper->expects($this->any())->method('getFormatStrings')->willReturn(['viewType' => 'month']);
     $dateHelper->expects($this->once())->method('getPeriod')->willReturnCallback(function ($dateRange) {
         return [$dateRange['start'], $dateRange['end']];
     });
     $orderRepository->expects($this->once())->method('getAverageOrderAmount')->with($this->aclHelper, $start, $end, $dateHelper)->will($this->returnValue($sourceOrderData));
     $this->registry->expects($this->once())->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('average_order_amount')->will($this->returnValue($chartConfig));
     $this->assertEquals($chartView, $this->dataProvider->getAverageOrderAmountChartView($chartViewBuilder, ['start' => $start, 'end' => $end], $dateHelper));
 }