Merge pull request #1270 from ravishnair/CRM-13037
[civicrm-core.git] / tests / phpunit / CiviTest / CiviReportTestCase.php
CommitLineData
ae555e90
DS
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26*/
27
28require_once 'CiviTest/CiviUnitTestCase.php';
29
30class CiviReportTestCase extends CiviUnitTestCase {
31 function setUp() {
32 parent::setUp();
33 }
34
35 function getReportOutputAsCsv($reportClass, $inputParams) {
36 $config = CRM_Core_Config::singleton();
37 $config->keyDisable = TRUE;
38 $controller = new CRM_Core_Controller_Simple($reportClass, ts('some title'));
39 $reportObj =& $controller->_pages['Detail'];//FIXME - Detail is going to change
40 $_REQUEST['force'] = 1;
41 if (!empty($inputParams['fields'])) {
42 $fields = implode(',', $inputParams['fields']);
43 $_GET['fld'] = $fields;
44 $_GET['ufld'] = 1;
45 }
ec24e302
DS
46 if (!empty($inputParams['filters'])) {
47 foreach ($inputParams['filters'] as $key => $val) {
48 $_GET[$key] = $val;
49 }
50 }
ae555e90
DS
51 $reportObj->storeResultSet();
52 $reportObj->buildForm();
53 $rows = $reportObj->getResultSet();
54
55 $tmpFile = $this->createTempDir() . CRM_Utils_File::makeFileName('CiviReport.csv');
56 $csvContent = CRM_Report_Utils_Report::makeCsv($reportObj, $rows);
57 file_put_contents($tmpFile, $csvContent);
58
59 return $tmpFile;
60 }
61
62 function getArrayFromCsv($csvFile) {
63 $arrFile = array();
64 if (($handle = fopen($csvFile, "r")) !== FALSE) {
65 while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
66 $arrFile[] = $data;
67 }
68 fclose($handle);
69 }
70 return $arrFile;
71 }
ae555e90 72}