X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fapi%2Fv3%2FContributionPageTest.php;h=fe257feb0db424ed5f3ebeef9f9e39b481c6ced2;hb=461ae02f8b5e088c0ffad5d87c94d46f3cfe0621;hp=442bd348b558372c36feab9e74eb626cb4e2d006;hpb=ec5ce226e8bb29127a5835ba667c1d2b7694b4d5;p=civicrm-core.git diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 442bd348b5..fe257feb0d 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -257,6 +257,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'trxn_id' => 'create_first_success', 'fee_amount' => .85, )); + $processor = $dummyPP->getPaymentProcessor(); $this->callAPISuccess('ContributionPage', 'create', array( 'id' => $this->_ids['contribution_page'], 'payment_processor' => array($paymentProcessor2ID, $this->_ids['payment_processor']), @@ -286,6 +287,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->_checkFinancialRecords(array( 'id' => $contribution['id'], 'total_amount' => $contribution['total_amount'], + 'payment_instrument_id' => $processor['payment_instrument_id'], ), 'online'); } @@ -399,6 +401,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); $this->assertCount(2, $contributions['values']); + $this->callAPISuccessGetCount('LineItem', array(), 2); $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); @@ -436,10 +439,18 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); - $mut->checkAllMailLog(array( - '$ 2.00', - 'Membership Fee', - )); + // We should have two separate email messages, each with their own amount + // line and no total line. + $mut->checkAllMailLog( + array( + 'Amount: $ 2.00', + 'Amount: $ 10.00', + 'Membership Fee', + ), + array( + 'Total: $', + ) + ); $mut->stop(); $mut->clearMessages(999); } @@ -599,6 +610,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->setUpMembershipContributionPage(); $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success')); + $processor = $dummyPP->getPaymentProcessor(); $submitParams = array( 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), @@ -624,6 +636,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1, )); + $this->assertEquals($processor['payment_instrument_id'], $contribution['payment_instrument_id']); $this->assertEquals('create_first_success', $contribution['trxn_id']); $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); @@ -632,8 +645,8 @@ 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'])); + + $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('payment_status_id' => 1, 'trxn_id' => 'create_second_success')); @@ -646,6 +659,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $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'])); + $this->assertEquals($processor['payment_instrument_id'], $recurringContribution['payment_instrument_id']); $this->assertEquals(5, $recurringContribution['contribution_status_id']); } @@ -710,6 +724,13 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->setUpMembershipContributionPage(); $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2)); + $this->membershipTypeCreate(array('name' => 'Student')); + + // Add a contribution & a couple of memberships so the id will not be 1 & will differ from membership id. + // This saves us from 'accidental success'. + $this->contributionCreate(array('contact_id' => $this->contactIds[0])); + $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0])); + $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0], 'membership_type_id' => 'Student')); $submitParams = array( 'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), @@ -735,18 +756,26 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { '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(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'])); + + $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'])); + $this->assertEquals('civicrm_membership', $line['entity_table']); + $this->assertEquals($membership['id'], $line['entity_id']); + $this->callAPISuccess('contribution', 'completetransaction', array( 'id' => $contribution['id'], 'trxn_id' => 'ipn_called', 'payment_processor_id' => $this->_paymentProcessor['id'], )); + $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'])); + $this->assertEquals('civicrm_membership', $line['entity_table']); + $this->assertEquals($membership['id'], $line['entity_id']); + $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); //renew it with processor setting completed - should extend membership $submitParams = array_merge($submitParams, array( @@ -756,6 +785,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'frequency_unit' => 'month', ) ); + $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2)); $this->callAPISuccess('contribution_page', 'submit', $submitParams); $newContribution = $this->callAPISuccess('contribution', 'getsingle', array( @@ -766,6 +796,9 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'contribution_status_id' => 2, ) ); + $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $newContribution['id'])); + $this->assertEquals('civicrm_membership', $line['entity_table']); + $this->assertEquals($membership['id'], $line['entity_id']); $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); //no renewal as the date hasn't changed @@ -1003,4 +1036,53 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->assertEquals($recur['contribution_status_id'], 5); // In progress status. } + /** + * Test submit pledge payment. + * + * - test submitting a pledge payment using contribution form. + */ + public function testSubmitPledgePayment() { + $this->testSubmitPledgePaymentPaymentProcessorRecurFuturePayment(); + $pledge = $this->callAPISuccess('pledge', 'getsingle', array()); + $params = array( + 'pledge_id' => $pledge['id'], + ); + $submitParams = array( + 'id' => (int) $pledge['pledge_contribution_page_id'], + 'pledge_amount' => array(2 => 1), + 'billing_first_name' => 'Billy', + 'billing_middle_name' => 'Goat', + 'billing_last_name' => 'Gruff', + 'email' => 'billy@goat.gruff', + 'payment_processor_id' => 1, + 'credit_card_number' => '4111111111111111', + 'credit_card_type' => 'Visa', + 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), + 'cvv2' => 123, + 'pledge_id' => $pledge['id'], + 'cid' => $pledge['contact_id'], + 'contact_id' => $pledge['contact_id'], + 'amount' => 100.00, + 'is_pledge' => TRUE, + 'pledge_block_id' => $this->_ids['pledge_block_id'], + ); + $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params); + $this->assertEquals($pledgePayment['values'][2]['status_id'], 2); + + $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); + + // Check if contribution created. + $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + 'contribution_page_id' => $pledge['pledge_contribution_page_id'], + 'contribution_status_id' => 'Completed', + 'contact_id' => $pledge['contact_id'], + 'contribution_recur_id' => array('IS NULL' => 1), + )); + + $this->assertEquals(100.00, $contribution['total_amount']); + $pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params); + $this->assertEquals($pledgePayment['values'][2]['status_id'], 1, "This pledge payment should have been completed"); + $this->assertEquals($pledgePayment['values'][2]['contribution_id'], $contribution['id']); + } + }