return $importedValue;
}
- $comparisonValue = is_numeric($importedValue) ? $importedValue : mb_strtolower($importedValue);
+ $comparisonValue = $this->getComparisonValue($importedValue);
return $options[$comparisonValue] ?? 'invalid_import_value';
}
if (!empty($fieldMetadata['FKClassName']) || !empty($fieldMetadata['pseudoconstant']['prefetch'])) {
// name AND label as either might be used. We also lower case before checking
$values = [];
foreach ($options as $option) {
- $idKey = is_numeric($option['id']) ? $option['id'] : mb_strtolower($option['id']);
+ $idKey = $this->getComparisonValue($option['id']);
$values[$idKey] = $option['id'];
foreach (['name', 'label', 'abbr'] as $key) {
- $optionValue = mb_strtolower($option[$key] ?? '');
+ $optionValue = $this->getComparisonValue($option[$key] ?? '');
if ($optionValue !== '') {
if (isset($values[$optionValue]) && $values[$optionValue] !== $option['id']) {
if (!isset($this->ambiguousOptions[$fieldName][$optionValue])) {
* @param string $importedValue
*/
protected function isAmbiguous(string $fieldName, $importedValue): bool {
- return !empty($this->ambiguousOptions[$fieldName][mb_strtolower($importedValue)]);
+ return !empty($this->ambiguousOptions[$fieldName][$this->getComparisonValue($importedValue)]);
}
/**
$formatted[$dateParam] = CRM_Utils_Date::processDate($params[$dateParam]);
}
+ /**
+ * Get the value to use for option comparison purposes.
+ *
+ * We do a case-insensitive comparison, also swapping ’ for '
+ * which has at least one known usage (Côte d’Ivoire).
+ *
+ * Note we do this to both sides of the comparison.
+ *
+ * @param int|string|false|null $importedValue
+ *
+ * @return false|int|string|null
+ */
+ protected function getComparisonValue($importedValue) {
+ return is_numeric($importedValue) ? $importedValue : mb_strtolower(str_replace('’', "'", $importedValue));
+ }
+
}
*/
public function importDataProvider(): array {
return [
+ 'individual_unicode.csv' => [
+ 'csv' => 'individual_unicode.csv',
+ 'mapper' => [['first_name'], ['last_name'], ['url', 1], ['country', 1]],
+ 'expected_error' => '',
+ 'expected_outcomes' => [CRM_Import_Parser::VALID => 1],
+ ],
'individual_invalid_sub_type' => [
'csv' => 'individual_invalid_contact_sub_type.csv',
'mapper' => [['first_name'], ['last_name'], ['contact_sub_type']],