From 6af3aebd28f04d8122cceec15ac21049f1a7f2b6 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 13 Jan 2022 14:22:46 +1300 Subject: [PATCH] Add test to cover building a membership permission --- CRM/Financial/BAO/FinancialType.php | 2 +- .../Civi/Financialacls/FinancialTypeTest.php | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CRM/Financial/BAO/FinancialType.php b/CRM/Financial/BAO/FinancialType.php index 2b3d81f5ec..36302a4c2a 100644 --- a/CRM/Financial/BAO/FinancialType.php +++ b/CRM/Financial/BAO/FinancialType.php @@ -299,7 +299,7 @@ class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType im */ public static function getAvailableMembershipTypes(&$membershipTypes = NULL, $action = CRM_Core_Action::VIEW) { if (empty($membershipTypes)) { - $membershipTypes = CRM_Member_PseudoConstant::membershipType(); + $membershipTypes = CRM_Member_BAO_Membership::buildOptions('membership_type_id'); } if (!self::isACLFinancialTypeStatus()) { return $membershipTypes; diff --git a/ext/financialacls/tests/phpunit/Civi/Financialacls/FinancialTypeTest.php b/ext/financialacls/tests/phpunit/Civi/Financialacls/FinancialTypeTest.php index 31594b86c2..8d45ee9baf 100644 --- a/ext/financialacls/tests/phpunit/Civi/Financialacls/FinancialTypeTest.php +++ b/ext/financialacls/tests/phpunit/Civi/Financialacls/FinancialTypeTest.php @@ -47,7 +47,7 @@ class FinancialTypeTest extends BaseTestClass { foreach ($actions as $action => $action_ts) { $this->assertEquals( [ - ts("CiviCRM: %1 contributions of type %2", [1 => $action_ts, 2 => $type]), + ts('CiviCRM: %1 contributions of type %2', [1 => $action_ts, 2 => $type]), ts('%1 contributions of type %2', [1 => $action_ts, 2 => $type]), ], $permissions[$action . ' contributions of type ' . $type] @@ -73,15 +73,27 @@ class FinancialTypeTest extends BaseTestClass { /** * Check method test buildPermissionedClause() + * + * @throws \API_Exception */ public function testBuildPermissionedClause(): void { Civi::settings()->set('acl_financial_type', 1); + $membershipTypeID = Civi\Api4\MembershipType::create()->setValues([ + 'financial_type_id:name' => 'Event Fee', + 'name' => 'event access', + 'member_of_contact_id' => \CRM_Core_Config::domainID(), + 'duration_unit' => 'year', + 'period_type' => 'fixed', + ])->execute()->first()['id']; $this->setPermissions([ 'view contributions of type Donation', 'view contributions of type Member Dues', ]); $whereClause = \CRM_Financial_BAO_FinancialType::buildPermissionedClause('contribution'); $this->assertEquals('(`civicrm_contribution`.`financial_type_id` IS NULL OR (`civicrm_contribution`.`financial_type_id` IN (1,2)))', $whereClause); + $whereClause = \CRM_Financial_BAO_FinancialType::buildPermissionedClause('membership'); + $this->assertEquals(' civicrm_membership.membership_type_id IN (0)', $whereClause); + $this->setPermissions([ 'view contributions of type Donation', 'view contributions of type Member Dues', @@ -90,6 +102,9 @@ class FinancialTypeTest extends BaseTestClass { $whereClause = \CRM_Financial_BAO_FinancialType::buildPermissionedClause('contribution'); $this->assertEquals('(`civicrm_contribution`.`financial_type_id` IS NULL OR (`civicrm_contribution`.`financial_type_id` IN (1,4,2)))', $whereClause); + $whereClause = \CRM_Financial_BAO_FinancialType::buildPermissionedClause('membership'); + $this->assertEquals(' civicrm_membership.membership_type_id IN (' . $membershipTypeID . ')', $whereClause); + } } -- 2.25.1