Merge pull request #11642 from JKingsnorth/CRM-21739
[civicrm-core.git] / tests / phpunit / api / v3 / PledgePaymentTest.php
index 8b03ae5d1837334e36c00a0fd818ce02813411c1..c1e36869983ff66fe7109b623c81c4171ee9cdcb 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -87,6 +87,41 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase {
     $this->assertEquals(1, $result['count'], " in line " . __LINE__);
   }
 
+  /**
+   * Test process_pledge job log.
+   */
+  public function testProcessPledgeJob() {
+    $pledgeStatuses = CRM_Core_OptionGroup::values('pledge_status',
+      FALSE, FALSE, FALSE, NULL, 'name'
+    );
+    //Make first payment.
+    $paymentParams = array(
+      'contact_id' => $this->_individualId,
+      'pledge_id' => $this->_pledgeID,
+      'contribution_id' => $this->_contributionID,
+      'scheduled_date' => date('Ymd', strtotime("-1 days")),
+      'status_id' => array_search('Pending', $pledgeStatuses),
+    );
+    $firstPayment = $this->callAPISuccess('pledge_payment', 'create', $paymentParams);
+    //Status should be 'Pending' after first incomplete payment.
+    $checkStatus = $this->callAPISuccess('pledge', 'getsingle', array(
+      'id' => $this->_pledgeID,
+      'return' => 'pledge_status',
+    ));
+    $this->assertEquals('Pending', $checkStatus['pledge_status']);
+
+    //Execute process_pledge job log.
+    $result = $this->callAPISuccess('Job', 'process_pledge', array());
+    $this->assertEquals("Checking if status update is needed for Pledge Id: {$this->_pledgeID} (current status is Pending)\n\r- status updated to: Overdue\n\r1 records updated.", $result['values']);
+
+    //Status should be 'Overdue' after processing.
+    $statusAfterProcessing = $this->callAPISuccess('pledge', 'getsingle', array(
+      'id' => $this->_pledgeID,
+      'return' => 'pledge_status',
+    ));
+    $this->assertEquals('Overdue', $statusAfterProcessing['pledge_status']);
+  }
+
   /**
    * Test status of pledge on payments and cancellation.
    */