Esempio n. 1
0
 /**
  * @covers \Altamira\JsWriter\JqPlot::getOptionsJS
  */
 public function testJqPlotJsArrayHidesTitleWhenRequired()
 {
     $chart = new \Altamira\Chart('foo', \Altamira\JsWriter\JqPlot::LIBRARY);
     $chart->setTitle("I am a title");
     $reflGet = new ReflectionMethod('\\Altamira\\JsWriter\\JqPlot', 'getOptionsJs');
     $reflGet->setAccessible(true);
     $origJs = json_decode($reflGet->invoke($chart->getJsWriter()), true);
     $this->assertArrayHasKey('title', $origJs, '\\Altamira\\JsWriter\\JqPlot::getOptionsJS should encode a value for the chart title by default');
     $newJs = json_decode($reflGet->invoke($chart->hideTitle()->getJsWriter()), true);
     $this->assertArrayNotHasKey('title', $newJs, '\\Altamira\\JsWriter\\JqPlot::getOptionsJS should not encode a value for the chart title if the chart is hiding its title');
 }
Esempio n. 2
0
 /**
  * @covers \Altamira\Chart::__construct
  * @covers \Altamira\Chart::getJsWriter
  * @covers \Altamira\Chart::getName
  * @covers \Altamira\Chart::getTitle
  * @covers \Altamira\Chart::setTitle
  * @covers \Altamira\Chart::useHighlighting
  * @covers \Altamira\Chart::useZooming
  * @covers \Altamira\Chart::useCursor
  * @covers \Altamira\Chart::useDates
  * @covers \Altamira\Chart::setAxisTicks
  * @covers \Altamira\Chart::setAxisOptions
  * @covers \Altamira\Chart::setSeriesColors
  * @covers \Altamira\Chart::setAxisLabel
  * @covers \Altamira\Chart::setType
  * @covers \Altamira\Chart::setTypeOption
  * @covers \Altamira\Chart::setLegend
  * @covers \Altamira\Chart::setGrid
  * @covers \Altamira\Chart::getFiles
  * @covers \Altamira\Chart::getScript
  * @covers \Altamira\Chart::getJsWriter
  * @covers \Altamira\Chart::getLibrary
  * @covers \Altamira\Chart::getSeries
  * @covers \Altamira\Chart::addSeries
  * @covers \Altamira\Chart::addSingleSeries
  * @covers \Altamira\Chart::createManySeries
  * @covers \Altamira\Chart::createSeries
  * @covers \Altamira\Chart::getDiv
  */
 public function testChart()
 {
     $exception = false;
     try {
         $chart = new \Altamira\Chart('');
     } catch (Exception $exception) {
     }
     $this->assertInstanceOf('Exception', $exception, '\\Altamira\\Chart should throw an exception if it passed an empty name');
     $jqplotChart = new \Altamira\Chart('chart 1');
     $flotChart = new \Altamira\Chart('chart2', \Altamira\JsWriter\Flot::LIBRARY);
     $libraryException = false;
     try {
         $crapChart = new \Altamira\Chart('chart3', 'notareallibrary');
     } catch (Exception $libraryException) {
     }
     $this->assertInstanceOf('Exception', $libraryException, 'A chart should throw an exception if we don\'t support the library.');
     $this->assertInstanceOf('\\Altamira\\JsWriter\\JqPlot', $jqplotChart->getJsWriter(), 'Charts should register a JqPlot JsWriter by default');
     $writermethods = array('useHighlighting', 'useZooming', 'useCursor', 'useDates', 'setAxisTicks', 'setAxisOptions', 'setOption', 'getOption', 'setType', 'setTypeOption', 'setLegend', 'setGrid', 'getType', 'getFiles', 'getScript', 'getLibrary');
     $mockJqPlotWriter = $this->getMock('\\Altamira\\JsWriter\\JqPlot', $writermethods, array($jqplotChart));
     $mockFlotWriter = $this->getMock('\\Altamira\\JsWriter\\Flot', $writermethods, array($flotChart));
     $jsWriterReflection = new ReflectionProperty('\\Altamira\\Chart', 'jsWriter');
     $jsWriterReflection->setAccessible(true);
     $jsWriterReflection->setValue($jqplotChart, $mockJqPlotWriter);
     $jsWriterReflection->setValue($flotChart, $mockFlotWriter);
     $this->assertEquals('chart_1', $jqplotChart->getName(), 'Name values should be normalized to turn whitespace into underscores');
     $flotChart->setTitle('This is a flot chart');
     $this->assertEquals('This is a flot chart', $flotChart->getTitle(), '\\Altamira\\Chart::getTitle should return title if set');
     $this->assertEquals('chart_1', $jqplotChart->getTitle(), '\\Altamira\\Chart::getTitle should return name if title not set');
     $mockJqPlotWriter->expects($this->once())->method('useHighlighting')->with(array('size' => 7.5));
     $this->assertEquals($jqplotChart, $jqplotChart->useHighlighting(), '\\Altamira\\Chart::useHighlighting should provide a fluent interface');
     $mockJqPlotWriter->expects($this->once())->method('useZooming');
     $this->assertEquals($jqplotChart, $jqplotChart->useZooming(), '\\Altamira\\Chart::useZooming should provide a fluent interface');
     $mockJqPlotWriter->expects($this->once())->method('useCursor');
     $this->assertEquals($jqplotChart, $jqplotChart->useCursor(), '\\Altamira\\Chart::useCursor should provide a fluent interface');
     $mockJqPlotWriter->expects($this->once())->method('useDates');
     $this->assertEquals($jqplotChart, $jqplotChart->useDates(), '\\Altamira\\Chart::useDates should provide a fluent interface');
     $mockJqPlotWriter->expects($this->once())->method('setAxisTicks')->with('x', array('one', 'two', 'three'));
     $this->assertEquals($jqplotChart, $jqplotChart->setAxisTicks('x', array('one', 'two', 'three')), '\\Altamira\\Chart::setAxisTicks should provide a fluent interface');
     $mockJqPlotWriter->expects($this->once())->method('setAxisOptions')->with('x', 'max', 10);
     $this->assertEquals($jqplotChart, $jqplotChart->setAxisOptions('x', 'max', 10), '\\Altamira\\Chart::setAxisOptions should provide a fluent interface');
     $mockJqPlotWriter->expects($this->at(0))->method('setOption')->with('seriesColors', array('#333333', '#666666'));
     $this->assertEquals($jqplotChart, $jqplotChart->setSeriesColors(array('#333333', '#666666')), '\\Altamira\\Chart::setSeriesColors should provide a fluent interface');
     $mockAxisOptions = array('xaxis' => array('min' => 0, 'max' => 10), 'yaxis' => array('min' => 0, 'max' => 10));
     $mockJqPlotWriter->expects($this->at(0))->method('getOption')->with('axes', array())->will($this->returnValue($mockAxisOptions));
     $mockAxisOptions['xaxis']['label'] = 'x';
     $mockJqPlotWriter->expects($this->at(1))->method('setOption')->with('axes', $mockAxisOptions);
     $this->assertEquals($jqplotChart, $jqplotChart->setAxisLabel('x', 'x'), '\\Altamira\\Chart::setAxisLabel should provide a fluent interface');
     $mockJqPlotWriter->expects($this->once())->method('setType')->with('Donut');
     $this->assertEquals($jqplotChart, $jqplotChart->setType('Donut'), '\\Altamira\\Chart::setType should provide a fluent interface');
     $mockJqPlotWriter->expects($this->once())->method('setTypeOption')->with('hole', '50px', null);
     $this->assertEquals($jqplotChart, $jqplotChart->setTypeOption('hole', '50px'), '\\Altamira\\Chart::setTypeOption should provide a fluent interface');
     $opts = array('on' => 'true', 'location' => 'ne', 'x' => 0, 'y' => 0);
     $mockJqPlotWriter->expects($this->once())->method('setLegend')->with($opts);
     $this->assertEquals($jqplotChart, $jqplotChart->setLegend(), '\\Altamira\\Chart::setLegend should provide a fluent interface');
     $mockJqPlotWriter->expects($this->once())->method('setGrid')->with(array('on' => true));
     $this->assertEquals($jqplotChart, $jqplotChart->setGrid(), '\\Altamira\\Chart::setGrid should provide a fluent interface');
     $mockJqPlotWriter->expects($this->once())->method('getFiles');
     $jqplotChart->getFiles();
     $mockJqPlotWriter->expects($this->once())->method('getScript');
     $jqplotChart->getScript();
     $seriesData = \Altamira\ChartDatum\TwoDimensionalPointFactory::getFromXValues(array(1, 2, 3));
     $series = $jqplotChart->createSeries($seriesData, 'seriesa', 'Donut');
     $this->assertInstanceOf('\\Altamira\\Series', $series, '\\Altamira\\Chart::createSeries should return an instance of \\Altamira\\Series');
     $this->assertEquals('seriesa', $series->getTitle(), '\\Altamira\\Chart::createSeries should set the series title');
     $this->assertEquals($seriesData, $series->getData(), '\\Altamira\\Chart::createSeries should set the series data');
     $jqplotChart->addSeries($series);
     $seriesArray = $jqplotChart->getSeries();
     $this->assertEquals(array($series->getTitle() => $series), $seriesArray);
     $this->assertArrayHasKey($series->getTitle(), $seriesArray);
     $this->assertEquals($jqplotChart->getLibrary(), $mockJqPlotWriter->getLibrary());
     $styleOptions = array('width' => '100px', 'height' => '200px');
     $this->assertEquals(\Altamira\ChartRenderer::render($jqplotChart, $styleOptions), $jqplotChart->getDiv(100, 200));
 }