From 6c8f579d9c1981be3f4ab62a4424c64b275ab57c Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 8 Feb 2023 14:26:56 +1100 Subject: [PATCH] dev/core#4068 Expand test coverage to include the contact summary report which is a non optimised report template --- CRM/Report/Form.php | 4 ++-- tests/phpunit/api/v3/ReportTemplateTest.php | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 0c401cae78..ee3cada4ec 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -3780,7 +3780,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND $smartGroupQuery = " UNION DISTINCT SELECT DISTINCT smartgroup_contact.contact_id FROM civicrm_group_contact_cache smartgroup_contact - INNER JOIN civicrm_group group ON group.id = smartgroup_contact.group_id + INNER JOIN `civicrm_group` AS `group` ON `group`.id = smartgroup_contact.group_id WHERE smartgroup_contact.group_id IN ({$smartGroups}) {$aclFilter}"; } @@ -3800,7 +3800,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND return " {$contactAlias}.id {$sqlOp} ( SELECT DISTINCT {$this->_aliases['civicrm_group']}.contact_id FROM civicrm_group_contact {$this->_aliases['civicrm_group']} - INNER JOIN civicrm_group group ON group.id = smartgroup_contact.group_id + INNER JOIN `civicrm_group` AS `group` ON `group`.id = {$this->_aliases['civicrm_group']}.group_id WHERE {$clause} AND {$this->_aliases['civicrm_group']}.status = 'Added' {$aclFilter} {$smartGroupQuery} ) "; } diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 73eb27a5e7..fb378c74b1 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -24,7 +24,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { protected $contactIDs = []; - protected $aclGroupId = NULL; + protected $aclGroupID = NULL; /** * Our group reports use an alter so transaction cleanup won't work. @@ -440,6 +440,11 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { return $templates; } + public static function getConactMenbershipAndContributionReportTemplatesForACLGroupTests(): array { + $templates = array_merge([['contact/summary']], self::getMembershipAndContributionReportTemplatesForGroupTests()); + return $templates; + } + /** * Test Lybunt report to check basic inclusion of a contact who gave in the year before the chosen year. * @@ -692,15 +697,15 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { /** * Test the group filter works on various reports when ACLed user is in play * - * @dataProvider getMembershipAndContributionReportTemplatesForGroupTests + * @dataProvider getConactMenbershipAndContributionReportTemplatesForACLGroupTests * * @param string $template * Report template unique identifier. * * @throws \CRM_Core_Exception */ - public function testReportsWithNonSmartGroupFilterWithACL($template) { - $this->aclGroupId = $this->setUpPopulatedGroup(); + public function testReportsWithNonSmartGroupFilterWithACL($template): void { + $this->aclGroupID = $this->setUpPopulatedGroup(); $this->createLoggedInUser(); CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; $this->callAPISuccessGetCount('Group', ['check_permissions' => 1], 0); @@ -709,7 +714,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { unset(Civi::$statics['CRM_ACL_API']['group_permission']); $rows = $this->callAPISuccess('report_template', 'getrows', [ 'report_id' => $template, - 'gid_value' => [$this->aclGroupId], + 'gid_value' => [$this->aclGroupID], 'gid_op' => 'in', 'options' => ['metadata' => ['sql']], ]); @@ -1816,7 +1821,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { * @param array $ids */ public function aclGroupOnly($type, $contactID, $tableName, $allGroups, &$ids) { - $ids = [$this->aclGroupId]; + $ids = [$this->aclGroupID]; } /** @@ -1832,7 +1837,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { if (!empty($where)) { $where .= ' AND '; } - $where .= 'contact_a.id IN (SELECT contact_id FROM civicrm_group_contact WHERE status = \'Added\' AND group_id = ' . $this->aclGroupId . ')'; + $where .= 'contact_a.id IN (SELECT contact_id FROM civicrm_group_contact WHERE status = \'Added\' AND group_id = ' . $this->aclGroupID . ')'; } } -- 2.25.1