/**
  * @depends testSetAndGetChart
  */
 public function testValidate()
 {
     $chart = new ChartForReportForm();
     $validated = $chart->validate();
     $this->assertTrue($validated);
     $chart->type = 'Bar2D';
     $validated = $chart->validate();
     $this->assertFalse($validated);
     $errors = $chart->getErrors();
     $compareErrors = array('firstSeries' => array('First Series cannot be blank.'), 'firstRange' => array('First Range cannot be blank.'));
     $this->assertEquals($compareErrors, $errors);
     $chart->firstSeries = 'dropDown';
     $chart->firstRange = 'float__Summation';
     $validated = $chart->validate();
     $this->assertTrue($validated);
     //When the type is a StackedColumn2D, it should require the second series and range
     $chart->type = 'StackedColumn2D';
     $validated = $chart->validate();
     $this->assertFalse($validated);
     $errors = $chart->getErrors();
     $compareErrors = array('secondSeries' => array('Second Series cannot be blank.'), 'secondRange' => array('Second Range cannot be blank.'));
     $this->assertEquals($compareErrors, $errors);
     $chart->secondSeries = 'integer';
     $chart->secondRange = 'integer__Summation';
     $validated = $chart->validate();
     $this->assertTrue($validated);
 }
 /**
  * @param array $data
  * @param Report $report
  */
 protected static function resolveChart($data, Report $report)
 {
     if ($report->getType() != Report::TYPE_SUMMATION) {
         return;
     }
     $moduleClassName = $report->getModuleClassName();
     if ($moduleClassName != null) {
         $modelClassName = $moduleClassName::getPrimaryModelName();
         $adapter = ModelRelationsAndAttributesToSummationReportAdapter::make($moduleClassName, $modelClassName, $report->getType());
         $seriesDataAndLabels = ReportUtil::makeDataAndLabelsForSeriesOrRange($adapter->getAttributesForChartSeries($report->getGroupBys(), $report->getDisplayAttributes()));
         $rangeDataAndLabels = ReportUtil::makeDataAndLabelsForSeriesOrRange($adapter->getAttributesForChartRange($report->getDisplayAttributes()));
     } else {
         $seriesDataAndLabels = array();
         $rangeDataAndLabels = array();
     }
     $chart = new ChartForReportForm($seriesDataAndLabels, $rangeDataAndLabels);
     if (null != ($chartData = ArrayUtil::getArrayValue($data, 'ChartForReportForm'))) {
         $chart->setAttributes($chartData);
     }
     $report->setChart($chart);
 }
 public function testValidateChartForErrors()
 {
     $summationReportWizardForm = new SummationReportWizardForm();
     $chart = new ChartForReportForm();
     $summationReportWizardForm->chart = $chart;
     $chart->type = 'Bar2D';
     $chart->firstSeries = 'dropDown';
     $summationReportWizardForm->validateChart();
     $validated = $chart->validate();
     $this->assertFalse($validated);
     $errors = $chart->getErrors();
     $compareErrors = array('firstRange' => array('First Range cannot be blank.'));
     $this->assertEquals($compareErrors, $errors);
     $this->assertTrue($summationReportWizardForm->hasErrors());
 }
 /**
  * @param ChartForReportForm $chartForReportForm
  * @return array
  */
 protected static function makeArrayFromChartForReportFormAttributesData(ChartForReportForm $chartForReportForm)
 {
     $data = array();
     foreach ($chartForReportForm->getAttributes() as $attribute => $value) {
         $data[$attribute] = $value;
     }
     return $data;
 }