3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Test class for CRM_Contact_Page_View_UserDashBoard
18 class CRM_Contact_Page_View_UserDashBoardTest
extends CiviUnitTestCase
{
20 use CRMTraits_Page_PageTestTrait
;
23 * Contact ID of logged in user.
30 * Contributions created for the test.
34 protected $contributions = [];
39 public function setUp(): void
{
41 $this->contactID
= $this->createLoggedInUser();
42 $this->listenForPageContent();
46 * Clean up after each test.
48 public function tearDown(): void
{
49 $this->quickCleanUpFinancialEntities();
50 $this->quickCleanup(['civicrm_uf_match']);
51 CRM_Utils_Hook
::singleton()->reset();
52 CRM_Core_Session
::singleton()->reset();
53 CRM_Core_Smarty
::singleton()->clearTemplateVars();
54 $this->callAPISuccess('Contact', 'delete', ['id' => $this->contactID
]);
58 * Test the content of the dashboard.
60 public function testDashboardContentEmptyContact() {
61 $this->runUserDashboard();
63 'You are not currently subscribed to any Groups',
64 'There are no contributions on record for you.',
65 'There are no Pledges for your record.',
66 'You are not registered for any current or upcoming Events.',
67 'There are no memberships on record for you.',
68 'You do not have any active Personal Campaign pages.',
70 $this->assertPageContains($expectedStrings);
74 * Test the content of the dashboard.
76 public function testDashboardContentContributionsWithInvoicingEnabled() {
77 $this->contributions
[] = $this->contributionCreate([
78 'contact_id' => $this->contactID
,
79 'receive_date' => '2018-11-21',
80 'receipt_date' => '2018-11-22',
82 $this->contributions
[] = $this->contributionCreate([
83 'contact_id' => $this->contactID
,
84 'receive_date' => '2018-11-22',
85 'receipt_date' => '2018-11-23',
89 $this->contributions
[] = $this->contributionCreate([
90 'contact_id' => $this->contactID
,
91 'receive_date' => '2018-11-24',
92 'receipt_date' => '2018-11-24',
95 'contribution_status_id' => 'Pending',
97 $recur = $this->callAPISuccess('ContributionRecur', 'create', [
98 'contact_id' => $this->contactID
,
99 'frequency_interval' => 1,
102 $this->contributions
[] = $this->contributionCreate([
103 'contact_id' => $this->contactID
,
104 'receive_date' => '2018-11-20',
105 'amount_level' => 'high',
106 'contribution_status_id' => 'Cancelled',
107 'invoice_id' => NULL,
109 'contribution_recur_id' => $recur['id'],
111 $this->callAPISuccess('Setting', 'create', ['invoicing' => 1]);
112 $this->callAPISuccess('Setting', 'create', ['default_invoice_page' => $this->contributionPageCreate()['id']]);
113 $this->runUserDashboard();
115 'Your Contribution(s)',
116 '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th><th></th>',
117 '<td>Completed</td><td><a class="button no-popup nowrap"href="/index.php?q=civicrm/contribute/invoice&reset=1&id=1&cid=' . $this->contactID
. '"><i class="crm-i fa-download" aria-hidden="true"></i><span>Download Invoice</span></a></td></tr><tr id=\'rowid2\'',
121 $this->assertPageContains($expectedStrings);
122 $this->assertSmartyVariableArrayIncludes('contribute_rows', 1, [
123 'contact_id' => $this->contactID
,
124 'contribution_id' => '1',
125 'total_amount' => '100.00',
126 'financial_type' => 'Donation',
127 'contribution_source' => 'SSF',
128 'receive_date' => '2018-11-21 00:00:00',
129 'contribution_status' => 'Completed',
131 'receipt_date' => '2018-11-22 00:00:00',
137 * Test the content of the dashboard.
139 * @throws \CRM_Core_Exception
140 * @throws \CiviCRM_API3_Exception
142 public function testDashboardContentContributions() {
143 $this->contributionCreate(['contact_id' => $this->contactID
]);
144 $this->contributions
[] = civicrm_api3('Contribution', 'get', [
145 'contact_id' => $this->contactID
,
146 'options' => ['limit' => 12, 'sort' => 'receive_date DESC'],
149 $this->runUserDashboard();
151 'Your Contribution(s)',
152 '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th>',
153 '<td>$ 100.00 </td><td>Donation</td>',
154 '<td>Completed</td>',
156 $this->assertPageContains($expectedStrings);
160 * Test the presence of a "Pay Now" button on partial payments
162 * @throws \CRM_Core_Exception
163 * @throws \CiviCRM_API3_Exception
165 public function testDashboardPartialPayments() {
166 $contributionId = $this->contributionCreate([
167 'contact_id' => $this->contactID
,
168 'contribution_status_id' => 'Pending',
169 'total_amount' => 25,
171 $result = civicrm_api3('Payment', 'create', [
172 'contribution_id' => $contributionId,
173 'total_amount' => 11,
174 'trxn_date' => "2021-05-11",
176 $this->contributions
[] = civicrm_api3('Contribution', 'get', [
177 'contact_id' => $this->contactID
,
178 'options' => ['limit' => 12, 'sort' => 'receive_date DESC'],
181 $this->runUserDashboard();
183 'Your Contribution(s)',
184 '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th>',
185 '<td>$ 25.00 </td><td>Donation</td>',
186 '<td>$ 14.00</td><td>Partially paid</td>',
189 $this->assertPageContains($expectedStrings);
193 * Run the user dashboard.
195 protected function runUserDashboard() {
196 $_REQUEST = ['reset' => 1, 'id' => $this->contactID
];
197 $dashboard = new CRM_Contact_Page_View_UserDashBoard();
198 $dashboard->_contactId
= $this->contactID
;
199 $dashboard->assign('formTpl', NULL);
200 $dashboard->assign('action', CRM_Core_Action
::VIEW
);
206 * Tests the event dashboard as a minimally permissioned user.
208 public function testEventDashboard() {
209 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= [
210 'register for events',
211 'access Contact Dashboard',
213 $event1id = $this->eventCreate()['id'];
214 $event2id = $this->eventCreate(['title' => 'Social Distancing Meetup Group'])['id'];
215 $params['contact_id'] = $this->contactID
;
216 $params['event_id'] = $event1id;
217 $this->participantCreate($params);
218 $params['event_id'] = $event2id;
219 $this->participantCreate($params);
220 $this->runUserDashboard();
222 '<div class="header-dark">Your Event(s)</div>',
223 '<td class="crm-participant-event-id_1"><a href="/index.php?q=civicrm/event/info&reset=1&id=1&context=dashboard">Annual CiviCRM meet</a></td>',
224 '<td class="crm-participant-event-id_2"><a href="/index.php?q=civicrm/event/info&reset=1&id=2&context=dashboard">Social Distancing Meetup Group</a></td>',
226 $this->assertPageContains($expectedStrings);
227 $this->individualCreate();