From 71aa434cfa5b480eb63f5298a8b2966e87d0d077 Mon Sep 17 00:00:00 2001 From: Heber Date: Sun, 24 Nov 2024 20:42:03 -0700 Subject: [PATCH] Make test namespace aware --- dlrs/main/classes/Utilities.cls | 2 +- dlrs/main/classes/UtilitiesTest.cls | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dlrs/main/classes/Utilities.cls b/dlrs/main/classes/Utilities.cls index 9d431fd6..3c23defd 100644 --- a/dlrs/main/classes/Utilities.cls +++ b/dlrs/main/classes/Utilities.cls @@ -136,7 +136,7 @@ public class Utilities { WHERE Id IN :customPermIds ]) { String permName = perm.DeveloperName; - if (!String.isBlank(perm.NamespacePrefix)) { + if (String.isNotBlank(perm.NamespacePrefix)) { // if this has a namespace prefix we should build a unified string permName = String.format( '{0}__{1}', diff --git a/dlrs/main/classes/UtilitiesTest.cls b/dlrs/main/classes/UtilitiesTest.cls index 4ed6cb9e..b7da4613 100644 --- a/dlrs/main/classes/UtilitiesTest.cls +++ b/dlrs/main/classes/UtilitiesTest.cls @@ -4,7 +4,7 @@ public class UtilitiesTest { static void testUserHasCustomPermission() { // find the permission set that has access to the Custom Permission we want to use to check (if it even exists in the system) List permSetsWithAccess = [ - SELECT ParentId + SELECT ParentId, SetupEntityId FROM SetupEntityAccess WHERE SetupEntityId IN ( @@ -15,6 +15,11 @@ public class UtilitiesTest { AND Parent.IsOwnedByProfile = FALSE ]; if (!permSetsWithAccess.isEmpty()) { + CustomPermission perm = [ + SELECT DeveloperName, NamespacePrefix + FROM CustomPermission + WHERE Id = :permSetsWithAccess[0].SetupEntityId + ]; // there is a compatible permission set that we can use for testing // see if the running user already has that permission set List assignments = [ @@ -35,7 +40,11 @@ public class UtilitiesTest { } // make sure the utility can see the perm set correctly // (we do it here because any earlier and the utility would have built the cache already) - Assert.areEqual(false, Utilities.userHasCustomPermission('DisableDLRS')); + String permName = perm.DeveloperName; + if (String.isNotBlank(perm.NamespacePrefix)) { + permName = perm.NamespacePrefix + '__' + perm.DeveloperName; + } + Assert.areEqual(false, Utilities.userHasCustomPermission(permName)); } Assert.areEqual(false, Utilities.userHasCustomPermission(null));