Add unit test to check CRM-20311
authorJitendra Purohit <jitendra@fuzion.co.nz>
Mon, 27 Mar 2017 05:33:48 +0000 (11:03 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Mon, 27 Mar 2017 11:50:05 +0000 (17:20 +0530)
tests/phpunit/api/v3/MembershipTest.php

index a35a52ad5be7096621fbd1397066c1ebaf484781..7e2579e3f3572b4f55c2eba52b0cd52870473242 100644 (file)
@@ -93,6 +93,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
         'civicrm_membership',
         'civicrm_membership_payment',
         'civicrm_membership_log',
+        'civicrm_uf_match',
       ),
       TRUE
     );
@@ -163,6 +164,47 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $this->assertDBRowNotExist('CRM_Contribute_DAO_Contribution', $ContributionCreate['values'][0]['id']);
   }
 
+  /**
+   * Test Activity creation on cancellation of membership contribution.
+   */
+  public function testActivityForCancelledContribution() {
+    $contactId = $this->createLoggedInUser();
+    $membershipID = $this->contactMembershipCreate($this->_params);
+    $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
+
+    $ContributionCreate = $this->callAPISuccess('Contribution', 'create', array(
+      'financial_type_id' => "Member Dues",
+      'total_amount' => 100,
+      'contact_id' => $this->_params['contact_id'],
+    ));
+    $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', array(
+      'sequential' => 1,
+      'contribution_id' => $ContributionCreate['id'],
+      'membership_id' => $membershipID,
+    ));
+    $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
+    $this->paymentInstruments = $instruments['values'];
+
+    $form = new CRM_Contribute_Form_Contribution();
+    $form->_id = $ContributionCreate['id'];
+    $form->testSubmit(array(
+      'total_amount' => 100,
+      'financial_type_id' => 1,
+      'receive_date' => '04/21/2015',
+      'receive_date_time' => '11:27PM',
+      'contact_id' => $contactId,
+      'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
+      'contribution_status_id' => 3,
+    ),
+    CRM_Core_Action::UPDATE);
+
+    $activity = $this->callAPISuccess('Activity', 'get', array(
+      'activity_type_id' => "Change Membership Status",
+      'source_record_id' => $membershipID,
+    ));
+    $this->assertNotEmpty($activity['values']);
+  }
+
   /**
    * Test membership get.
    */