From 6df0ad23d3d54eed3f782a79546f13d91f898d51 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 23 Aug 2022 09:54:54 +1200 Subject: [PATCH] Remove do-nothing code, add test to prove --- CRM/Contribute/Import/Parser/Contribution.php | 17 ------- .../Import/Parser/ContributionTest.php | 51 +++++++++++++++---- .../Import/Parser/data/contributions.csv | 4 +- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/CRM/Contribute/Import/Parser/Contribution.php b/CRM/Contribute/Import/Parser/Contribution.php index 3e781ed049..b2870f7c5c 100644 --- a/CRM/Contribute/Import/Parser/Contribution.php +++ b/CRM/Contribute/Import/Parser/Contribution.php @@ -847,23 +847,6 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Import_Parser { } } - if (array_key_exists('note', $params)) { - $values['note'] = $params['note']; - } - - if ($create) { - // CRM_Contribute_BAO_Contribution::add() handles contribution_source - // So, if $values contains contribution_source, convert it to source - $changes = ['contribution_source' => 'source']; - - foreach ($changes as $orgVal => $changeVal) { - if (isset($values[$orgVal])) { - $values[$changeVal] = $values[$orgVal]; - unset($values[$orgVal]); - } - } - } - return NULL; } diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php index 1b25e57839..8bdda8e3a4 100644 --- a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php @@ -6,6 +6,7 @@ use Civi\Api4\Contribution; use Civi\Api4\ContributionSoft; +use Civi\Api4\Note; use Civi\Api4\OptionValue; use Civi\Api4\UserJob; @@ -264,23 +265,37 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { /** * Test the full form-flow import. + * + * @throws \CRM_Core_Exception */ - public function testImport() :void { - $this->importCSV('contributions.csv', [ - ['name' => 'first_name'], - ['name' => 'total_amount'], - ['name' => 'receive_date'], - ['name' => 'financial_type_id'], - ['name' => 'email'], - ]); - $dataSource = new CRM_Import_DataSource_CSV($this->userJobID); + public function testImportNoMatch() :void { + $dataSource = $this->importContributionsDotCSV(); $row = $dataSource->getRow(); $this->assertEquals('ERROR', $row['_status']); $this->assertEquals('No matching Contact found for (mum@example.com )', $row['_status_message']); } + /** + * Test the full form-flow import. + * + * @throws \CRM_Core_Exception + */ + public function testImportMatch() :void { + $this->individualCreate(['email' => 'mum@example.com']); + $this->importContributionsDotCSV(); + $contribution = Contribution::get()->execute()->first(); + $this->assertEquals('Word of mouth', $contribution['source']); + $note = Note::get() + ->addWhere('entity_id', '=', $contribution['id']) + ->addWhere('entity_table', '=', 'civicrm_contribution')->execute()->first(); + $this->assertEquals('Call him back', $note['note']); + } + + /** + * @throws \CRM_Core_Exception + */ public function testImportWithMatchByExternalIdentifier() :void { - CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_contact AUTO_INCREMENT = 1000000"); + CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_contact AUTO_INCREMENT = 1000000'); $contactRubyParams = [ 'first_name' => 'Ruby', @@ -449,4 +464,20 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { return $form; } + /** + * @return \CRM_Import_DataSource_CSV + */ + private function importContributionsDotCSV(): CRM_Import_DataSource_CSV { + $this->importCSV('contributions.csv', [ + ['name' => 'first_name'], + ['name' => 'total_amount'], + ['name' => 'receive_date'], + ['name' => 'financial_type_id'], + ['name' => 'email'], + ['name' => 'contribution_source'], + ['name' => 'note'], + ]); + return new CRM_Import_DataSource_CSV($this->userJobID); + } + } diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/data/contributions.csv b/tests/phpunit/CRM/Contribute/Import/Parser/data/contributions.csv index ba8175db8f..135032e217 100644 --- a/tests/phpunit/CRM/Contribute/Import/Parser/data/contributions.csv +++ b/tests/phpunit/CRM/Contribute/Import/Parser/data/contributions.csv @@ -1,2 +1,2 @@ -External Identifier,Total Amount,Receive Date,Financial Type,Soft Credit to -bob,65,2008-09-20,Donation,mum@example.com +External Identifier,Total Amount,Receive Date,Financial Type,Soft Credit to,Source,Note +bob,65,2008-09-20,Donation,mum@example.com,Word of mouth,Call him back -- 2.25.1