From 6cfe164ef67bb3152d6d4c4538e79a79112d3445 Mon Sep 17 00:00:00 2001 From: Edsel Date: Thu, 1 Sep 2016 17:43:05 +0530 Subject: [PATCH] CRM-19153 Added unit test for pledge payments ---------------------------------------- * CRM-19153: Future pledge start date causes improper future pledge payment dates https://issues.civicrm.org/jira/browse/CRM-19153 --- tests/phpunit/api/v3/ContributionPageTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index f789eb0b89f7..62a2b9dbc72b 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -999,4 +999,53 @@ public function testSubmitPledgePaymentPaymentProcessorRecurFuturePayment() { $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']); + } + }