9d879397d0e5f612f7ce97aab88a21b5436e7c93
[civicrm-core.git] / tests / phpunit / CRM / Financial / Page / AjaxTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Test for CRM_Financial_Page_Ajax class.
14 * @group headless
15 */
16 class CRM_Financial_Page_AjaxTest extends CiviUnitTestCase {
17
18 public function tearDown(): void {
19 $this->quickCleanUpFinancialEntities();
20 $this->quickCleanUp([
21 'civicrm_entity_batch',
22 'civicrm_batch',
23 ]);
24 parent::tearDown();
25 }
26
27 /**
28 * Test the ajax function to get financial transactions.
29 *
30 * Test focus is on ensuring changes to how labels are retrieved does not cause regression.
31 */
32 public function testGetFinancialTransactionsList() {
33 $individualID = $this->individualCreate();
34 $this->contributionCreate(['contact_id' => $individualID, 'trxn_id' => 12345]);
35 $batch = $this->callAPISuccess('Batch', 'create', ['title' => 'test', 'status_id' => 'Open']);
36 CRM_Core_DAO::executeQuery("
37 INSERT INTO civicrm_entity_batch (entity_table, entity_id, batch_id)
38 values('civicrm_financial_trxn', 1, 1)
39 ");
40 $_REQUEST['sEcho'] = 1;
41 $_REQUEST['entityID'] = $batch['id'];
42 $_REQUEST['return'] = TRUE;
43 $json = CRM_Financial_Page_AJAX::getFinancialTransactionsList();
44 $json = str_replace(rtrim(CIVICRM_UF_BASEURL, '/'), 'http://FIX ME', $json);
45 $this->assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","<a href=\"/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3\" data-tooltip-url=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1\" class=\"crm-summary-link\"><div'
46 . ' 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","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",'
47 . '"Credit Card","Completed","Donation","<span><a href=\"/index.php?q=civicrm/contact/view/contribution&amp;reset=1&amp;id=1&amp;cid=3&amp;action=view&amp;context=contribution&amp;'
48 . 'selectedChild=contribute\" class=\"action-item crm-hover-button\" title=\'View Contribution\' >View</a></span>"]] }', $json);
49 }
50
51 /**
52 * Test getting open batch.
53 */
54 public function testGetFinancialTransactionsListOpenBatch() {
55 $individualID = $this->individualCreate();
56 $this->contributionCreate(['contact_id' => $individualID, 'trxn_id' => 12345]);
57 $batch = $this->callAPISuccess('Batch', 'create', ['title' => 'test', 'status_id' => 'Open']);
58 CRM_Core_DAO::executeQuery("
59 INSERT INTO civicrm_entity_batch (entity_table, entity_id, batch_id)
60 values('civicrm_financial_trxn', 1, 1)
61 ");
62 $_REQUEST['sEcho'] = 1;
63 $_REQUEST['entityID'] = $batch['id'];
64 $_REQUEST['statusID'] = 1;
65 $_REQUEST['notPresent'] = 1;
66 $_REQUEST['return'] = TRUE;
67 $json = CRM_Financial_Page_AJAX::getFinancialTransactionsList();
68 $json = str_replace(rtrim(CIVICRM_UF_BASEURL, '/'), 'http://FIX ME', $json);
69 $this->assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["<input type=\'checkbox\' id=\'mark_x_2\' name=\'mark_x_2\' value=\'1\' onclick=enableActions(\'x\')></input>","<a href=\"/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3\" data-tooltip-url=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1\" class=\"crm-summary-link\"><div'
70 . ' 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>","$ 5.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",'
71 . '"Credit Card","Completed","Donation","<span><a href=\"/index.php?q=civicrm/contact/view/contribution&amp;reset=1&amp;id=1&amp;cid=3&amp;action=view&amp;context=contribution&amp;'
72 . 'selectedChild=contribute\" class=\"action-item crm-hover-button\" title=\'View Contribution\' >View</a><a href=\"#\" class=\"action-item crm-hover-button disable-action\" title=\'Assign Transaction\' onclick = \"assignRemove( 2,\'assign\' );\">Assign</a></span>"]] }', $json);
73 }
74
75 }