diff --git a/CRM/Core/Smarty.php b/CRM/Core/Smarty.php index 49a40a4fe3ff..095e9f8bd03d 100644 --- a/CRM/Core/Smarty.php +++ b/CRM/Core/Smarty.php @@ -138,7 +138,7 @@ private function initialize() { } $this->register_function('crmURL', ['CRM_Utils_System', 'crmURL']); - if (CRM_Utils_Constant::value('CIVICRM_SMARTY_DEFAULT_ESCAPE')) { + if (CRM_Utils_Constant::value('CIVICRM_SMARTY_DEFAULT_ESCAPE') || self::isTestEnvironment()) { // When default escape is enabled if the core escape is called before // any custom escaping is done the modifier_escape function is not // found, so require_once straight away. Note this was hit on the basic @@ -158,6 +158,17 @@ private function initialize() { } } + /** + * Is this a test environment. + * + * Currently we just check the class name but it is possible to run tests in CMS frameworks. + * + * @return bool + */ + private static function isTestEnvironment(): bool { + return CRM_Core_Config::singleton()->userFramework === 'UnitTests'; + } + /** * Static instance provider. *