Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Add test for to time processing #16861

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/phpunit/api/v3/ReportTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ public function testLybuntReportWithFYDataOrderByLastYearAmount() {
*
* @param string $template
* Name of the template to test.
*
* @throws \CRM_Core_Exception
*/
public function testContributionSummaryWithSmartGroupFilter($template) {
$groupID = $this->setUpPopulatedSmartGroup();
Expand Down Expand Up @@ -788,6 +790,8 @@ public function testContributionSummaryWithSingleContactsInTwoGroups() {

/**
* Test the group filter works on the contribution summary when 2 groups are involved.
*
* @throws \CRM_Core_Exception
*/
public function testContributionSummaryWithTwoGroupsWithIntersection() {
$groups = $this->setUpIntersectingGroups();
Expand All @@ -801,6 +805,36 @@ public function testContributionSummaryWithTwoGroupsWithIntersection() {
$this->assertEquals(7, $rows['values'][0]['civicrm_contribution_total_amount_count']);
}

/**
* Test date field is correctly handled.
*
* @throws \CRM_Core_Exception
*/
public function testContributionSummaryDateFields() {
$sql = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contribute/summary',
'thankyou_date_relative' => '0',
'thankyou_date_from' => '2020-03-01 00:00:00',
'thankyou_date_to' => '2020-03-31 23:59:59',
'options' => ['metadata' => ['sql']],
])['metadata']['sql'];
$expectedSql = 'SELECT contact_civireport.id as civicrm_contact_id, DATE_SUB(contribution_civireport.receive_date, INTERVAL (DAYOFMONTH(contribution_civireport.receive_date)-1) DAY) as civicrm_contribution_receive_date_start, MONTH(contribution_civireport.receive_date) AS civicrm_contribution_receive_date_subtotal, MONTHNAME(contribution_civireport.receive_date) AS civicrm_contribution_receive_date_interval, contribution_civireport.currency as civicrm_contribution_currency, COUNT(contribution_civireport.total_amount) as civicrm_contribution_total_amount_count, SUM(contribution_civireport.total_amount) as civicrm_contribution_total_amount_sum, ROUND(AVG(contribution_civireport.total_amount),2) as civicrm_contribution_total_amount_avg, address_civireport.country_id as civicrm_address_country_id FROM civicrm_contact contact_civireport
INNER JOIN civicrm_contribution contribution_civireport
ON contact_civireport.id = contribution_civireport.contact_id AND
contribution_civireport.is_test = 0
LEFT JOIN civicrm_contribution_soft contribution_soft_civireport
ON contribution_soft_civireport.contribution_id = contribution_civireport.id AND contribution_soft_civireport.id = (SELECT MIN(id) FROM civicrm_contribution_soft cs WHERE cs.contribution_id = contribution_civireport.id)
LEFT JOIN civicrm_financial_type financial_type_civireport
ON contribution_civireport.financial_type_id =financial_type_civireport.id

LEFT JOIN civicrm_address address_civireport
ON (contact_civireport.id =
address_civireport.contact_id) AND
address_civireport.is_primary = 1
WHERE ( contribution_civireport.thankyou_date >= 20200301000000) AND ( contribution_civireport.thankyou_date <= 20200331235959) AND ( contribution_civireport.contribution_status_id IN (1) ) GROUP BY EXTRACT(YEAR_MONTH FROM contribution_civireport.receive_date), contribution_civireport.contribution_status_id LIMIT 25';
$this->assertLike($expectedSql, $sql[0]);
}

/**
* Set up a smart group for testing.
*
Expand Down