From 639e4f3711710a1eca67195fe45f5d4755bd57c1 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 22 May 2022 14:14:24 +1200 Subject: [PATCH] Fix import to work with phone_ext, test This fixes a couple of bugs I found writing tests & adds test cover for website & phone imports + cleanup Notably - creating a phone with a phone_ext or an email with signature_text doesn't work prior to this --- CRM/Contact/BAO/Contact.php | 18 +- CRM/Contact/Import/Parser/Contact.php | 230 ++++-------------- CRM/Import/Parser.php | 30 ++- .../individual_locations_with_related.csv | 4 +- .../CRM/Contact/Import/Parser/ContactTest.php | 46 +++- 5 files changed, 107 insertions(+), 221 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 9165d43b15..cf3261c9ba 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -790,7 +790,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); ); } - $blocks = ['address', 'im', 'phone']; + $blocks = ['address']; foreach ($blocks as $name) { if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) { continue; @@ -825,22 +825,6 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); ); } - if ($name == 'im') { - CRM_Utils_Array::lookupValue($values, - 'provider', - CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), - $reverse - ); - } - - if ($name == 'phone') { - CRM_Utils_Array::lookupValue($values, - 'phone_type', - CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), - $reverse - ); - } - // Kill the reference. unset($values); } diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index a79a944744..2b65e44aea 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -101,6 +101,12 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { 'suffix_id', 'communication_style', 'preferred_language', + 'phone', + 'im', + 'openid', + 'email', + 'website', + 'url', ]; /** @@ -280,7 +286,12 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { } $params = $this->getMappedRow($values); - $formatted = array_filter(array_intersect_key($params, array_fill_keys($this->metadataHandledFields, 1)), 'strlen'); + $formatted = array_intersect_key($params, array_fill_keys($this->metadataHandledFields, 1)); + foreach ($formatted as $key => $value) { + if (!is_array($value) && !strlen($value)) { + unset($formatted[$key]); + } + } $contactFields = CRM_Contact_DAO_Contact::import(); @@ -397,9 +408,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { $relationType->find(TRUE); $direction = "contact_sub_type_$second"; - $formatting = [ - 'contact_type' => $params[$key]['contact_type'], - ]; + $formatting = array_filter(array_intersect_key($field, array_fill_keys($this->metadataHandledFields, 1))); //set subtype for related contact CRM-5125 if (isset($relationType->$direction)) { @@ -728,11 +737,23 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { } } } - + $metadataBlocks = ['phone', 'im', 'openid', 'email']; + foreach ($metadataBlocks as $block) { + foreach ($formatted[$block] ?? [] as $blockKey => $blockValues) { + if ($blockValues['location_type_id'] === 'Primary') { + $this->fillPrimary($formatted[$block][$blockKey], $blockValues, $block, $formatted['id'] ?? NULL); + } + } + } //now format custom data. foreach ($params as $key => $field) { + if (in_array($key, $metadataBlocks, TRUE)) { + // This location block is already fully handled at this point. + continue; + } if (is_array($field)) { $isAddressCustomField = FALSE; + foreach ($field as $value) { $break = FALSE; if (is_array($value)) { @@ -741,8 +762,8 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { $isAddressCustomField = TRUE; break; } - // check if $value does not contain IM provider or phoneType - if (($name !== 'phone_type_id' || $name !== 'provider_id') && ($testForEmpty === '' || $testForEmpty == NULL)) { + + if (($testForEmpty === '' || $testForEmpty == NULL)) { $break = TRUE; break; } @@ -1111,17 +1132,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { } break; - case 'url': - if (is_array($value)) { - foreach ($value as $values) { - if (!empty($values['url']) && !CRM_Utils_Rule::url($values['url'])) { - $errors[] = ts('Website'); - break; - } - } - } - break; - case 'do_not_email': case 'do_not_phone': case 'do_not_mail': @@ -1133,17 +1143,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { } break; - case 'email': - if (is_array($value)) { - foreach ($value as $values) { - if (!empty($values['email']) && !CRM_Utils_Rule::email($values['email'])) { - $errors[] = $key; - break; - } - } - } - break; - default: if (is_array($params[$key]) && isset($params[$key]["contact_type"])) { //check for any relationship data ,FIX ME @@ -1382,32 +1381,15 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { $billingLocationTypeId = CRM_Core_BAO_LocationType::getBilling(); - $blocks = ['email', 'phone', 'im', 'openid']; - $multiplFields = ['url']; - // prevent overwritten of formatted array, reset all block from - // params if it is not in valid format (since import pass valid format) - foreach ($blocks as $blk) { - if (array_key_exists($blk, $params) && - !is_array($params[$blk]) - ) { - unset($params[$blk]); - } - } - $primaryPhoneLoc = NULL; $session = CRM_Core_Session::singleton(); foreach ($params as $key => $value) { [$fieldName, $locTypeId, $typeId] = CRM_Utils_System::explode('-', $key, 3); if ($locTypeId == 'Primary') { if ($contactID) { - if (in_array($fieldName, $blocks)) { - $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactID, FALSE, $fieldName); - } - else { - $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactID, FALSE, 'address'); - } + $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactID, FALSE, 'address'); $primaryLocationType = $locTypeId; } else { @@ -1450,44 +1432,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { $data[$blockName][$loc]['is_primary'] = 1; } - if (in_array($fieldName, ['phone'])) { - if ($typeId) { - $data['phone'][$loc]['phone_type_id'] = $typeId; - } - else { - $data['phone'][$loc]['phone_type_id'] = ''; - } - $data['phone'][$loc]['phone'] = $value; - - //special case to handle primary phone with different phone types - // in this case we make first phone type as primary - if (isset($data['phone'][$loc]['is_primary']) && !$primaryPhoneLoc) { - $primaryPhoneLoc = $loc; - } - - if ($loc != $primaryPhoneLoc) { - unset($data['phone'][$loc]['is_primary']); - } - } - elseif ($fieldName == 'email') { - $data['email'][$loc]['email'] = $value; - if (empty($contactID)) { - $data['email'][$loc]['is_primary'] = 1; - } - } - elseif ($fieldName == 'im') { - if (isset($params[$key . '-provider_id'])) { - $data['im'][$loc]['provider_id'] = $params[$key . '-provider_id']; - } - if (strpos($key, '-provider_id') !== FALSE) { - $data['im'][$loc]['provider_id'] = $params[$key]; - } - else { - $data['im'][$loc]['name'] = $value; - } - } - elseif ($fieldName == 'openid') { - $data['openid'][$loc]['openid'] = $value; + if (0) { } else { if ($fieldName === 'state_province') { @@ -1520,12 +1465,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { } } else { - if (substr($key, 0, 4) === 'url-') { - $websiteField = explode('-', $key); - $data['website'][$websiteField[1]]['website_type_id'] = $websiteField[1]; - $data['website'][$websiteField[1]]['url'] = $value; - } - elseif (in_array($key, CRM_Contact_BAO_Contact::$_greetingTypes, TRUE)) { + if (in_array($key, CRM_Contact_BAO_Contact::$_greetingTypes, TRUE)) { //save email/postal greeting and addressee values if any, CRM-4575 $data[$key . '_id'] = $value; } @@ -1583,15 +1523,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { } } } - if ($key === 'phone' && isset($params['phone_ext'])) { - $data[$key] = $value; - foreach ($value as $cnt => $phoneBlock) { - if ($params[$key][$cnt]['location_type_id'] == $params['phone_ext'][$cnt]['location_type_id']) { - $data[$key][$cnt]['phone_ext'] = CRM_Utils_Array::retrieveValueRecursive($params['phone_ext'][$cnt], 'phone_ext'); - } - } - } - elseif (in_array($key, ['nick_name', 'job_title', 'middle_name', 'birth_date', 'gender_id', 'current_employer', 'prefix_id', 'suffix_id']) + if (in_array($key, ['nick_name', 'job_title', 'middle_name', 'birth_date', 'gender_id', 'current_employer', 'prefix_id', 'suffix_id']) && ($value == '' || !isset($value)) && ($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0 || ($key === 'current_employer' && empty($params['current_employer']))) { @@ -1658,10 +1590,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults, FALSE, FALSE); $locationFields = [ - 'email' => 'email', - 'phone' => 'phone', - 'im' => 'name', - 'website' => 'website', 'address' => 'address', ]; @@ -1711,15 +1639,8 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { if (isset($getValue)) { foreach ($getValue as $cnt => $values) { - if ($locKeys == 'website') { - if (($getValue[$cnt]['website_type_id'] == $params[$locKeys][$key]['website_type_id'])) { - unset($params[$locKeys][$key]); - } - } - else { - if ((!empty($getValue[$cnt]['location_type_id']) && !empty($params[$locKeys][$key]['location_type_id'])) && $getValue[$cnt]['location_type_id'] == $params[$locKeys][$key]['location_type_id']) { - unset($params[$locKeys][$key]); - } + if ((!empty($getValue[$cnt]['location_type_id']) && !empty($params[$locKeys][$key]['location_type_id'])) && $getValue[$cnt]['location_type_id'] == $params[$locKeys][$key]['location_type_id']) { + unset($params[$locKeys][$key]); } } } @@ -2244,7 +2165,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { // Location // Address // Email - // Phone // IM // Note // Custom @@ -2341,26 +2261,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { return TRUE; } - // format the website params. - if (!empty($values['url'])) { - static $websiteFields; - if (!is_array($websiteFields)) { - $websiteFields = CRM_Core_DAO_Website::fields(); - } - if (!array_key_exists('website', $params) || - !is_array($params['website']) - ) { - $params['website'] = []; - } - - $websiteCount = count($params['website']); - _civicrm_api3_store_values($websiteFields, $values, - $params['website'][++$websiteCount] - ); - - return TRUE; - } - if (isset($values['note'])) { // add a note field if (!isset($params['note'])) { @@ -2409,53 +2309,16 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { /** * Format location block ready for importing. * - * There is some test coverage for this in CRM_Contact_Import_Parser_ContactTest - * e.g. testImportPrimaryAddress. + * There is some test coverage for this in + * CRM_Contact_Import_Parser_ContactTest e.g. testImportPrimaryAddress. * * @param array $values * @param array $params * * @return bool + * @throws \CiviCRM_API3_Exception */ protected function formatLocationBlock(&$values, &$params) { - $blockTypes = [ - 'phone' => 'Phone', - 'email' => 'Email', - 'im' => 'IM', - 'openid' => 'OpenID', - 'phone_ext' => 'Phone', - ]; - foreach ($blockTypes as $blockFieldName => $block) { - if (!array_key_exists($blockFieldName, $values)) { - continue; - } - $blockIndex = $values['location_type_id'] . (!empty($values['phone_type_id']) ? '_' . $values['phone_type_id'] : ''); - - // block present in value array. - if (!array_key_exists($blockFieldName, $params) || !is_array($params[$blockFieldName])) { - $params[$blockFieldName] = []; - } - - $fields[$block] = $this->getMetadataForEntity($block); - - // copy value to dao field name. - if ($blockFieldName == 'im') { - $values['name'] = $values[$blockFieldName]; - } - - _civicrm_api3_store_values($fields[$block], $values, - $params[$blockFieldName][$blockIndex] - ); - - $this->fillPrimary($params[$blockFieldName][$blockIndex], $values, $block, CRM_Utils_Array::value('id', $params)); - - if (empty($params['id']) && (count($params[$blockFieldName]) == 1)) { - $params[$blockFieldName][$blockIndex]['is_primary'] = TRUE; - } - - // we only process single block at a time. - return TRUE; - } // handle address fields. if (!array_key_exists('address', $params) || !is_array($params['address'])) { @@ -2605,9 +2468,11 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { $fieldName = $isRelationshipField ? $fieldMapping[1] : $fieldMapping[0]; $locationTypeID = NULL; $possibleLocationField = $isRelationshipField ? 2 : 1; - if ($fieldName !== 'url' && is_numeric($fieldMapping[$possibleLocationField] ?? NULL)) { + $entity = strtolower($this->getFieldEntity($fieldName)); + if ($entity !== 'website' && is_numeric($fieldMapping[$possibleLocationField] ?? NULL)) { $locationTypeID = $fieldMapping[$possibleLocationField]; } + return [ 'name' => $fieldName, 'mapping_id' => $mappingID, @@ -2615,9 +2480,9 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { 'relationship_direction' => $isRelationshipField ? substr($fieldMapping[0], -3) : NULL, 'column_number' => $columnNumber, 'contact_type' => $this->getContactType(), - 'website_type_id' => $fieldName !== 'url' ? NULL : ($isRelationshipField ? $fieldMapping[2] : $fieldMapping[1]), - 'phone_type_id' => $fieldName !== 'phone' ? NULL : ($isRelationshipField ? $fieldMapping[3] : $fieldMapping[2]), - 'im_provider_id' => $fieldName !== 'im' ? NULL : ($isRelationshipField ? $fieldMapping[3] : $fieldMapping[2]), + 'website_type_id' => $entity !== 'website' ? NULL : ($isRelationshipField ? $fieldMapping[2] : $fieldMapping[1]), + 'phone_type_id' => $entity !== 'phone' ? NULL : ($isRelationshipField ? $fieldMapping[3] : $fieldMapping[2]), + 'im_provider_id' => $entity !== 'im' ? NULL : ($isRelationshipField ? $fieldMapping[3] : $fieldMapping[2]), 'location_type_id' => $locationTypeID, ]; } @@ -2869,6 +2734,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { $fieldMap = ['country' => 'country_id']; $realFieldName = empty($fieldMap[$fieldName]) ? $fieldName : $fieldMap[$fieldName]; $entity = strtolower($this->getFieldEntity($fieldName)); + // The entity key is either location_type_id for address, email - eg. 1, or // location_type_id + '_' + phone_type_id or im_provider_id // or the value for website(since websites are not historically one-per-type) @@ -2877,7 +2743,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { $entityKey .= '_' . ($locationValues['phone_type_id'] ?? '' . $locationValues['provider_id'] ?? ''); } $fieldValue = $this->getTransformedFieldValue($realFieldName, $importedValue); - $availableCountries = $this->getAvailableCountries(); + if (!empty($fieldValue) && $realFieldName === 'country_id') { if ($this->getAvailableCountries() && empty($this->getAvailableCountries()[$fieldValue])) { // We restrict to allowed countries for address fields - but not custom country fields. @@ -2889,7 +2755,11 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { if (!isset($contactArray[$entity][$entityKey])) { $contactArray[$entity][$entityKey] = $locationValues; } - if (!isset($locationValues[$fieldName])) { + // Honestly I'll explain in comment_final_version(revision_2)_use_this_one... + $reallyRealFieldName = $fieldName === 'im' ? 'name' : $fieldName; + $contactArray[$entity][$entityKey][$reallyRealFieldName] = $fieldValue; + + if (!isset($locationValues[$fieldName]) && $entity === 'address') { // These lines add the values to params 'the old way' // The old way is then re-formatted by formatCommonData more // or less as per below. diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php index 6d8e6e3958..1db73e1df3 100644 --- a/CRM/Import/Parser.php +++ b/CRM/Import/Parser.php @@ -1223,6 +1223,14 @@ abstract class CRM_Import_Parser { return $importedValue; } $fieldMetadata = $this->getFieldMetadata($fieldName); + if ($fieldName === 'url') { + return CRM_Utils_Rule::url($importedValue) ? $importedValue : 'invalid_import_value'; + } + + if ($fieldName === 'email') { + return CRM_Utils_Rule::email($importedValue) ? $importedValue : 'invalid_import_value'; + } + if ($fieldMetadata['type'] === CRM_Utils_Type::T_BOOLEAN) { $value = CRM_Utils_String::strtoboolstr($importedValue); if ($value !== FALSE) { @@ -1280,16 +1288,20 @@ abstract class CRM_Import_Parser { 'where' => [['name', '=', empty($fieldMap[$fieldName]) ? $fieldMetadata['name'] : $fieldName]], 'select' => ['options'], ])->first()['options']; - // We create an array of the possible variants - notably including - // name AND label as either might be used. We also lower case before checking - $values = []; - foreach ($options as $option) { - $values[$option['id']] = $option['id']; - $values[mb_strtolower($option['name'])] = $option['id']; - $values[mb_strtolower($option['label'])] = $option['id']; + if (is_array($options)) { + // We create an array of the possible variants - notably including + // name AND label as either might be used. We also lower case before checking + $values = []; + foreach ($options as $option) { + $values[$option['id']] = $option['id']; + $values[mb_strtolower($option['name'])] = $option['id']; + $values[mb_strtolower($option['label'])] = $option['id']; + } + $this->importableFieldsMetadata[$fieldMapName]['options'] = $values; + } + else { + $this->importableFieldsMetadata[$fieldMapName]['options'] = $options; } - - $this->importableFieldsMetadata[$fieldMapName]['options'] = $values; return $this->importableFieldsMetadata[$fieldMapName]; } return $fieldMetadata; diff --git a/tests/phpunit/CRM/Contact/Import/Form/data/individual_locations_with_related.csv b/tests/phpunit/CRM/Contact/Import/Form/data/individual_locations_with_related.csv index e5dd31fcdb..783f25a293 100644 --- a/tests/phpunit/CRM/Contact/Import/Form/data/individual_locations_with_related.csv +++ b/tests/phpunit/CRM/Contact/Import/Form/data/individual_locations_with_related.csv @@ -1,2 +1,2 @@ -First Name,Last Name,Birth Date,Street Address,City,Postal Code,Country,State,Email,Signature Text,IM,Website,Phone,Phone Ext,Mum’s first name,Last Name,Mum-Street Address,Mum-City,Mum-Country,Mum-State,Mum-email,Mum-signature Test,Mum-IM,Mum-website,Mum-phone,Mum-phone-ext,Mum-home-phone,Mum-home-mobile,Sister-Street Address,Sister-City,Sister-Country,Sister-State,Sister-email,Sister-signature Test,Sister-IM,Sister-website,Sister-phone,Sister-phone-ext,Team,Team Website,Team email ,Team Reference,Team Address1,Team Address 2,Team address Validity Date,Team Backup Website -Susie,Jones,2002-01-08,24 Adelaide Road,Sydney,90210,Australia,NSW,susie@example.com,Regards,susiej,https://susie.example.com,999-4445,123,Mum,Jones,The Green House,,,,mum@example.com,,Mum-IM,http://mum.example.com,911,1,88-999,99-888,,,New Zealand,,sis@example.com,,,,555-666,,Soccer Superstars,https://super.example.org,tt@example.org,T-882,PO Box 999,Marion Square,2022-03-04,http://super-t.example.org +First Name,Last Name,Birth Date,Street Address,City,Postal Code,Country,State,Email,Signature Text,IM,Website,Phone,Phone Ext,Mum’s first name,Last Name,Mum-Street Address,Mum-City,Mum-Country,Mum-State,Mum-email,Mum-signature Test,Mum-IM,Mum-website,Mum-phone,Mum-phone-ext,Mum-home-phone,Mum-home-mobile,Sister-Street Address,Sister-City,Sister-Country,Sister-State,Sister-email,Sister-signature Test,Sister-IM,Sister-website,Sister-phone,Sister-phone-ext,Team,Team Website,Team email ,Team Reference,Team Address1,Team Address 2,Team address Validity Date,Team Backup Website,Team open +Susie,Jones,2002-01-08,24 Adelaide Road,Sydney,90210,Australia,NSW,susie@example.com,Regards,susiej,https://susie.example.com,999-4445,123,Mum,Jones,The Green House,,,,mum@example.com,,Mum-IM,http://mum.example.com,911,1,88-999,99-888,,,New Zealand,,sis@example.com,,,,555-666,,Soccer Superstars,https://super.example.org,tt@example.org,T-882,PO Box 999,Marion Square,2022-03-04,http://super-t.example.org,team-id diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 130f04df47..ba8e4dbe19 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -53,7 +53,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * Tear down after test. */ public function tearDown(): void { - $this->quickCleanup(['civicrm_address', 'civicrm_phone', 'civicrm_email', 'civicrm_user_job', 'civicrm_relationship'], TRUE); + $this->quickCleanup(['civicrm_address', 'civicrm_phone', 'civicrm_openid', 'civicrm_email', 'civicrm_user_job', 'civicrm_relationship', 'civicrm_im', 'civicrm_website'], TRUE); RelationshipType::delete()->addWhere('name_a_b', '=', 'Dad to')->execute(); ContactType::delete()->addWhere('name', '=', 'baby')->execute(); parent::tearDown(); @@ -952,12 +952,12 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { 'individual_bad_email' => [ 'csv' => 'individual_invalid_email.csv', 'mapper' => [['email', 1], ['first_name'], ['last_name']], - 'expected_error' => 'Invalid value for field(s) : email', + 'expected_error' => 'Invalid value for field(s) : Email', ], 'individual_related_bad_email' => [ 'csv' => 'individual_invalid_related_email.csv', 'mapper' => [['1_a_b', 'email', 1], ['first_name'], ['last_name']], - 'expected_error' => 'Invalid value for field(s) : email', + 'expected_error' => 'Invalid value for field(s) : (Child of) Email', ], 'individual_invalid_external_identifier_only' => [ // External identifier is only enough in upgrade mode. @@ -1216,7 +1216,6 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { /** * Test location importing, including for related contacts. * - * @throws \CRM_Core_Exception * @throws \API_Exception */ public function testImportLocations(): void { @@ -1271,7 +1270,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { [$siblingKey, 'state_province', $homeID], [$siblingKey, 'email', $homeID], [$siblingKey, 'signature_text', $homeID], - [$childKey, 'im', $homeID, $skypeTypeID], + [$siblingKey, 'im', $homeID, $skypeTypeID], // The 2 is website_type_id (yes, small hard-coding cheat) [$siblingKey, 'url', $linkedInTypeID], [$siblingKey, 'phone', $workID, $phoneTypeID], @@ -1285,8 +1284,36 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { [$employeeKey, 'do_not_import'], // Second website, different type. [$employeeKey, 'url', $linkedInTypeID], + ['openid'], ]; $this->validateCSV($csv, $mapper); + + $this->importCSV($csv, $mapper); + $contacts = $this->getImportedContacts(); + $this->assertCount(4, $contacts); + $this->assertCount(1, $contacts['Susie Jones']['phone']); + $this->assertEquals('123', $contacts['Susie Jones']['phone'][0]['phone_ext']); + $this->assertCount(2, $contacts['Mum Jones']['phone']); + $this->assertCount(1, $contacts['sis@example.com']['phone']); + $this->assertCount(0, $contacts['Soccer Superstars']['phone']); + $this->assertCount(1, $contacts['Susie Jones']['website']); + $this->assertCount(1, $contacts['Mum Jones']['website']); + $this->assertCount(0, $contacts['sis@example.com']['website']); + $this->assertCount(2, $contacts['Soccer Superstars']['website']); + $this->assertCount(1, $contacts['Susie Jones']['email']); + $this->assertEquals('Regards', $contacts['Susie Jones']['email'][0]['signature_text']); + $this->assertCount(1, $contacts['Mum Jones']['email']); + $this->assertCount(1, $contacts['sis@example.com']['email']); + $this->assertCount(1, $contacts['Soccer Superstars']['email']); + $this->assertCount(1, $contacts['Susie Jones']['im']); + $this->assertCount(1, $contacts['Mum Jones']['im']); + $this->assertCount(0, $contacts['sis@example.com']['im']); + $this->assertCount(0, $contacts['Soccer Superstars']['im']); + $this->assertCount(1, $contacts['Susie Jones']['address']); + $this->assertCount(1, $contacts['Mum Jones']['address']); + $this->assertCount(1, $contacts['sis@example.com']['address']); + $this->assertCount(1, $contacts['Soccer Superstars']['address']); + $this->assertCount(1, $contacts['Susie Jones']['openid']); } /** @@ -1659,13 +1686,6 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { 'website_type_id' => 1, ], ], - // We still pump out the legacy key too - for now! - 'url' => [ - 'https://example.org' => [ - 'url' => 'https://example.org', - 'website_type_id' => 1, - ], - ], 'phone' => [ '1_1' => [ 'phone' => '456', @@ -1676,7 +1696,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { ], 'im' => [ '1_1' => [ - 'im' => 'my-handle', + 'name' => 'my-handle', 'location_type_id' => 1, 'provider_id' => 1, ], -- 2.25.1