From 478c39cf7cc914cf285c8e6d177e857557a85d6d Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Fri, 4 Sep 2015 11:37:46 +1200 Subject: [PATCH] CRM-17120 add test to getFinancialTransactionsList function --- CRM/Financial/Page/AJAX.php | 13 ++++- tests/phpunit/CRM/Financial/Page/AjaxTest.php | 56 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/CRM/Financial/Page/AjaxTest.php 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"]] }'); + } + +} -- 2.25.1