fix email receipt flag for recurring record
authorSunil Pawar <sunil@skvare.com>
Mon, 14 Dec 2020 17:03:40 +0000 (22:33 +0530)
committereileen <emcnaughton@wikimedia.org>
Thu, 7 Jan 2021 05:19:31 +0000 (18:19 +1300)
added test case

CRM/Contribute/Form/Contribution/Confirm.php
CRM/Member/Form/Membership.php
tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php

index e69795941453df768f6d6bc70a4f5d74f6eb69d7..cc947dbbd4c56cb34c23ebec2d58bc0a8aaeef39 100644 (file)
@@ -1074,7 +1074,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
     $recurParams['invoice_id'] = $params['invoiceID'] ?? NULL;
     $recurParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
     $recurParams['payment_processor_id'] = $params['payment_processor_id'] ?? NULL;
-    $recurParams['is_email_receipt'] = $params['is_email_receipt'] ?? NULL;
+    $recurParams['is_email_receipt'] = (bool) ($params['is_email_receipt'] ?? FALSE);
     // we need to add a unique trxn_id to avoid a unique key error
     // in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
     $recurParams['trxn_id'] = $params['trxn_id'] ?? $params['invoiceID'];
index 8a81ebdc7dd0e3ea2cab653e8d860978c06e43ae..64f9c01f59c243c01206eb6e70397cda546caa55 100644 (file)
@@ -1993,7 +1993,7 @@ DESC limit 1");
     $recurParams['invoice_id'] = $params['invoiceID'] ?? NULL;
     $recurParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
     $recurParams['payment_processor_id'] = $params['payment_processor_id'] ?? NULL;
-    $recurParams['is_email_receipt'] = $params['is_email_receipt'] ?? NULL;
+    $recurParams['is_email_receipt'] = (bool) ($params['is_email_receipt'] ?? FALSE);
     // we need to add a unique trxn_id to avoid a unique key error
     // in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
     $recurParams['trxn_id'] = $params['trxn_id'] ?? $params['invoiceID'];
index d34f23c2ee228cc90f415a892415016c84f8d13f..138b5b9393e1e2b2e3011bd6e832978b68302b90 100644 (file)
@@ -564,4 +564,32 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase {
     ];
   }
 
+  /**
+   * Test Recurring Contribution Email Receipt Flag
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function testContributionEmailReceipt() {
+    $createParams = $this->_params;
+    unset($createParams['trxn_id'], $createParams['invoice_id']);
+
+    // pass null value to is_email_receipt
+    $createParams['is_email_receipt'] = NULL;
+    $recurring1 = CRM_Contribute_BAO_ContributionRecur::add($createParams);
+    $recurring1Get = $this->callAPISuccess('ContributionRecur', 'getsingle', ['id' => $recurring1->id]);
+    // default is_email_receipt column value is 1
+    $this->assertEquals('1', $recurring1Get['is_email_receipt']);
+
+    // pass empty value to is_email_receipt
+    $createParams['is_email_receipt'] = '';
+    $recurring2 = CRM_Contribute_BAO_ContributionRecur::add($createParams);
+    $this->assertEquals('null', $recurring2->is_email_receipt);
+
+    // pass 0 value to is_email_receipt
+    $createParams['is_email_receipt'] = 0;
+    $recurring3 = CRM_Contribute_BAO_ContributionRecur::add($createParams);
+    $recurring3Get = $this->callAPISuccess('ContributionRecur', 'getsingle', ['id' => $recurring3->id]);
+    $this->assertEquals('0', $recurring3Get['is_email_receipt']);
+  }
+
 }