elseif ($field == 'provider_id' || $field == 'im_provider') {
$fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders);
}
- elseif ($field == 'master_id') {
+ elseif (strstr($field, 'master_id')) {
$masterAddressId = NULL;
- if (isset($iterationDAO->master_id)) {
- $masterAddressId = $iterationDAO->master_id;
+ if (isset($iterationDAO->$field)) {
+ $masterAddressId = $iterationDAO->$field;
}
// get display name of contact that address is shared.
$fieldValue = CRM_Contact_BAO_Contact::getMasterDisplayName($masterAddressId, $iterationDAO->contact_id);
if (empty($exportParams['suppress_csv_for_testing'])) {
self::writeCSVFromTable($exportTempTable, $headerRows, $sqlColumns, $exportMode);
}
+ else {
+ // return tableName and sqlColumns in test context
+ return array($exportTempTable, $sqlColumns);
+ }
// delete the export temp table and component table
$sql = "DROP TABLE IF EXISTS {$exportTempTable}";
CRM_Core_DAO::executeQuery($sql);
- // Do not exit in test context.
- if (empty($exportParams['suppress_csv_for_testing'])) {
- CRM_Utils_System::civiExit();
- }
+
+ CRM_Utils_System::civiExit();
}
else {
CRM_Core_Error::fatal(ts('No records to export'));
* Basic test to ensure the exportComponents function completes without error.
*/
public function testExportComponentsNull() {
- CRM_Export_BAO_Export::exportComponents(
+ list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
TRUE,
array(),
array(),
'suppress_csv_for_testing' => TRUE,
)
);
+
+ // delete the export temp table and component table
+ $sql = "DROP TABLE IF EXISTS {$tableName}";
+ CRM_Core_DAO::executeQuery($sql);
}
/**
array('Individual', 'email', 1),
array('Contribution', 'trxn_id'),
);
- CRM_Export_BAO_Export::exportComponents(
+
+ list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
TRUE,
$this->contributionIDs,
array(),
'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->contactIDs[] = $this->individualCreate();
}
+ public function testExportMasterAddress() {
+ $contactA = $this->individualCreate(array(), 0);
+ $contactB = $this->individualCreate(array(), 1);
+
+ //create address for contact A
+ $params = array(
+ 'contact_id' => $contactA,
+ 'location_type_id' => 'Home',
+ 'street_address' => 'Ambachtstraat 23',
+ 'postal_code' => '6971 BN',
+ 'country_id' => '1152',
+ 'city' => 'Brummen',
+ 'is_primary' => 1,
+ );
+ $result = $this->callAPISuccess('address', 'create', $params);
+ $addressId = $result['id'];
+
+ //share address with contact B
+ $result = $this->callAPISuccess('address', 'create', array(
+ 'contact_id' => $contactB,
+ 'location_type_id' => "Home",
+ 'master_id' => $addressId,
+ ));
+
+ //export the master address for contact B
+ $selectedFields = array(
+ array('Individual', 'master_id', 1),
+ );
+ list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
+ TRUE,
+ array($contactB),
+ array(),
+ NULL,
+ $selectedFields,
+ NULL,
+ CRM_Export_Form_Select::CONTACT_EXPORT,
+ "contact_a.id IN ({$contactB})",
+ NULL,
+ FALSE,
+ FALSE,
+ array(
+ 'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT,
+ 'suppress_csv_for_testing' => TRUE,
+ )
+ );
+ $field = key($sqlColumns);
+
+ //assert the exported result
+ $masterName = CRM_Core_DAO::singleValueQuery("SELECT {$field} FROM {$tableName}");
+ $displayName = CRM_Contact_BAO_Contact::getMasterDisplayName(NULL, $contactB);
+ $this->assertEquals($displayName, $masterName);
+
+ // delete the export temp table and component table
+ $sql = "DROP TABLE IF EXISTS {$tableName}";
+ CRM_Core_DAO::executeQuery($sql);
+ }
+
}