From: jitendrapurohit Date: Fri, 16 Dec 2016 12:31:42 +0000 (+0530) Subject: CRM-19591: Creating a pledge with only one instalment will cause pledge payment to... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=43b786725ad679fe018b5925b26cb05af6ce3ee5;p=civicrm-core.git CRM-19591: Creating a pledge with only one instalment will cause pledge payment to have a null status (and cannot record a payment) --- diff --git a/CRM/Pledge/BAO/Pledge.php b/CRM/Pledge/BAO/Pledge.php index c8594c0618..6e5371c793 100644 --- a/CRM/Pledge/BAO/Pledge.php +++ b/CRM/Pledge/BAO/Pledge.php @@ -154,7 +154,6 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge { $transaction = new CRM_Core_Transaction(); $paymentParams = array(); - $paymentParams['status_id'] = CRM_Utils_Array::value('status_id', $params); if (!empty($params['installment_amount'])) { $params['amount'] = $params['installment_amount'] * $params['installments']; } @@ -174,6 +173,7 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge { } } } + $paymentParams['status_id'] = CRM_Utils_Array::value('status_id', $params); $pledge = self::add($params); if (is_a($pledge, 'CRM_Core_Error')) { diff --git a/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php b/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php index 2e07bb2fdb..77a21be518 100644 --- a/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php +++ b/tests/phpunit/CRM/Pledge/BAO/PledgeTest.php @@ -40,20 +40,7 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { protected function setUp() { parent::setUp(); $this->_contactId = $this->individualCreate(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() { - } - - /** - * Test for Add/Update Pledge. - */ - public function testAdd() { - $params = array( + $this->_params = array( 'contact_id' => $this->_contactId, 'frequency_unit' => 'month', 'original_installment_amount' => 25.00, @@ -68,15 +55,46 @@ class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { 'currency' => 'USD', 'amount' => 300, ); + } + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() { + } + + /** + * Test for Add/Update Pledge. + */ + public function testAdd() { //do test for normal add. - $pledge = CRM_Pledge_BAO_Pledge::add($params); + $pledge = CRM_Pledge_BAO_Pledge::add($this->_params); - foreach ($params as $param => $value) { + foreach ($this->_params as $param => $value) { $this->assertEquals($value, $pledge->$param); } } + /** + * Test Pledge Payment Status with 1 installment + * and not passing status id. + */ + public function testPledgePaymentStatus() { + $scheduledDate = date('Ymd', mktime(0, 0, 0, date("m"), date("d") + 2, date("y"))); + $this->_params['installments'] = 1; + $this->_params['scheduled_date'] = $scheduledDate; + + unset($this->_params['status_id']); + $pledge = CRM_Pledge_BAO_Pledge::create($this->_params); + $pledgePayment = CRM_Pledge_BAO_PledgePayment::getPledgePayments($pledge->id); + + $this->assertEquals(count($pledgePayment), 1); + $payment = array_pop($pledgePayment); + $this->assertEquals($payment['status'], 'Pending'); + $this->assertEquals($payment['scheduled_date'], date('Y-m-d 00:00:00', strtotime($scheduledDate))); + } + /** * Retrieve a pledge based on a pledge id = 0 */