From 339d7a00566be15d8a970f3b06f37fd5dd83ee3b Mon Sep 17 00:00:00 2001 From: Seamus Lee <seamuslee001@gmail.com> Date: Tue, 16 Jun 2020 14:57:41 +1000 Subject: [PATCH] dev/core#1806 Fix issue with importing radio custom data field using the option label --- CRM/Contribute/Import/Parser/Contribution.php | 1 + .../Import/Parser/ContributionTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CRM/Contribute/Import/Parser/Contribution.php b/CRM/Contribute/Import/Parser/Contribution.php index 41fe4b8e4b6..13b16a9ff22 100644 --- a/CRM/Contribute/Import/Parser/Contribution.php +++ b/CRM/Contribute/Import/Parser/Contribution.php @@ -671,6 +671,7 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Contribute_Import_Pa } } } + continue; } switch ($key) { diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php index 753f684e71b..e445f6e36ea 100644 --- a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php @@ -177,6 +177,25 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { // on one hand the custom fields have a date format & on the other there is an input format & // it seems to ignore the latter in favour of the former - which seems wrong. $this->assertEquals('20191020000000', $formatted[$this->getCustomFieldName('date')]); + $this->callAPISuccess('CustomField', 'delete', ['id' => $this->ids['CustomField']['date']]); + $this->callAPISuccess('CustomGroup', 'delete', ['id' => $this->ids['CustomGroup']['Custom Group']]); + } + + public function testParsedCustomOption() { + $contactID = $this->individualCreate(); + $values = ['contribution_contact_id' => $contactID, 'total_amount' => 10, 'financial_type' => 'Donation', 'payment_instrument' => 'Check', 'contribution_status_id' => 'Pending']; + // Note that the expected result should logically be CRM_Import_Parser::valid but writing test to reflect not fix here + $this->runImport($values, CRM_Import_Parser::DUPLICATE_UPDATE, NULL); + $contribution = $this->callAPISuccess('Contribution', 'getsingle', ['contact_id' => $contactID]); + $this->createCustomGroupWithFieldOfType([], 'radio'); + $values['contribution_id'] = $contribution['id']; + $values[$this->getCustomFieldName('radio')] = 'Red Testing'; + unset(Civi::$statics['CRM_Core_BAO_OptionGroup']); + $this->runImport($values, CRM_Import_Parser::DUPLICATE_UPDATE, NULL); + $contribution = $this->callAPISuccess('Contribution', 'get', ['contact_id' => $contactID, $this->getCustomFieldName('radio') => 'Red Testing']); + $this->assertEquals(5, $contribution['values'][$contribution['id']]['custom_' . $this->ids['CustomField']['radio']]); + $this->callAPISuccess('CustomField', 'delete', ['id' => $this->ids['CustomField']['radio']]); + $this->callAPISuccess('CustomGroup', 'delete', ['id' => $this->ids['CustomGroup']['Custom Group']]); } /** -- GitLab