From 1576627e133b3f59ec59a541823a59762f1badff Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 24 May 2022 17:27:38 +1200 Subject: [PATCH] Additional test --- .../CRM/Contact/Import/Parser/ContactTest.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 57ce710904..2a46d0f0f3 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -1602,6 +1602,60 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { ], $params); } + /** + * Test that import parser will not match the imported primary to + * an existing contact via the related contacts fields. + * + * Currently fails because CRM_Dedupe_Finder::formatParams($input, $contactType); + * called in getDuplicateContacts flattens the contact array adding the + * related contacts values to the primary contact. + * + * https://github.com/civicrm/civicrm-core/blob/ca13ec46eae2042604e4e106c6cb3dc0439db3e2/CRM/Dedupe/Finder.php#L238 + * + * @throws \API_Exception + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + * @throws \Civi\API\Exception\UnauthorizedException + */ + public function testImportParserDoesNotMatchPrimaryToRelated(): void { + $this->individualCreate([ + 'first_name' => 'Bob', + 'last_name' => 'Dobbs', + 'email' => 'tim.cook@apple.com', + ]); + + $contactImportValues = [ + 'first_name' => 'Alok', + 'last_name' => 'Patel', + 'Employee of' => 'email', + ]; + + $mapper = [ + ['first_name'], + ['last_name'], + ['5_a_b', 'email'], + ]; + $fields = array_keys($contactImportValues); + $values = array_values($contactImportValues); + $values[] = 'tim.cook@apple.com'; + + $userJobID = $this->getUserJobID([ + 'mapper' => $mapper, + 'onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE, + ]); + + $parser = new CRM_Contact_Import_Parser_Contact($fields); + $parser->setUserJobID($userJobID); + $parser->init(); + + $this->assertEquals(CRM_Import_Parser::ERROR, $parser->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), 'Return code from parser import was not as expected'); + $this->callAPISuccessGetSingle('Contact', [ + 'first_name' => 'Bob', + 'last_name' => 'Dobbs', + 'email' => 'tim.cook@apple.com', + ]); + } + /** * Set up the underlying contact. * -- 2.25.1