From: Eileen McNaughton Date: Tue, 30 Sep 2014 07:35:27 +0000 (+1300) Subject: CRM-15296 test updates X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e6fa4056efab2bc11d3d47d81c6a3b218107e72a;p=civicrm-core.git CRM-15296 test updates --- diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index cea0c0ee62..8289a514b9 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1820,13 +1820,12 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } } - /** - * Static submit function allowing tests (& api access although this is being built slowly) - * @param $params - */ static function submit($params) { $form = new CRM_Contribute_Form_Contribution_Confirm(); $form->_id = $params['id']; + if (!empty($params['contact_id'])) { + $form->_contactID = $params['contact_id']; + } CRM_Contribute_BAO_ContributionPage::setValues($form->_id, $form->_values); $form->_separateMembershipPayment = CRM_Contribute_BAO_ContributionPage::getIsMembershipPayment($form->_id); //this way the mocked up controller ignores the session stuff @@ -1835,7 +1834,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $params['invoiceID'] = md5(uniqid(rand(), TRUE)); $paramsProcessedForForm = $form->_params = self::getFormParams($params['id'], $params); $form->_amount = $params['amount']; - $priceSetID = $form->_params['priceSetId'] = $paramsProcessedForForm['price_set_id']; $priceFields = CRM_Price_BAO_PriceSet::getSetDetail($priceSetID); $priceSetFields = reset($priceFields); @@ -1844,6 +1842,12 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $form->setFormAmountFields($priceSetID); if (!empty($params['payment_processor'])) { $form->_paymentProcessor = civicrm_api3('payment_processor', 'getsingle', array('id' => $params['payment_processor'])); + if ($form->_paymentProcessor['billing_mode'] ==1) { + $form->_contributeMode = 'direct'; + } + else { + $form->_contributeMode = 'notify'; + } } $priceFields = $priceFields[$priceSetID]['fields']; CRM_Price_BAO_PriceSet::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution'); diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 6380c11786..37c209a93a 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -252,7 +252,11 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { } /** - * Test submit with a membership block in place + * Test submit recurring membership with immediate confirmation (IATS style) + * - we process 2 membership transactions against with a recurring contribution against a contribution page with an immediate + * processor (IASTS style - denoted by returning trxn_id) + * - the first creates a new membership, completed contribution, in progress recurring. Check these + * - create another - end date should be extended */ public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecur() { $this->params['is_recur'] = 1; @@ -260,7 +264,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $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,)); + $dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 1, 'trxn_id' => 'create_first_success',)); $submitParams = array( 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), @@ -289,29 +293,33 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $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'])); - + //@todo - check with Joe about these not existing + //$this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['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,)); + $dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 1, 'trxn_id' => 'create_second_success',)); $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']); + $this->assertEquals(2, $recurringContribution['contribution_status_id']); } /** - * Test submit with a membership block in place + * Test submit recurring membership with delayed confirmation (Authorize.net style) + * - we process 2 membership transactions against with a recurring contribution against a contribution page with a delayed + * processor (Authorize.net style - denoted by NOT returning trxn_id) + * - the first creates a pending membership, pending contribution, penging recurring. Check these + * - complete the transaction + * - create another - end date should NOT be extended */ 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,)); + $dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 2,)); $submitParams = array( 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), @@ -327,16 +335,22 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { '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)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 2)); $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->assertEquals(5, $membership['status_id']); + //@todo - check with Joe about these not existing + //$this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['id'])); + $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id'], 'trxn_id' => 'ipn_called')); + $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); //renew it with processor setting completed - should extend membership $submitParams = array_merge($submitParams, array( 'contact_id' => $contribution['contact_id'], @@ -345,16 +359,16 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { '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( + $newContribution = $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']); + $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $newContribution['contribution_recur_id'])); + $this->assertEquals(2, $recurringContribution['contribution_status_id']); } /**