$exportParams = array(),
$queryOperator = 'AND'
) {
+
$headerRows = $returnProperties = array();
$primary = $paymentFields = $selectedPaymentFields = FALSE;
$origFields = $fields;
// 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'));
--- /dev/null
+<?php
+require_once 'CiviTest/CiviUnitTestCase.php';
+
+/**
+ * Class CRM_Core_DAOTest
+ */
+class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
+
+ /**
+ * Basic test to ensure the exportComponents function completes without error.
+ */
+ function testExportComponentsNull() {
+ CRM_Export_BAO_Export::exportComponents(
+ TRUE,
+ array(),
+ array(),
+ NULL,
+ NULL,
+ NULL,
+ CRM_Export_Form_Select::CONTACT_EXPORT,
+ NULL,
+ NULL,
+ FALSE,
+ FALSE,
+ array(
+ 'exportOption' => 1,
+ 'suppress_csv_for_testing' => TRUE,
+ )
+ );
+ }
+}