CRM-15296 test for behaviour on renew with recurring
authoreileenmcnaughton <eileen@fuzion.co.nz>
Sun, 28 Sep 2014 22:10:15 +0000 (22:10 +0000)
committereileenmcnaughton <eileen@fuzion.co.nz>
Sun, 28 Sep 2014 22:38:29 +0000 (22:38 +0000)
CRM-15296 mark incomplete portion of this test as incomplete so as not to commit failing tests
note that the incomplete part can be enabled when th issue is fixed

Alter Dummy processor to be test-friendly

Conflicts:
tests/phpunit/api/v3/ContributionPageTest.php

wq!

CRM/Core/Payment/Dummy.php
tests/phpunit/api/v3/ContributionPageTest.php

index 2dca05ea830a3ce4ff2a9c00975a9265f171c08a..05d19d37e2c2448b9404e1a70096f6462665fafd 100644 (file)
@@ -24,6 +24,14 @@ class CRM_Core_Payment_Dummy extends CRM_Core_Payment {
   protected $_mode = NULL;
 
   protected $_params = array();
+  protected $_doDirectPaymentResult = array();
+
+  /**
+   * @param array $doDirectPaymentResult
+   */
+  public function setDoDirectPaymentResult($doDirectPaymentResult) {
+    $this->_doDirectPaymentResult = $doDirectPaymentResult;
+  }
 
   /**
    * We only need one instance of this object. So we use the singleton
@@ -90,8 +98,10 @@ class CRM_Core_Payment_Dummy extends CRM_Core_Payment {
       $params,
       $cookedParams
     );
-    //end of hook invokation
-
+    //end of hook invocation
+    if (!empty($this->_doDirectPaymentResult)) {
+      return $this->_doDirectPaymentResult;
+    }
     if ($this->_mode == 'test') {
       $query             = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'";
       $p                 = array();
index 03969056aaa329d528caff1495dd7d2586aaf211..6380c117866689bce36159f41961161892a46899 100644 (file)
@@ -44,6 +44,11 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
   protected $_entity = 'contribution_page';
   protected $contribution_result = null;
   protected $_priceSetParams = array();
+  /**
+   * Payment processor details
+   * @var array
+   */
+  protected $_paymentProcessor = array();
 
   /**
    * @var array
@@ -245,13 +250,125 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
     $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
   }
+
+  /**
+   * Test submit with a membership block in place
+   */
+  public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecur() {
+    $this->params['is_recur'] = 1;
+    $var = array();
+    $this->params['recur_frequency_unit'] = 'month';
+    $this->setUpMembershipContributionPage();
+    $dummyPP = CRM_Core_Payment::singleton('live', $this->_paymentProcessor);
+    $dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 1, 'trxn_id' => 1233,));
+
+    $submitParams = array(
+      'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
+      'id' => (int) $this->_ids['contribution_page'],
+      'amount' => 10,
+      'billing_first_name' => 'Billy',
+      'billing_middle_name' => 'Goat',
+      'billing_last_name' => 'Gruff',
+      'email' => 'billy@goat.gruff',
+      'selectMembership' => $this->_ids['membership_type'],
+      'payment_processor' => 1,
+      'credit_card_number' => '4111111111111111',
+      'credit_card_type' => 'Visa',
+      'credit_card_exp_date' => array('M' => 9, 'Y' => 2040 ),
+      'cvv2' => 123,
+      'is_recur' => 1,
+      'frequency_interval' => 1,
+      'frequency_unit' => 'month',
+    );
+
+    $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL, 'Submit');
+    $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1));
+    $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+    $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
+    $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+    $this->assertEquals($membership['contact_id'], $contribution['contact_id']);
+    $this->assertEquals(1, $membership['status_id']);
+    $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
+
+    //renew it with processor setting completed - should extend membership
+    $submitParams['contact_id'] = $contribution['contact_id'];
+    $dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 1, 'trxn_id' => 1234,));
+    $this->callAPISuccess('contribution_page', 'submit', $submitParams);
+    $this->callAPISuccess('contribution', 'getsingle', array('id' => array('NOT IN' => array($contribution['id'])), 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1));
+    $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+    $this->assertEquals(date('Y-m-d', strtotime('+ 1 year', strtotime($membership['end_date']))), $renewedMembership['end_date']);
+    $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
+    //@todo this assertion should pass
+    //$this->assertEquals(5, $recurringContribution['contribution_status_id']);
+  }
+
+  /**
+   * Test submit with a membership block in place
+   */
+  public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurDelayed() {
+    $this->params['is_recur'] = 1;
+    $var = array();
+    $this->params['recur_frequency_unit'] = 'month';
+    $this->setUpMembershipContributionPage();
+    $dummyPP = CRM_Core_Payment::singleton('live', $this->_paymentProcessor);
+    $dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 1, 'trxn_id' => 1233,));
+
+    $submitParams = array(
+      'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
+      'id' => (int) $this->_ids['contribution_page'],
+      'amount' => 10,
+      'billing_first_name' => 'Billy',
+      'billing_middle_name' => 'Goat',
+      'billing_last_name' => 'Gruff',
+      'email' => 'billy@goat.gruff',
+      'selectMembership' => $this->_ids['membership_type'],
+      'payment_processor' => 1,
+      'credit_card_number' => '4111111111111111',
+      'credit_card_type' => 'Visa',
+      'credit_card_exp_date' => array('M' => 9, 'Y' => 2040 ),
+      'cvv2' => 123,
+    );
+
+    $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL, 'Submit');
+    $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1));
+    $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+    $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
+    $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+    $this->assertEquals($membership['contact_id'], $contribution['contact_id']);
+    $this->assertEquals(1, $membership['status_id']);
+
+    //renew it with processor setting completed - should extend membership
+    $submitParams = array_merge($submitParams, array(
+      'contact_id' => $contribution['contact_id'],
+      'is_recur' => 1,
+      'frequency_interval' => 1,
+      'frequency_unit' => 'month',)
+    );
+    $dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 2,));
+    $this->markTestIncomplete('currently failing - this needs fixing per CRM-15296 as it shows that renewals are being actioned even when payment is not');
+    $this->callAPISuccess('contribution_page', 'submit', $submitParams);
+    $this->callAPISuccess('contribution', 'getsingle', array('id' => array(
+      'NOT IN' => array($contribution['id'])), 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 2)
+    );
+    $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+    //no renewal as the date hasn't changed
+    $this->assertEquals($membership['end_date'], $renewedMembership['end_date']);
+    $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
+    $this->assertEquals(5, $recurringContribution['status_id']);
+  }
+
   /**
    * set up membership contribution page
    * @param bool $isSeparatePayment
    */
   function setUpMembershipContributionPage($isSeparatePayment = FALSE) {
     $this->setUpMembershipBlockPriceSet();
-    $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate(array('payment_processor_type_id' => 'Dummy',));
+    $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate(array(
+      'payment_processor_type_id' => 'Dummy',
+      'class_name' => 'Payment_Dummy',
+      'billing_mode' => 1,
+    ));
+    $this->_paymentProcessor = $this->callAPISuccess('payment_processor', 'getsingle', array('id' => $this->params['payment_processor_id']));
     $this->setUpContributionPage();
 
     $this->callAPISuccess('membership_block', 'create', array(