Exemplo n.º 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));
 }
Exemplo n.º 2
0
 /**
  * @dataProvider getRevenueOverTimeChartViewDataProvider
  */
 public function testGetRevenueOverTimeChartView($sourceData, $expectedArrayData, $expectedOptions, $chartConfig)
 {
     $from = new DateTime('2015-05-10');
     $to = new DateTime('2015-05-15');
     $previousFrom = new DateTime('2015-05-05');
     $previousTo = new DateTime('2015-05-10');
     $this->dateHelper->expects($this->any())->method('getFormatStrings')->willReturn(['viewType' => 'day']);
     $this->dateHelper->expects($this->once())->method('getPeriod')->willReturnCallback(function ($dateRange) {
         return [$dateRange['start'], $dateRange['end']];
     });
     $this->dateHelper->expects($this->once())->method('convertToCurrentPeriod')->will($this->returnValue($expectedArrayData['2015-05-10 - 2015-05-15']));
     $this->dateHelper->expects($this->once())->method('combinePreviousDataWithCurrentPeriod')->will($this->returnValue($expectedArrayData['2015-05-05 - 2015-05-10']));
     $this->dateTimeFormatter->expects($this->exactly(4))->method('formatDate')->will($this->onConsecutiveCalls('2015-05-05', '2015-05-10', '2015-05-10', '2015-05-15'));
     $orderRepository = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\OrderRepository')->disableOriginalConstructor()->getMock();
     $orderRepository->expects($this->at(0))->method('getRevenueOverTime')->with($this->aclHelper, $this->dateHelper, $from, $to)->will($this->returnValue($sourceData[0]));
     $orderRepository->expects($this->at(1))->method('getRevenueOverTime')->with($this->aclHelper, $this->dateHelper, $previousFrom, $previousTo)->will($this->returnValue($sourceData[1]));
     $this->registry->expects($this->any())->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('revenue_over_time_chart')->will($this->returnValue($chartConfig));
     $this->assertEquals($chartView, $this->dataProvider->getRevenueOverTimeChartView($chartViewBuilder, ['start' => $from, 'end' => $to]));
 }