From 53809cc71cee75c155ecfe322516f3b3e8f1a221 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 28 Oct 2022 14:12:27 +1300 Subject: [PATCH] ix import mandatory field validation regression --- CRM/Contribute/Import/Form/MapField.php | 10 +++++++--- .../Import/Parser/ContributionTest.php | 18 ++++++++++++++++++ .../Import/Parser/data/checkboxes.csv | 3 +++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/CRM/Contribute/Import/Parser/data/checkboxes.csv diff --git a/CRM/Contribute/Import/Form/MapField.php b/CRM/Contribute/Import/Form/MapField.php index 113a7806b2..7f96270c5a 100644 --- a/CRM/Contribute/Import/Form/MapField.php +++ b/CRM/Contribute/Import/Form/MapField.php @@ -247,13 +247,17 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { $ruleFields = $rule['fields']; $weightSum = 0; foreach ($mapper as $mapping) { - if ($mapping[0] === 'external_identifier' || $mapping[0] === 'contribution_contact_id' || $mapping[0] === 'contact__id') { + // Because api v4 style fields have a . and QuickForm multiselect js does + // not cope with a . the quick form layer will use a double underscore + // as a stand in (the angular layer will not) + $fieldName = str_replace('__', '.', $mapping[0]); + if ($fieldName === 'external_identifier' || $fieldName === 'contribution_contact_id' || $fieldName === 'contact__id') { // It is enough to have external identifier mapped. $weightSum = $threshold; break; } - if (array_key_exists($mapping[0], $ruleFields)) { - $weightSum += $ruleFields[$mapping[0]]; + if (array_key_exists($fieldName, $ruleFields)) { + $weightSum += $ruleFields[$fieldName]; } } if ($weightSum < $threshold) { diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php index 78203e35fa..90927307ec 100644 --- a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php @@ -456,6 +456,24 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { } + /** + * Tests the form flow copes with QuickForm style dots. + * + * Because the QuickForm hierarchical select won't cope with dots + * we are using a double underscore on that form. The test checks that works. + */ + public function testImportQuickFormEmailMatch() :void { + $this->individualCreate(['email' => 'jenny@example.com']); + $this->importCSV('checkboxes.csv', [ + ['name' => 'total_amount'], + ['name' => 'receive_date'], + ['name' => 'financial_type_id'], + ['name' => ''], + ['name' => 'email_primary__email'], + ['name' => ''], + ]); + } + /** * Test whether importing a contribution using email match will match a non-primary. * diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/data/checkboxes.csv b/tests/phpunit/CRM/Contribute/Import/Parser/data/checkboxes.csv new file mode 100644 index 0000000000..8d23a52ee4 --- /dev/null +++ b/tests/phpunit/CRM/Contribute/Import/Parser/data/checkboxes.csv @@ -0,0 +1,3 @@ +Total Amount,Date Received,Financial Type,Colour,Contact email,Soft credit email +50,2022-03-09,Donation,"Red,Yellow,Blue",jenny@example.com,demo@example.com +60,2022-04-09,Donation,"1,2,3",jenny@example.com,demo@example.com -- 2.25.1