CRM-11338 add fix & test for amount & fee_amount on membership renewal
authoreileenmcnaugton <eileen@fuzion.co.nz>
Wed, 26 Aug 2015 10:29:32 +0000 (22:29 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Wed, 26 Aug 2015 13:33:18 +0000 (01:33 +1200)
CRM/Member/Form/MembershipRenewal.php
tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php

index 178dd1df619df2cb9a1f222d8a9dd1dc3010d7a3..addb5b71bda9387facb6723d6b0ac421b0d675a6 100644 (file)
@@ -637,7 +637,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
           $li['financial_type_id'] = $submittedFinancialType;
         }
       }
-      $this->_params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
+
       if (!empty($lineItem)) {
         $this->_params['lineItems'] = $lineItem;
         $this->_params['processPriceSet'] = TRUE;
index 06748da47e06fd8a092c862f58d3c45cfabe6d2e..fb95bda61d19587793bd9dfd46f89650a9240b82 100644 (file)
@@ -280,6 +280,53 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
     ));
   }
 
+  /**
+   * Test the submit function of the membership form.
+   */
+  public function testSubmitRecurCompleteInstant() {
+    $form = $this->getForm();
+
+    $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
+    $processor->setDoDirectPaymentResult(array(
+      'payment_status_id' => 1,
+      'trxn_id' => 'kettles boil water',
+      'fee_amount' => .29,
+    ));
+
+    $this->callAPISuccess('MembershipType', 'create', array(
+      'id' => $this->membershipTypeAnnualFixedID,
+      'duration_unit' => 'month',
+      'duration_interval' => 1,
+      'auto_renew' => TRUE,
+    ));
+    $this->createLoggedInUser();
+    $form->preProcess();
+
+    $form->_contactID = $this->_individualId;
+    $params = $this->getBaseSubmitParams();
+    $form->_mode = 'test';
+
+    $form->testSubmit($params);
+    $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+    $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);
+
+    $contribution = $this->callAPISuccess('Contribution', 'getsingle', array(
+      'contact_id' => $this->_individualId,
+      'is_test' => TRUE,
+    ));
+
+    $this->assertEquals('kettles boil water', $contribution['trxn_id']);
+    $this->assertEquals(.29, $contribution['fee_amount']);
+    $this->assertEquals(78, $contribution['total_amount']);
+    $this->assertEquals(77.71, $contribution['net_amount']);
+
+    $this->callAPISuccessGetCount('LineItem', array(
+      'entity_id' => $membership['id'],
+      'entity_table' => 'civicrm_membership',
+      'contribution_id' => $contribution['id'],
+    ), 1);
+
+  }
   /**
    * Test the submit function of the membership form.
    */
@@ -462,4 +509,49 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
     return $form;
   }
 
+  /**
+   * Get some re-usable parameters for the submit function.
+   *
+   * @return array
+   */
+  protected function getBaseSubmitParams() {
+    $params = array(
+      'cid' => $this->_individualId,
+      'price_set_id' => 0,
+      'join_date' => date('m/d/Y', time()),
+      'start_date' => '',
+      'end_date' => '',
+      'campaign_id' => '',
+      // This format reflects the 23 being the organisation & the 25 being the type.
+      'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+      'auto_renew' => '1',
+      'is_recur' => 1,
+      'max_related' => 0,
+      'num_terms' => '1',
+      'source' => '',
+      'total_amount' => '78.00',
+      'financial_type_id' => '2', //Member dues, see data.xml
+      'soft_credit_type_id' => 11,
+      'soft_credit_contact_id' => '',
+      'from_email_address' => '"Demonstrators Anonymous" <info@example.org>',
+      'receipt_text' => 'Thank you text',
+      'payment_processor_id' => $this->_paymentProcessorID,
+      'credit_card_number' => '4111111111111111',
+      'cvv2' => '123',
+      'credit_card_exp_date' => array(
+        'M' => '9',
+        'Y' => '2019', // TODO: Future proof
+      ),
+      'credit_card_type' => 'Visa',
+      'billing_first_name' => 'Test',
+      'billing_middlename' => 'Last',
+      'billing_street_address-5' => '10 Test St',
+      'billing_city-5' => 'Test',
+      'billing_state_province_id-5' => '1003',
+      'billing_postal_code-5' => '90210',
+      'billing_country_id-5' => '1228',
+    );
+    return $params;
+  }
+
 }