From: eileenmcnaugton Date: Thu, 3 Sep 2015 23:37:46 +0000 (+1200) Subject: CRM-17120 add test to getFinancialTransactionsList function X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=478c39cf7cc914cf285c8e6d177e857557a85d6d;p=civicrm-core.git CRM-17120 add test to getFinancialTransactionsList function --- diff --git a/CRM/Financial/Page/AJAX.php b/CRM/Financial/Page/AJAX.php index 68a2012803..6b6fd425ad 100644 --- a/CRM/Financial/Page/AJAX.php +++ b/CRM/Financial/Page/AJAX.php @@ -261,7 +261,15 @@ class CRM_Financial_Page_AJAX { CRM_Utils_JSON::output($response); } - public static function getFinancialTransactionsList() { + /** + * Get output of financial transactions. + * + * @param bool $return + * Return result. This parameter allows the output to be unit tested. + * + * @return string + */ + public static function getFinancialTransactionsList($return = FALSE) { $sortMapper = array( 0 => '', 1 => '', @@ -463,6 +471,9 @@ class CRM_Financial_Page_AJAX { 'action', ); + if ($return) { + return CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); + } CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); diff --git a/tests/phpunit/CRM/Financial/Page/AjaxTest.php b/tests/phpunit/CRM/Financial/Page/AjaxTest.php new file mode 100644 index 0000000000..42a5b6c508 --- /dev/null +++ b/tests/phpunit/CRM/Financial/Page/AjaxTest.php @@ -0,0 +1,56 @@ +individualCreate(); + $this->contributionCreate($individualID); + $batch = $this->callAPISuccess('Batch', 'create', array('title' => 'test', 'status_id' => 'Open')); + CRM_Core_DAO::executeQuery(" + INSERT INTO civicrm_entity_batch (entity_table, entity_id, batch_id) + values('civicrm_financial_trxn', 1, 1) + "); + $_REQUEST['sEcho'] = 1; + $_REQUEST['entityID'] = $batch['id']; + $json = CRM_Financial_Page_AJAX::getFinancialTransactionsList(TRUE); + $this->assertEquals($json, '{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","","Anderson, Anthony","$ 100.00","12345","September 3rd, 2015 12:00 AM",' + . '"Credit Card","Completed","Donation","View"]] }'); + } + +}