Skip to content

Commit

Permalink
Merge pull request #14848 from eileenmcnaughton/test_fix
Browse files Browse the repository at this point in the history
[REF][TEST][EXPORT] minor test cleanup & minor cleanup of code it tests
  • Loading branch information
colemanw authored Jul 20, 2019
2 parents 3a1babb + ffd511e commit 6bc0781
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
6 changes: 2 additions & 4 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,10 +970,8 @@ public function buildRow($query, $iterationDAO, $outputColumns, $metadata, $paym
$fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders);
}
elseif (strstr($field, 'master_id')) {
$masterAddressId = NULL;
if (isset($iterationDAO->$field)) {
$masterAddressId = $iterationDAO->$field;
}
// @todo - why not just $field === 'master_id' - what else would it be?
$masterAddressId = $iterationDAO->$field ?? NULL;
// get display name of contact that address is shared.
$fieldValue = CRM_Contact_BAO_Contact::getMasterDisplayName($masterAddressId);
}
Expand Down
37 changes: 10 additions & 27 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,10 @@ public function testExportAddressData() {
}

/**
* Test master_address_id field.
* Test master_address_id field when no merge is in play.
*
* @throws \CRM_Core_Exception
* @throws \League\Csv\Exception
*/
public function testExportMasterAddress() {
$this->setUpContactExportData();
Expand All @@ -1047,32 +1050,12 @@ public function testExportMasterAddress() {
$selectedFields = [
['contact_type' => 'Individual', 'name' => 'master_id', 'location_type_id' => 1],
];
list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
TRUE,
[$this->contactIDs[1]],
[],
NULL,
$selectedFields,
NULL,
CRM_Export_Form_Select::CONTACT_EXPORT,
"contact_a.id IN ({$this->contactIDs[1]})",
NULL,
FALSE,
FALSE,
[
'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($this->masterAddressID);
$this->assertEquals($displayName, $masterName);

// delete the export temp table and component table
$sql = "DROP TABLE IF EXISTS {$tableName}";
CRM_Core_DAO::executeQuery($sql);
$this->doExportTest([
'fields' => $selectedFields,
'ids' => [$this->contactIDs[1]],
]);
$row = $this->csv->fetchOne();
$this->assertEquals(CRM_Contact_BAO_Contact::getMasterDisplayName($this->masterAddressID), $row['Home-Master Address Belongs To']);
}

/**
Expand Down

0 comments on commit 6bc0781

Please sign in to comment.