Add test and minor fixes
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Fri, 15 Jul 2016 11:06:07 +0000 (16:36 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Fri, 15 Jul 2016 11:10:15 +0000 (16:40 +0530)
CRM/Report/Form.php
tests/phpunit/CRM/Report/Form/TestCaseTest.php

index 82d7c1b4068c8a2b263b5b495c7f31414b1c31c4..9529e6d9eb68d7ae03f971ba4e7c986cdc113859 100644 (file)
@@ -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';
-    }
   }
 
   /**
index 1e4e6da6dde35feb511c64709628d4bf15578ff6..93d88f4757e3d4200d245329353f0525860b6f01 100644 (file)
@@ -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));
+  }
+
 }