contactID = $this->createLoggedInUser();
$this->listenForPageContent();
}
/**
* Clean up after each test.
*/
public function tearDown(): void {
$this->quickCleanUpFinancialEntities();
$this->quickCleanup(['civicrm_uf_match']);
CRM_Utils_Hook::singleton()->reset();
CRM_Core_Session::singleton()->reset();
CRM_Core_Smarty::singleton()->clearTemplateVars();
$this->callAPISuccess('Contact', 'delete', ['id' => $this->contactID]);
}
/**
* Test the content of the dashboard.
*/
public function testDashboardContentEmptyContact() {
$this->runUserDashboard();
$expectedStrings = [
'You are not currently subscribed to any Groups',
'There are no contributions on record for you.',
'There are no Pledges for your record.',
'You are not registered for any current or upcoming Events.',
'There are no memberships on record for you.',
'You do not have any active Personal Campaign pages.',
];
$this->assertPageContains($expectedStrings);
}
/**
* Test the content of the dashboard.
*/
public function testDashboardContentContributionsWithInvoicingEnabled() {
$this->contributions[] = $this->contributionCreate([
'contact_id' => $this->contactID,
'receive_date' => '2018-11-21',
'receipt_date' => '2018-11-22',
]);
$this->contributions[] = $this->contributionCreate([
'contact_id' => $this->contactID,
'receive_date' => '2018-11-22',
'receipt_date' => '2018-11-23',
'trxn_id' => '',
'invoice_id' => '',
]);
$this->contributions[] = $this->contributionCreate([
'contact_id' => $this->contactID,
'receive_date' => '2018-11-24',
'receipt_date' => '2018-11-24',
'trxn_id' => '',
'invoice_id' => '',
'contribution_status_id' => 'Pending',
]);
$recur = $this->callAPISuccess('ContributionRecur', 'create', [
'contact_id' => $this->contactID,
'frequency_interval' => 1,
'amount' => 5,
]);
$this->contributions[] = $this->contributionCreate([
'contact_id' => $this->contactID,
'receive_date' => '2018-11-20',
'amount_level' => 'high',
'contribution_status_id' => 'Cancelled',
'invoice_id' => NULL,
'trxn_id' => NULL,
'contribution_recur_id' => $recur['id'],
]);
$this->callAPISuccess('Setting', 'create', ['invoicing' => 1]);
$this->callAPISuccess('Setting', 'create', ['default_invoice_page' => $this->contributionPageCreate()['id']]);
$this->runUserDashboard();
$expectedStrings = [
'Your Contribution(s)',
'
Total Amount | Financial Type | Received date | Receipt Sent | Balance | Status | | ',
'Completed | |
---|
assertPageContains($expectedStrings);
$this->assertSmartyVariableArrayIncludes('contribute_rows', 1, [
'contact_id' => $this->contactID,
'contribution_id' => '1',
'total_amount' => '100.00',
'financial_type' => 'Donation',
'contribution_source' => 'SSF',
'receive_date' => '2018-11-21 00:00:00',
'contribution_status' => 'Completed',
'currency' => 'USD',
'receipt_date' => '2018-11-22 00:00:00',
]);
}
/**
* Test the content of the dashboard.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testDashboardContentContributions() {
$this->contributionCreate(['contact_id' => $this->contactID]);
$this->contributions[] = civicrm_api3('Contribution', 'get', [
'contact_id' => $this->contactID,
'options' => ['limit' => 12, 'sort' => 'receive_date DESC'],
'sequential' => 1,
])['values'];
$this->runUserDashboard();
$expectedStrings = [
'Your Contribution(s)',
'Total Amount | Financial Type | Received date | Receipt Sent | Balance | Status | ',
'$ 100.00 | Donation | ',
'Completed | ',
];
$this->assertPageContains($expectedStrings);
}
/**
* Test the presence of a "Pay Now" button on partial payments
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testDashboardPartialPayments() {
$contributionId = $this->contributionCreate([
'contact_id' => $this->contactID,
'contribution_status_id' => 'Pending',
'total_amount' => 25,
]);
$result = civicrm_api3('Payment', 'create', [
'contribution_id' => $contributionId,
'total_amount' => 11,
'trxn_date' => "2021-05-11",
]);
$this->contributions[] = civicrm_api3('Contribution', 'get', [
'contact_id' => $this->contactID,
'options' => ['limit' => 12, 'sort' => 'receive_date DESC'],
'sequential' => 1,
])['values'];
$this->runUserDashboard();
$expectedStrings = [
'Your Contribution(s)',
'Total Amount | Financial Type | Received date | Receipt Sent | Balance | Status | ',
'$ 25.00 | Donation | ',
'$ 14.00 | Partially paid | ',
'Pay Now',
];
$this->assertPageContains($expectedStrings);
}
/**
* Run the user dashboard.
*/
protected function runUserDashboard() {
$_REQUEST = ['reset' => 1, 'id' => $this->contactID];
$dashboard = new CRM_Contact_Page_View_UserDashBoard();
$dashboard->_contactId = $this->contactID;
$dashboard->run();
$_REQUEST = [];
}
/**
* Tests the event dashboard as a minimally permissioned user.
*/
public function testEventDashboard() {
CRM_Core_Config::singleton()->userPermissionClass->permissions = [
'register for events',
'access Contact Dashboard',
];
$event1id = $this->eventCreate()['id'];
$event2id = $this->eventCreate(['title' => 'Social Distancing Meetup Group'])['id'];
$params['contact_id'] = $this->contactID;
$params['event_id'] = $event1id;
$this->participantCreate($params);
$params['event_id'] = $event2id;
$this->participantCreate($params);
$this->runUserDashboard();
$expectedStrings = [
'',
'Annual CiviCRM meet | ',
'Social Distancing Meetup Group | ',
];
$this->assertPageContains($expectedStrings);
$this->individualCreate();
}
}
---|
---|