From: jitendrapurohit Date: Fri, 15 Jul 2016 11:06:07 +0000 (+0530) Subject: Add test and minor fixes X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7343d8a78c0bc6b6663faf1a3c8cbe26ab947988;p=civicrm-core.git Add test and minor fixes --- diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 82d7c1b406..9529e6d9eb 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -2517,7 +2517,6 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND public function processReportMode() { $this->setOutputMode(); - $buttonName = $this->controller->getButtonName(); $this->_sendmail = CRM_Utils_Request::retrieve( 'sendmail', @@ -4602,7 +4601,6 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a * is that we might print a bar chart as a pdf. */ protected function setOutputMode() { - $buttonName = $this->controller->getButtonName(); $this->_outputMode = str_replace('report_instance.', '', CRM_Utils_Request::retrieve( 'output', 'String', @@ -4610,12 +4608,13 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a FALSE, CRM_Utils_Array::value('task', $this->_params) )); + // if contacts are added to group + if (!empty($this->_params['groups']) && empty($this->_outputMode)) { + $this->_outputMode = 'group'; + } if (isset($this->_params['task'])) { unset($this->_params['task']); } - if ($this->_groupButtonName == $buttonName) { - $this->_outputMode = 'group'; - } } /** diff --git a/tests/phpunit/CRM/Report/Form/TestCaseTest.php b/tests/phpunit/CRM/Report/Form/TestCaseTest.php index 1e4e6da6dd..93d88f4757 100644 --- a/tests/phpunit/CRM/Report/Form/TestCaseTest.php +++ b/tests/phpunit/CRM/Report/Form/TestCaseTest.php @@ -180,4 +180,29 @@ class CRM_Report_Form_TestCaseTest extends CiviReportTestCase { $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray); } + /** + * Test processReportMode() Function in Reports + */ + public function testOutputMode() { + $clazz = new ReflectionClass('CRM_Report_Form'); + $reportForm = new CRM_Report_Form(); + + $params = $clazz->getProperty('_params'); + $params->setAccessible(TRUE); + $outputMode = $clazz->getProperty('_outputMode'); + $outputMode->setAccessible(TRUE); + + $params->setValue($reportForm, array('groups' => 4)); + $reportForm->processReportMode(); + $this->assertEquals('group', $outputMode->getValue($reportForm)); + + $params->setValue($reportForm, array('task' => 'copy')); + $reportForm->processReportMode(); + $this->assertEquals('copy', $outputMode->getValue($reportForm)); + + $params->setValue($reportForm, array('task' => 'print')); + $reportForm->processReportMode(); + $this->assertEquals('print', $outputMode->getValue($reportForm)); + } + }