/** * @depends testSetAndGetGroupBy */ public function testValidate() { $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION); $groupBy->attributeIndexOrDerivedType = 'string'; $groupBy->axis = null; $validated = $groupBy->validate(); $this->assertFalse($validated); $errors = $groupBy->getErrors(); $compareErrors = array('axis' => array('Axis cannot be blank.')); $this->assertEquals($compareErrors, $errors); $groupBy->axis = 'z'; $validated = $groupBy->validate(); $this->assertFalse($validated); $errors = $groupBy->getErrors(); $compareErrors = array('axis' => array('Axis must be x or y.')); $this->assertEquals($compareErrors, $errors); $groupBy->axis = 'y'; $validated = $groupBy->validate(); $this->assertTrue($validated); }
/** * @param array $data * @param Report $report */ protected static function resolveGroupBys($data, Report $report) { $report->removeAllGroupBys(); $moduleClassName = $report->getModuleClassName(); if (count($groupBysData = ArrayUtil::getArrayValue($data, ComponentForReportForm::TYPE_GROUP_BYS)) > 0) { foreach ($groupBysData as $key => $groupByData) { $groupBy = new GroupByForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(), $report->getType(), $key); $groupBy->setAttributes($groupByData); $report->addGroupBy($groupBy); } } else { $report->removeAllGroupBys(); } }
/** * @return string */ public static function getTreeType() { return GroupByForReportForm::getType(); }