3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
30 class CiviReportTestCase
extends CiviUnitTestCase
{
39 function getReportOutputAsCsv($reportClass, $inputParams) {
40 $config = CRM_Core_Config
::singleton();
41 $config->keyDisable
= TRUE;
42 $controller = new CRM_Core_Controller_Simple($reportClass, ts('some title'));
43 $reportObj =& $controller->_pages
['Detail'];//FIXME - Detail is going to change
45 $tmpGlobals = array();
46 $tmpGlobals['_REQUEST']['force'] = 1;
47 $tmpGlobals['_GET'][$config->userFrameworkURLVar
] = 'civicrm/placeholder';
48 $tmpGlobals['_SERVER']['QUERY_STRING'] = '';
49 if (!empty($inputParams['fields'])) {
50 $fields = implode(',', $inputParams['fields']);
51 $tmpGlobals['_GET']['fld'] = $fields;
52 $tmpGlobals['_GET']['ufld'] = 1;
54 if (!empty($inputParams['filters'])) {
55 foreach ($inputParams['filters'] as $key => $val) {
56 $tmpGlobals['_GET'][$key] = $val;
59 CRM_Utils_GlobalStack
::singleton()->push($tmpGlobals);
62 $reportObj->storeResultSet();
63 $reportObj->buildForm();
64 $rows = $reportObj->getResultSet();
66 $tmpFile = $this->createTempDir() . CRM_Utils_File
::makeFileName('CiviReport.csv');
67 $csvContent = CRM_Report_Utils_Report
::makeCsv($reportObj, $rows);
68 file_put_contents($tmpFile, $csvContent);
69 } catch (Exception
$e) {
70 CRM_Utils_GlobalStack
::singleton()->pop();
73 CRM_Utils_GlobalStack
::singleton()->pop();
78 function getArrayFromCsv($csvFile) {
80 if (($handle = fopen($csvFile, "r")) !== FALSE) {
81 while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
90 * @param array $expectedCsvArray two-dimensional array representing a CSV table
91 * @param array $actualCsvArray two-dimensional array representing a CSV table
93 public function assertCsvArraysEqual($expectedCsvArray, $actualCsvArray) {
94 // TODO provide better debug output
97 count($actualCsvArray),
98 count($expectedCsvArray),
99 'Arrays have different number of rows; in line ' . __LINE__
102 foreach ($actualCsvArray as $intKey => $strVal) {
103 $this->assertNotNull($expectedCsvArray[$intKey], 'In line ' . __LINE__
);
105 count($actualCsvArray[$intKey]),
106 count($expectedCsvArray[$intKey]),
107 'Arrays have different number of columns at row ' . $intKey . '; in line ' . __LINE__
109 $this->assertEquals($expectedCsvArray[$intKey], $strVal);