Merge pull request #15760 from colemanw/iconPicker
[civicrm-core.git] / tests / phpunit / CRM / Contact / Page / View / UserDashBoardTest.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 class for CRM_Contact_Page_View_UserDashBoard
14 *
15 * @package CiviCRM
16 * @group headless
17 */
18 class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase {
19
20 use CRMTraits_Page_PageTestTrait;
21
22 /**
23 * Contact ID of logged in user.
24 *
25 * @var int
26 */
27 protected $contactID;
28
29 /**
30 * Contributions created for the test.
31 *
32 * @var array
33 */
34 protected $contributions = [];
35
36 /**
37 * Prepare for test
38 */
39 public function setUp() {
40 parent::setUp();
41 $this->contactID = $this->createLoggedInUser();
42 $this->listenForPageContent();
43 }
44
45 /**
46 * Clean up after each test.
47 */
48 public function tearDown() {
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]);
55 }
56
57 /**
58 * Test the content of the dashboard.
59 */
60 public function testDashboardContentEmptyContact() {
61 $this->runUserDashboard();
62 $expectedStrings = [
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.',
69 ];
70 $this->assertPageContains($expectedStrings);
71 }
72
73 /**
74 * Test the content of the dashboard.
75 */
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',
81 ]);
82 $this->contributions[] = $this->contributionCreate([
83 'contact_id' => $this->contactID,
84 'receive_date' => '2018-11-22',
85 'receipt_date' => '2018-11-23',
86 'trxn_id' => '',
87 'invoice_id' => '',
88 ]);
89 $this->contributions[] = $this->contributionCreate([
90 'contact_id' => $this->contactID,
91 'receive_date' => '2018-11-24',
92 'receipt_date' => '2018-11-24',
93 'trxn_id' => '',
94 'invoice_id' => '',
95 'contribution_status_id' => 'Pending',
96 ]);
97 $recur = $this->callAPISuccess('ContributionRecur', 'create', [
98 'contact_id' => $this->contactID,
99 'frequency_interval' => 1,
100 'amount' => 5,
101 ]);
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,
108 'trxn_id' => NULL,
109 'contribution_recur_id' => $recur['id'],
110 ]);
111 $this->callAPISuccess('Setting', 'create', ['invoicing' => 1]);
112 $this->callAPISuccess('Setting', 'create', ['default_invoice_page' => $this->contributionPageCreate()['id']]);
113 $this->runUserDashboard();
114 $expectedStrings = [
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>Status</th><th></th>',
117 '<td>Completed</td><td><a class="button no-popup nowrap"href="/index.php?q=civicrm/contribute/invoice&amp;reset=1&amp;id=1&amp;cid=' . $this->contactID . '"><i class="crm-i fa-print"></i><span>Print Invoice</span></a></td></tr><tr id=\'rowid2\'',
118 'Pay Now',
119 ];
120
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',
130 'currency' => 'USD',
131 'receipt_date' => '2018-11-22 00:00:00',
132 ]);
133
134 }
135
136 /**
137 * Test the content of the dashboard.
138 */
139 public function testDashboardContentContributions() {
140 $this->contributionCreate(['contact_id' => $this->contactID]);
141 $this->contributions[] = civicrm_api3('Contribution', 'get', [
142 'contact_id' => $this->contactID,
143 'options' => ['limit' => 12, 'sort' => 'receive_date DESC'],
144 'sequential' => 1,
145 ])['values'];
146 $this->runUserDashboard();
147 $expectedStrings = [
148 'Your Contribution(s)',
149 '<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Status</th>',
150 '<td>$ 100.00 </td><td>Donation</td>',
151 '<td>Completed</td>',
152 ];
153 $this->assertPageContains($expectedStrings);
154 }
155
156 /**
157 * Run the user dashboard.
158 */
159 protected function runUserDashboard() {
160 $_REQUEST = ['reset' => 1, 'id' => $this->contactID];
161 $dashboard = new CRM_Contact_Page_View_UserDashBoard();
162 $dashboard->_contactId = $this->contactID;
163 $dashboard->run();
164 $_REQUEST = [];
165 }
166
167 }