From 40c60cca9b4c0bc4e73b401258fbbe606e7b597e Mon Sep 17 00:00:00 2001 From: Saurabh Batra Date: Fri, 16 Oct 2015 22:29:02 +0530 Subject: [PATCH] Unit test for makeBatchSummary function final. --- CRM/Financial/Page/AJAX.php | 10 +++++++- .../Financial/Page/AjaxBatchSummaryTest.php | 25 +++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CRM/Financial/Page/AJAX.php b/CRM/Financial/Page/AJAX.php index f7a9a00dc4..871da971f4 100644 --- a/CRM/Financial/Page/AJAX.php +++ b/CRM/Financial/Page/AJAX.php @@ -524,12 +524,20 @@ class CRM_Financial_Page_AJAX { CRM_Utils_JSON::output($batchSummary); } + /** + * Makes an array of the batch's summary and returns array to parent getBatchSummary() function. + * + * @param $batchID + * @param $params + * + * @return array + */ public static function makeBatchSummary($batchID, $params) { $batchInfo = CRM_Batch_BAO_Batch::retrieve($params, $value); $batchTotals = CRM_Batch_BAO_Batch::batchTotals(array($batchID)); $batchSummary = array( 'created_by' => CRM_Contact_BAO_Contact::displayName($batchInfo->created_id), - 'status' => CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'batch_status_id', $batchInfo->status_id), + 'status' => CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'status_id', $batchInfo->status_id), 'description' => $batchInfo->description, 'payment_instrument' => CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $batchInfo->payment_instrument_id), 'item_count' => $batchInfo->item_count, diff --git a/tests/phpunit/CRM/Financial/Page/AjaxBatchSummaryTest.php b/tests/phpunit/CRM/Financial/Page/AjaxBatchSummaryTest.php index dee25639fc..6ec7b1e139 100644 --- a/tests/phpunit/CRM/Financial/Page/AjaxBatchSummaryTest.php +++ b/tests/phpunit/CRM/Financial/Page/AjaxBatchSummaryTest.php @@ -26,21 +26,24 @@ */ require_once 'CiviTest/CiviUnitTestCase.php'; +/** + * Test for CRM_Financial_Page_Ajax class. + */ class CRM_Financial_Page_AjaxBatchSummaryTest extends CiviUnitTestCase { - + /** + * Test the makeBatchSummary function. + * + * We want to ensure changing the meethod of obtaining status and payment_instrument + * does not cause any regression. + */ public function testMakeBatchSummary() { - $batch = $this->callAPISuccess('Batch', 'create', array('title' => 'test', 'status_id' => 'Open')); + $batch = $this->callAPISuccess('Batch', 'create', array('title' => 'test', 'status_id' => 'Open', 'payment_instrument_id' => 'Cash')); + $batchID = $batch['id']; $params = array('id' => $batchID); - - $test = array( - 'status' => 'some status', // how do i extract the batch's status? - 'payment_instrument' => 'some instrument', // how do i extract the batch's payment instrument? - ); - $makeBatchSummary = CRM_Financial_Page_AJAX::makeBatchSummary($batchID,$params); - $this->assertEquals($test['status'], $makeBatchSummary['status']); - $this->assertEquals($test['payment_instrument'], $makeBatchSummary['payment_instrument']); + $this->assertEquals('Open', $makeBatchSummary['status']); + $this->assertEquals('Cash', $makeBatchSummary['payment_instrument']); } -} \ No newline at end of file +} -- 2.25.1