CRM-17120 add test to getFinancialTransactionsList function
authoreileenmcnaugton <eileen@fuzion.co.nz>
Thu, 3 Sep 2015 23:37:46 +0000 (11:37 +1200)
committermonishdeb <monish.deb@webaccessglobal.com>
Wed, 9 Sep 2015 14:50:31 +0000 (20:20 +0530)
CRM/Financial/Page/AJAX.php
tests/phpunit/CRM/Financial/Page/AjaxTest.php [new file with mode: 0644]

index 68a20128032587241b38352a6b00c7e7717329e8..6b6fd425ad72edf101bd507beb64e9415ef1b71b 100644 (file)
@@ -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 (file)
index 0000000..42a5b6c
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+require_once 'CiviTest/CiviUnitTestCase.php';
+
+/**
+ * Test for CRM_Financial_Page_Ajax class.
+ */
+class CRM_Financial_Page_AjaxTest extends CiviUnitTestCase {
+
+  /**
+   * Test the ajax function to get financial transactions.
+   *
+   * Test focus is on ensuring changes to how labels are retrieved does not cause regression.
+   */
+  public function testGetFinancialTransactionsList() {
+    $individualID = $this->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": [ ["","<a href=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4\" class=\"crm-summary-link\"><div'
+    . ' class=\"icon crm-icon Individual-icon\"></div></a>","<a href=/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3>Anderson, Anthony</a>","$ 100.00","12345","September 3rd, 2015 12:00 AM",'
+    . '"Credit Card","Completed","Donation","<span><a href=\"http://FIX ME/index.php?q=civicrm/contact/view/contribution&amp;reset=1&amp;id=1&amp;cid=3&amp;action=view&amp;context=contribution&amp;'
+    . 'selectedChild=contribute\" class=\"action-item crm-hover-button\" title=\'View Contribution\' >View</a></span>"]] }');
+  }
+
+}