Merge pull request #1458 from colemanw/contactTypeSearch
[civicrm-core.git] / tests / phpunit / CiviTest / CiviReportTestCase.php
index 5ae55cec147ff83fc0f4f6380f75834dbe77dcf4..f43dc77ab87cc0a95f90aa98fdbf664e409fc416 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -34,6 +34,10 @@ class CiviReportTestCase extends CiviUnitTestCase {
   }
 
   function tearDown() {
+    // TODO Figure out how to automatically drop all temporary tables.
+    // Note that MySQL doesn't provide a way to list them, so we would need
+    // to keep track ourselves (eg CRM_Core_TemporaryTableManager) or reset
+    // the MySQL connection between test runs.
     parent::tearDown();
   }
 
@@ -41,7 +45,9 @@ class CiviReportTestCase extends CiviUnitTestCase {
     $config = CRM_Core_Config::singleton();
     $config->keyDisable = TRUE;
     $controller = new CRM_Core_Controller_Simple($reportClass, ts('some title'));
-    $reportObj =& $controller->_pages['Detail']; //FIXME - Detail is going to change
+    $tmpReportVal = explode('_', $reportClass);
+    $reportName = array_pop($tmpReportVal);
+    $reportObj =& $controller->_pages[$reportName];
 
     $tmpGlobals = array();
     $tmpGlobals['_REQUEST']['force'] = 1;
@@ -57,6 +63,11 @@ class CiviReportTestCase extends CiviUnitTestCase {
         $tmpGlobals['_GET'][$key] = $val;
       }
     }
+    if (!empty($inputParams['group_bys'])) {
+      $groupByFields = implode(' ', $inputParams['group_bys']);
+      $tmpGlobals['_GET']['gby'] = $groupByFields;
+    }
+
     CRM_Utils_GlobalStack::singleton()->push($tmpGlobals);
 
     try {
@@ -68,6 +79,7 @@ class CiviReportTestCase extends CiviUnitTestCase {
       $csvContent = CRM_Report_Utils_Report::makeCsv($reportObj, $rows);
       file_put_contents($tmpFile, $csvContent);
     } catch (Exception $e) {
+      // print_r($e->getCause()->getUserInfo());
       CRM_Utils_GlobalStack::singleton()->pop();
       throw $e;
     }