Add test for thousand separators on import
authoreileen <emcnaughton@wikimedia.org>
Thu, 22 Mar 2018 08:50:38 +0000 (21:50 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 22 Mar 2018 08:50:38 +0000 (21:50 +1300)
CRM/Contribute/Import/Parser/Contribution.php
tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php
tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php

index 993e977decff09e02366f7060181949008956b0d..0e22418d61931f0278fc83cc2904991712ad0696 100644 (file)
@@ -256,14 +256,8 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Contribute_Import_Pa
     }
 
     $params = &$this->getActiveFieldParams();
-    $formatted = array('version' => 3);
-
-    // don't add to recent items, CRM-4399
-    $formatted['skipRecentView'] = TRUE;
-
-    //for date-Formats
-    $session = CRM_Core_Session::singleton();
-    $dateType = $session->get('dateTypes');
+    $formatted = ['version' => 3, 'skipRecentView' => TRUE, 'skipCleanMoney' => FALSE];
+    $dateType = CRM_Core_Session::singleton()->get('dateTypes');
 
     $customDataType = !empty($params['contact_type']) ? $params['contact_type'] : 'Contribution';
     $customFields = CRM_Core_BAO_CustomField::getFields($customDataType);
index d5758aef09ed4446243cc7bb99a01a2a8a5ef918..7d2a4e49fa7960f1169cfa8fe81e8bb1aba813d0 100644 (file)
@@ -99,7 +99,7 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase {
    */
   public function testSupportFinancialTypeChange() {
     $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $this->_params);
-    $this->callAPISuccess('contribution', 'create', array(
+    $this->callAPISuccess('Contribution', 'create', array(
       'contribution_recur_id' => $contributionRecur['id'],
       'total_amount' => '3.00',
       'financial_type_id' => 1,
index 303bdd11138e665c272a82798c4903df93de6a45..4cae5b79d8f918227794f8d9501d03a8ff9f5cc3 100644 (file)
@@ -22,9 +22,14 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase {
    *
    * In this case primary contact and secondary contact both are identified by external identifier.
    *
+   * @dataProvider getThousandSeparators
+   *
+   * @param string $thousandSeparator
+   *
    * @throws \Exception
    */
-  public function testImportParserWithSoftCreditsByExternalIdentifier() {
+  public function testImportParserWithSoftCreditsByExternalIdentifier($thousandSeparator) {
+    $this->setCurrencySeparators($thousandSeparator);
     $contact1Params = array(
       'first_name' => 'Contact',
       'last_name' => 'One',
@@ -40,7 +45,7 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase {
     $contact1Id = $this->individualCreate($contact1Params);
     $contact2Id = $this->individualCreate($contact2Params);
     $values = array(
-      "total_amount" => 10,
+      "total_amount" => $this->formatMoneyInput(1230.99),
       "financial_type" => "Donation",
       "external_identifier" => "ext-1",
       "soft_credit" => "ext-2",
@@ -53,6 +58,10 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase {
     );
     $values = array();
     $contributionsOfMainContact = CRM_Contribute_BAO_Contribution::retrieve($params, $values, $values);
+    $this->assertEquals(1230.99, $contributionsOfMainContact->total_amount);
+    $this->assertEquals(1230.99, $contributionsOfMainContact->net_amount);
+    $this->assertEquals(0, $contributionsOfMainContact->fee_amount);
+
     $params["contact_id"] = $contact2Id;
     $contributionsOfSoftContact = CRM_Contribute_BAO_ContributionSoft::retrieve($params, $values);
     $this->assertEquals(1, count($contributionsOfMainContact), 'Contribution not added for primary contact');