Merge pull request #11967 from seamuslee001/dev_translation_9
[civicrm-core.git] / tests / phpunit / CiviTest / CiviReportTestCase.php
index 7e40d8ccf3b6f13251187c6ce6050e0d332e435f..9e7f93cf3db83e431e4ca36cbe8eeb3e4e52e17f 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -52,6 +52,28 @@ class CiviReportTestCase extends CiviUnitTestCase {
    * @throws Exception
    */
   public function getReportOutputAsCsv($reportClass, $inputParams) {
+
+    $reportObj = $this->getReportObject($reportClass, $inputParams);
+    try {
+      $rows = $reportObj->getResultSet();
+      $tmpFile = $this->createTempDir() . CRM_Utils_File::makeFileName('CiviReport.csv');
+      $csvContent = CRM_Report_Utils_Report::makeCsv($reportObj, $rows);
+      file_put_contents($tmpFile, $csvContent);
+    }
+    catch (Exception $e) {
+      throw $e;
+    }
+    return $tmpFile;
+  }
+
+  /**
+   * @param $reportClass
+   * @param array $inputParams
+   *
+   * @return array
+   * @throws Exception
+   */
+  public function getReportObject($reportClass, $inputParams) {
     $config = CRM_Core_Config::singleton();
     $config->keyDisable = TRUE;
     $controller = new CRM_Core_Controller_Simple($reportClass, ts('some title'));
@@ -83,11 +105,6 @@ class CiviReportTestCase extends CiviUnitTestCase {
     try {
       $reportObj->storeResultSet();
       $reportObj->buildForm();
-      $rows = $reportObj->getResultSet();
-
-      $tmpFile = $this->createTempDir() . CRM_Utils_File::makeFileName('CiviReport.csv');
-      $csvContent = CRM_Report_Utils_Report::makeCsv($reportObj, $rows);
-      file_put_contents($tmpFile, $csvContent);
     }
     catch (Exception $e) {
       // print_r($e->getCause()->getUserInfo());
@@ -96,7 +113,7 @@ class CiviReportTestCase extends CiviUnitTestCase {
     }
     CRM_Utils_GlobalStack::singleton()->pop();
 
-    return $tmpFile;
+    return $reportObj;
   }
 
   /**