From 701231635064fe3ff5b39645b966a597202c080e Mon Sep 17 00:00:00 2001 From: colemanw Date: Fri, 15 Sep 2023 17:32:22 -0400 Subject: [PATCH] CRM_Case_ManagedEntities - Fix bugs caused by double-caching The list of case types was being cached twice, once by CRM_Core_Pseudoconstant and yet again in CRM_Case_XMLRepository::$allCaseTypes. This made getting a fresh list of case types unnecessarily difficult. --- CRM/Case/XMLRepository.php | 20 +++++++++---------- .../tests/mixin/ManagedCaseTypeTest.php | 10 ---------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/CRM/Case/XMLRepository.php b/CRM/Case/XMLRepository.php index 000ccdb52f..70fc9088b2 100644 --- a/CRM/Case/XMLRepository.php +++ b/CRM/Case/XMLRepository.php @@ -32,11 +32,11 @@ class CRM_Case_XMLRepository { protected $hookCache = NULL; /** - * Symbolic names of case-types. + * Override case types, only used by unit tests * * @var array|null */ - protected $allCaseTypes = NULL; + protected $unitTestCaseTypes = NULL; /** * @param bool $fresh @@ -52,18 +52,18 @@ class CRM_Case_XMLRepository { public function flush() { $this->xml = []; $this->hookCache = NULL; - $this->allCaseTypes = NULL; + $this->unitTestCaseTypes = NULL; CRM_Core_DAO::$_dbColumnValueCache = []; } /** * Class constructor. * - * @param array $allCaseTypes + * @param array $unitTestCaseTypes * @param array $xml */ - public function __construct($allCaseTypes = NULL, $xml = []) { - $this->allCaseTypes = $allCaseTypes; + public function __construct($unitTestCaseTypes = NULL, $xml = []) { + $this->unitTestCaseTypes = $unitTestCaseTypes; $this->xml = $xml; } @@ -215,13 +215,11 @@ class CRM_Case_XMLRepository { } /** - * @return array symbolic names of case-types + * @return string[] + * symbolic names of case-types */ public function getAllCaseTypes() { - if ($this->allCaseTypes === NULL) { - $this->allCaseTypes = CRM_Case_PseudoConstant::caseType("name"); - } - return $this->allCaseTypes; + return $this->unitTestCaseTypes ?? CRM_Case_PseudoConstant::caseType("name"); } /** diff --git a/mixin/mgd-php@1/example/tests/mixin/ManagedCaseTypeTest.php b/mixin/mgd-php@1/example/tests/mixin/ManagedCaseTypeTest.php index 097ce106b5..db7b74b81a 100644 --- a/mixin/mgd-php@1/example/tests/mixin/ManagedCaseTypeTest.php +++ b/mixin/mgd-php@1/example/tests/mixin/ManagedCaseTypeTest.php @@ -24,10 +24,6 @@ class ManagedCaseTypeTest extends \PHPUnit\Framework\Assert { $this->assertEquals(TRUE, $items[0]['is_active']); $this->assertEquals(1, count($items)); - // This is normally handled by `CRM_Case_BAO_CaseType` calling `CRM_Core_ManagedEntities::scheduleReconciliation` - // But due to timing issues with the E2E tests the scheduled reconciliation hasn't happened yet. - \Civi\Api4\Managed::reconcile(FALSE)->addModule('civicrm')->execute(); - $actTypes = $cv->api4('OptionValue', 'get', [ 'where' => [['option_group_id:name', '=', 'activity_type'], ['name', '=', 'Nibble']], ]); @@ -48,12 +44,6 @@ class ManagedCaseTypeTest extends \PHPUnit\Framework\Assert { $items = $cv->api4('CaseType', 'get', ['where' => [['name', '=', 'BunnyDance']]]); $this->assertEquals(0, count($items)); - // This is normally handled by `CRM_Case_BAO_CaseType` calling `CRM_Core_ManagedEntities::scheduleReconciliation` - // But static caching seems to interfere. - \Civi\Api4\Managed::reconcile(FALSE)->execute(); - \CRM_Core_PseudoConstant::flush(); - \Civi\Api4\Managed::reconcile(FALSE)->addModule('civicrm')->execute(); - $actTypes = $cv->api4('OptionValue', 'get', [ 'where' => [['option_group_id:name', '=', 'activity_type'], ['name', '=', 'Nibble']], ]); -- 2.25.1