3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | Use of this source code is governed by the AGPL license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class CRM_Contribute_Page_AjaxTest
16 class CRM_Contribute_Page_AjaxTest
extends CiviUnitTestCase
{
18 protected $_params = [];
20 public function setUp() {
23 $this->_fields
= ['amount', 'sct_label'];
31 'is_unit_test' => TRUE,
33 $softContactParams = [
34 'first_name' => 'soft',
35 'last_name' => 'Contact',
37 $this->_softContactId
= $this->individualCreate($softContactParams);
39 //create three sample contacts
40 foreach ([0, 1, 2] as $seq) {
41 $this->_primaryContacts
[] = $this->individualCreate([], $seq);
46 * Test retrieve Soft Contribution through AJAX
48 public function testGetSoftContributionSelector() {
49 $softTypes = [3, 2, 5];
50 $amounts = ['100', '600', '150'];
52 // create sample soft contribution for contact
53 foreach ($this->_primaryContacts
as $seq => $contactId) {
54 $this->callAPISuccess('Contribution', 'create', [
55 'contact_id' => $contactId,
56 'receive_date' => date('Ymd'),
57 'total_amount' => $amounts[$seq],
58 'financial_type_id' => 1,
59 'non_deductible_amount' => '10',
60 'contribution_status_id' => 1,
63 'contact_id' => $this->_softContactId
,
64 'amount' => $amounts[$seq],
65 'soft_credit_type_id' => $softTypes[$seq],
71 $_GET = array_merge($this->_params
,
73 'cid' => $this->_softContactId
,
74 'context' => 'contribution',
77 $softCreditList = CRM_Contribute_Page_AJAX
::getSoftContributionRows();
79 foreach ($this->_fields
as $columnName) {
80 $_GET['columns'][] = [
81 'data' => $columnName,
84 // get the results in descending order
91 $amountSortedList = CRM_Contribute_Page_AJAX
::getSoftContributionRows();
93 $this->assertEquals(3, $softCreditList['recordsTotal']);
94 $this->assertEquals(3, $amountSortedList['recordsTotal']);
96 foreach ($amounts as $key => $amount) {
97 $amount = CRM_Utils_Money
::format($amount, 'USD');
98 $this->assertEquals($amount, $amountSortedList['data'][$key]['amount']);
101 // sort with soft credit types
102 $_GET['order'][0]['column'] = 1;
103 foreach ($softTypes as $id) {
104 $softLabels[] = CRM_Core_PseudoConstant
::getLabel('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', $id);
107 $softTypeSortedList = CRM_Contribute_Page_AJAX
::getSoftContributionRows();
108 foreach ($softLabels as $key => $labels) {
109 $this->assertEquals($labels, $softTypeSortedList['data'][$key]['sct_label']);
114 * Test retrieve Soft Contribution For Membership
116 public function testGetSoftContributionForMembership() {
117 //Check soft credit for membership
119 'contribution_contact_id' => $this->_primaryContacts
[0],
120 'contact_id' => $this->_softContactId
,
121 'contribution_status_id' => 1,
122 'financial_type_id' => 2,
124 'total_amount' => 100,
125 'receive_date' => '2018-06-08',
127 'soft_credit_type_id' => 11,
128 'contact_id' => $this->_softContactId
,
131 $_GET = array_merge($this->_params
,
133 'cid' => $this->_softContactId
,
134 'context' => 'membership',
135 'entityID' => $this->contactMembershipCreate($memParams),
139 $softCreditList = CRM_Contribute_Page_AJAX
::getSoftContributionRows();
140 $this->assertEquals(1, $softCreditList['recordsTotal']);
141 $this->assertEquals('Gift', $softCreditList['data'][0]['sct_label']);
142 $this->assertEquals('$ 100.00', $softCreditList['data'][0]['amount']);
143 $this->assertEquals('Member Dues', $softCreditList['data'][0]['financial_type']);