From 373c66cf93f69e7245cdc5b2eb21e9a92e5cb1c0 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Fri, 10 May 2019 20:08:26 +1200 Subject: [PATCH] Add test for updating email via import & ensuring it is primary --- .../CRM/Contact/Import/Parser/ContactTest.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 2ab4aaf85cb3..f5776183db4e 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -162,10 +162,10 @@ public function testImportParserWithUpdateWithExternalIdentifier() { * @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,28 @@ public function testImportParserWithUpdateWithExternalIdentifierButNoPrimaryMatc $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->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. *