Remove do-nothing code, add test to prove
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 22 Aug 2022 21:54:54 +0000 (09:54 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 22 Aug 2022 21:54:54 +0000 (09:54 +1200)
CRM/Contribute/Import/Parser/Contribution.php
tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php
tests/phpunit/CRM/Contribute/Import/Parser/data/contributions.csv

index 3e781ed0499acea2e4620d0964175ccdf5898eb1..b2870f7c5c0117d40e3135796a7f0b715a8d44f2 100644 (file)
@@ -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;
   }
 
index 1b25e5783975c3d77fc338b484973833933d4d68..8bdda8e3a4ef211f28ac0e245d7a4a60db2d2b59 100644 (file)
@@ -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);
+  }
+
 }
index ba8175db8f74393709ce98f0227473d201c438f4..135032e217006bcd489e9730b7e985ce667321b7 100644 (file)
@@ -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