/** * This method returns all usage for a chart based on the chartconfig given * * @param ChartConfig $chartConfig * @return array */ public function getChartUsage(ChartConfig $chartConfig) { $provider = $this->dataProviderFactory->getDataProviderByConfig($chartConfig); $data = $provider->getChartUsage(); $adapter = $this->chartTypeAdapterFactory->getChartTypeAdapterByConfig($chartConfig); return $adapter->formatData($data); }
public function testGetChartTypeAdapterByConfigTest() { $factory = new ChartTypeAdapterFactory($this->user); $mock1 = clone $this->config; $mock1->expects($this->once())->method('getChartType')->willReturn("StorageUsageCurrent"); $adapter = $factory->getChartTypeAdapterByConfig($mock1); $this->assertInstanceOf('OCA\\ocUsageCharts\\Adapters\\c3js\\Storage\\StorageUsageCurrentAdapter', $adapter); $mock2 = clone $this->config; $mock2->expects($this->once())->method('getChartType')->willReturn("StorageUsageLastMonth"); $adapter = $factory->getChartTypeAdapterByConfig($mock2); $this->assertInstanceOf('OCA\\ocUsageCharts\\Adapters\\c3js\\Storage\\StorageUsageLastMonthAdapter', $adapter); $mock3 = clone $this->config; $mock3->expects($this->once())->method('getChartType')->willReturn("StorageUsagePerMonth"); $adapter = $factory->getChartTypeAdapterByConfig($mock3); $this->assertInstanceOf('OCA\\ocUsageCharts\\Adapters\\c3js\\Storage\\StorageUsagePerMonthAdapter', $adapter); $mock4 = clone $this->config; $mock4->expects($this->once())->method('getChartType')->willReturn("ActivityUsageLastMonth"); $adapter = $factory->getChartTypeAdapterByConfig($mock4); $this->assertInstanceOf('OCA\\ocUsageCharts\\Adapters\\c3js\\Activity\\ActivityUsageLastMonthAdapter', $adapter); $mock5 = clone $this->config; $mock5->expects($this->once())->method('getChartType')->willReturn("ActivityUsagePerMonth"); $adapter = $factory->getChartTypeAdapterByConfig($mock5); $this->assertInstanceOf('OCA\\ocUsageCharts\\Adapters\\c3js\\Activity\\ActivityUsagePerMonthAdapter', $adapter); $this->setExpectedException('OCA\\ocUsageCharts\\Exception\\ChartTypeAdapterException'); $mock6 = clone $this->config; $mock6->expects($this->exactly(2))->method('getChartType')->willReturn("undefined"); $factory->getChartTypeAdapterByConfig($mock6); }
/** * @param ChartConfig $config * @return ChartTypeAdapterInterface * * @throws \OCA\ocUsageCharts\Exception\ChartServiceException */ public function getChartByConfig(ChartConfig $config) { /** @var ChartTypeAdapterInterface $chartAdapter */ $chartAdapter = $this->chartTypeAdapterFactory->getChartTypeAdapterByConfig($config); if (!in_array($config->getChartProvider(), $this->isLoaded)) { $chartAdapter->loadFrontend(); $this->isLoaded[] = $config->getChartProvider(); } return $chartAdapter; }
public function testGetChartUsage() { $data = array('x' => array(111, 112), $this->configMock->getUsername() => array(145, 454646)); $provider = $this->getMockBuilder('OCA\\ocUsageCharts\\DataProviders\\Storage\\StorageUsageCurrentProvider')->disableOriginalConstructor()->getMock(); $provider->expects($this->once())->method('getChartUsage')->willReturn($data); $this->dataProviderFactory->method('getDataProviderByConfig')->willReturn($provider); $adapter = $this->getMockBuilder('OCA\\ocUsageCharts\\Adapters\\c3js\\Storage\\StorageUsageLastMonthAdapter')->disableOriginalConstructor()->getMock(); $adapter->expects($this->once())->method('formatData')->willReturn($data); $this->chartTypeAdapterFactory->expects($this->once())->method('getChartTypeAdapterByConfig')->willReturn($adapter); $data = $this->dataProvider->getChartUsage($this->configMock); $this->assertArrayHasKey('x', $data); $this->assertArrayHasKey($this->configMock->getUsername(), $data); }
/** * This returns the data adapter for a specific provider * This is use full when you want to implement alternatives for the current * chart providers * * @param ChartConfig $config * @return ChartTypeAdapterInterface * @throws \OCA\ocUsageCharts\Exception\ChartTypeAdapterException */ private function getProviderAdapterByConfig(ChartConfig $config) { return $this->chartTypeAdapterFactory->getChartTypeAdapterByConfig($config); }