From ef51caa8a1e31f969d238f511390011a93a0dec4 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 5 Jan 2016 14:10:30 +1300 Subject: [PATCH] Add export test Change-Id: Ide9668a25394fc4ef10efc63925133d89e309c13 --- CRM/Export/BAO/Export.php | 14 +++++++--- tests/phpunit/CRM/Export/BAO/ExportTest.php | 31 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 tests/phpunit/CRM/Export/BAO/ExportTest.php diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index e767e8f1ff..5aeff00104 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -301,6 +301,7 @@ class CRM_Export_BAO_Export { $exportParams = array(), $queryOperator = 'AND' ) { + $headerRows = $returnProperties = array(); $primary = $paymentFields = $selectedPaymentFields = FALSE; $origFields = $fields; @@ -1258,14 +1259,19 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c // call export hook CRM_Utils_Hook::export($exportTempTable, $headerRows, $sqlColumns, $exportMode); - // now write the CSV file - self::writeCSVFromTable($exportTempTable, $headerRows, $sqlColumns, $exportMode); + // In order to be able to write a unit test against this function we need to suppress + // the csv writing. In future hopefully the csv writing & the main processing will be in separate functions. + if (empty($exportParams['suppress_csv_for_testing'])) { + self::writeCSVFromTable($exportTempTable, $headerRows, $sqlColumns, $exportMode); + } // delete the export temp table and component table $sql = "DROP TABLE IF EXISTS {$exportTempTable}"; CRM_Core_DAO::executeQuery($sql); - - CRM_Utils_System::civiExit(); + // Do not exit in test context. + if (empty($exportParams['suppress_csv_for_testing'])) { + CRM_Utils_System::civiExit(); + } } else { CRM_Core_Error::fatal(ts('No records to export')); diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php new file mode 100644 index 0000000000..af08969160 --- /dev/null +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -0,0 +1,31 @@ + 1, + 'suppress_csv_for_testing' => TRUE, + ) + ); + } +} -- 2.25.1