From 9698bf7bb2438567a76ca6ec029d0c1ea757d193 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Mon, 6 Dec 2021 19:57:48 -0500 Subject: [PATCH] deprecated money-formatting of non-numeric --- CRM/Report/Form/Contribute/Repeat.php | 4 +-- tests/phpunit/api/v3/ReportTemplateTest.php | 40 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/CRM/Report/Form/Contribute/Repeat.php b/CRM/Report/Form/Contribute/Repeat.php index 3ec045ca10..3f3bc2d6d9 100644 --- a/CRM/Report/Form/Contribute/Repeat.php +++ b/CRM/Report/Form/Contribute/Repeat.php @@ -175,7 +175,7 @@ class CRM_Report_Form_Contribute_Repeat extends CRM_Report_Form { 'name' => 'total_amount', 'alias' => 'contribution1', 'title' => ts('Range One Stat'), - 'type' => CRM_Utils_Type::T_MONEY, + 'type' => CRM_Utils_Type::T_STRING, 'default' => TRUE, 'required' => TRUE, 'clause' => 'contribution_civireport1.total_amount_count as contribution1_total_amount_count, contribution_civireport1.total_amount_sum as contribution1_total_amount_sum', @@ -184,7 +184,7 @@ class CRM_Report_Form_Contribute_Repeat extends CRM_Report_Form { 'name' => 'total_amount', 'alias' => 'contribution2', 'title' => ts('Range Two Stat'), - 'type' => CRM_Utils_Type::T_MONEY, + 'type' => CRM_Utils_Type::T_STRING, 'default' => TRUE, 'required' => TRUE, 'clause' => 'contribution_civireport2.total_amount_count as contribution2_total_amount_count, contribution_civireport2.total_amount_sum as contribution2_total_amount_sum', diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index e246c4e145..6722019768 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -1650,6 +1650,46 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $this->callAPISuccess('Contact', 'delete', ['id' => $contact]); } + /** + * Basic test of the repeat contributions report. + */ + public function testRepeatContributions() { + // our sorting options are limited in this report - default is last name so let's ensure order + $contact1 = $this->individualCreate(['last_name' => 'aaaaa']); + $contact2 = $this->individualCreate(['last_name' => 'zzzzz']); + $this->contributionCreate(['contact_id' => $contact1, 'receive_date' => (date('Y') - 1) . '-07-01', 'financial_type_id' => 1, 'total_amount' => '10']); + $this->contributionCreate(['contact_id' => $contact1, 'receive_date' => (date('Y') - 1) . '-08-01', 'financial_type_id' => 1, 'total_amount' => '20']); + $this->contributionCreate(['contact_id' => $contact1, 'receive_date' => date('Y') . '-01-01', 'financial_type_id' => 1, 'total_amount' => '40']); + $this->contributionCreate(['contact_id' => $contact2, 'receive_date' => (date('Y') - 1) . '-09-01', 'financial_type_id' => 1, 'total_amount' => '80']); + $rows = $this->callAPISuccess('report_template', 'getrows', [ + 'report_id' => 'contribute/repeat', + 'receive_date1' => 'previous.year', + 'receive_date2' => 'this.year', + 'fields' => [ + 'sort_name' => 1, + ], + ]); + + $this->assertCount(2, $rows['values']); + + // Should have for both this year and last, and last year was multiple. + $this->assertEquals($contact1, $rows['values'][0]['contact_civireport_id'], "doesn't seem to be the right contact 1"); + $this->assertSame('30.00', $rows['values'][0]['contribution1_total_amount_sum']); + $this->assertSame('2', $rows['values'][0]['contribution1_total_amount_count']); + $this->assertSame('40.00', $rows['values'][0]['contribution2_total_amount_sum']); + $this->assertSame('1', $rows['values'][0]['contribution2_total_amount_count']); + + // Should only have for last year. + $this->assertEquals($contact2, $rows['values'][1]['contact_civireport_id'], "doesn't seem to be the right contact 2"); + $this->assertSame('80.00', $rows['values'][1]['contribution1_total_amount_sum']); + $this->assertSame('1', $rows['values'][1]['contribution1_total_amount_count']); + $this->assertNull($rows['values'][1]['contribution2_total_amount_sum']); + $this->assertNull($rows['values'][1]['contribution2_total_amount_count']); + + $this->callAPISuccess('Contact', 'delete', ['id' => $contact1]); + $this->callAPISuccess('Contact', 'delete', ['id' => $contact2]); + } + /** * Convoluted test of the convoluted logging detail report. * -- 2.25.1