Skip to content
Snippets Groups Projects
Commit 12e2ccdc authored by eileenmcnaugton's avatar eileenmcnaugton
Browse files

#953 Fix failure to set new emails for existing contacts to primary on import

Add test for updating email via import & ensuring it is primary
parent 683b43cb
No related branches found
No related tags found
No related merge requests found
......@@ -344,8 +344,18 @@ class CRM_Core_BAO_Block {
}
$blockFields = array_merge($value, $contactFields);
$baoString = 'CRM_Core_BAO_' . $name;
$blocks[] = $baoString::add($blockFields);
if ($name === 'Email') {
// @todo ideally all would call the api which is our main tested function,
// and towards that call the create rather than add which is preferred by the
// api. In order to be careful with change only email is swapped over here because it
// is specifically tested in testImportParserWithUpdateWithContactID
// and the primary handling is otherwise bypassed on importing an email update.
$blocks[] = CRM_Core_BAO_Email::create($blockFields);
}
else {
$baoString = 'CRM_Core_BAO_' . $name;
$blocks[] = $baoString::add($blockFields);
}
}
return $blocks;
......
......@@ -162,10 +162,10 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
* @throws \Exception
*/
public function testImportParserWithUpdateWithExternalIdentifierButNoPrimaryMatch() {
list($originalValues, $result) = $this->setUpBaseContact(array(
list($originalValues, $result) = $this->setUpBaseContact([
'external_identifier' => 'windows',
'email' => NULL,
));
]);
$this->assertEquals('windows', $result['external_identifier']);
......@@ -177,6 +177,30 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
$this->callAPISuccessGetSingle('Contact', $originalValues);
}
/**
* Test import parser will fallback to external identifier.
*
* In this case no primary match exists (e.g the details are not supplied) so it falls back on external identifier.
*
* CRM-17275
*
* @throws \Exception
*/
public function testImportParserWithUpdateWithContactID() {
list($originalValues, $result) = $this->setUpBaseContact(array(
'external_identifier' => '',
'email' => NULL,
));
$updateValues = ['id' => $result['id'], 'email' => 'bill@example.com'];
// This is some deep weirdness - this sets a flag for updatingBlankLocinfo - allowing input to be blanked
// (which IS a good thing but it's pretty weird & all to do with legacy profile stuff).
CRM_Core_Session::singleton()->set('authSrc', CRM_Core_Permission::AUTH_SRC_CHECKSUM);
$this->runImport($updateValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [NULL, 1]);
$originalValues['id'] = $result['id'];
$this->callAPISuccessGetSingle('Email', ['contact_id' => $originalValues['id'], 'is_primary' => 1]);
$this->callAPISuccessGetSingle('Contact', $originalValues);
}
/**
* Test that the import parser adds the external identifier where none is set.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment