* @param array $exportParams
* @param string $queryOperator
*
+ * @return array|null
+ * An array can be requested from within a unit test.
+ *
+ * @throws \CRM_Core_Exception
*/
public static function exportComponents(
$selectAll,
}
}
- $contactType = CRM_Utils_Array::value(0, $value);
$locTypeId = CRM_Utils_Array::value(2, $value);
if ($relationField) {
}
elseif ($exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) {
$sourceID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Source');
- $query = "SELECT contact_id FROM civicrm_activity_contact
- WHERE activity_id IN ( " . implode(',', $ids) . ") AND
- record_type_id = {$sourceID}";
- $dao = CRM_Core_DAO::executeQuery($query);
+ $dao = CRM_Core_DAO::executeQuery("
+ SELECT contact_id FROM civicrm_activity_contact
+ WHERE activity_id IN ( " . implode(',', $ids) . ") AND
+ record_type_id = {$sourceID}
+ ");
+
while ($dao->fetch()) {
$relIDs[] = $dao->contact_id;
}
CRM_Utils_System::civiExit();
}
else {
- CRM_Core_Error::fatal(ts('No records to export'));
+ throw new CRM_Core_Exception(ts('No records to export'));
}
}
*
* @var array
*/
- protected $contactIDs = array();
+ protected $contactIDs = [];
/**
* Contribution IDs created for testing.
*
* @var array
*/
- protected $contributionIDs = array();
+ protected $contributionIDs = [];
+
+ /**
+ * Contribution IDs created for testing.
+ *
+ * @var array
+ */
+ protected $activityIDs = [];
/**
* Basic test to ensure the exportComponents function completes without error.
$sql = "DROP TABLE IF EXISTS {$tableName}";
CRM_Core_DAO::executeQuery($sql);
}
+
+ /**
+ * Basic test to ensure the exportComponents function can export selected fields for contribution.
+ */
+ public function testExportComponentsActivity() {
+ $this->setUpActivityExportData();
+ $selectedFields = array(
+ array('Individual', 'display_name'),
+ array('Individual', '5_a_b', 'display_name'),
+ );
+
+ list($tableName) = CRM_Export_BAO_Export::exportComponents(
+ FALSE,
+ $this->activityIDs,
+ array(),
+ '`activity_date_time` desc',
+ $selectedFields,
+ NULL,
+ CRM_Export_Form_Select::ACTIVITY_EXPORT,
+ 'civicrm_activity.id IN ( ' . implode(',', $this->activityIDs) . ')',
+ NULL,
+ FALSE,
+ FALSE,
+ array(
+ 'exportOption' => CRM_Export_Form_Select::ACTIVITY_EXPORT,
+ 'suppress_csv_for_testing' => TRUE,
+ )
+ );
+
+ // delete the export temp table and component table
+ $sql = "DROP TABLE IF EXISTS {$tableName}";
+ CRM_Core_DAO::executeQuery($sql);
+ }
+
/**
* Test the function that extracts the arrays used to structure the output.
*
$this->contributionIDs[] = $this->contributionCreate(array('contact_id' => $this->contactIDs[0]));
}
+ /**
+ * Set up some data for us to do testing on.
+ */
+ public function setUpActivityExportData() {
+ $this->setUpContactExportData();
+ $this->activityIDs[] = $this->activityCreate(array('contact_id' => $this->contactIDs[0]))['id'];
+ }
+
/**
* Set up some data for us to do testing on.
*/