From 167f848f2f4604723809e2339ab04917c17c220e Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 14 Oct 2021 23:00:35 -0700 Subject: [PATCH] (NFC) TokenConsistencyTest - More aggressive test cleanup --- .../CRM/Utils/TokenConsistencyTest.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index 088eff7ae8..a3169345fd 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -48,6 +48,11 @@ class CRM_Utils_TokenConsistencyTest extends CiviUnitTestCase { public function tearDown(): void { $this->quickCleanup(['civicrm_case', 'civicrm_case_type', 'civicrm_participant', 'civicrm_event'], TRUE); $this->quickCleanUpFinancialEntities(); + + // WORKAROUND: CRM_Event_Tokens copies `civicrm_event` data into metadata cache. That should probably change, but that's a different scope-of-work. + // `clear()` works around it. This should be removed if that's updated, but it will be safe either way. + Civi::cache('metadata')->clear(); + parent::tearDown(); } @@ -944,10 +949,18 @@ December 21st, 2007 } public function testEscaping() { - $create = function(string $entity, array $record): CRM_Core_DAO { - // It's most convenient to use createTestObject(), but it doesn't reproduce the normal escaping rules from QuickForm/APIv3/APIv4. + $autoClean = []; + $create = function(string $entity, array $record = []) use (&$autoClean) { + // It's convenient to use createTestObject(), but it doesn't reproduce the normal escaping rules from QuickForm/APIv3/APIv4. CRM_Utils_API_HTMLInputCoder::singleton()->encodeRow($record); - return CRM_Core_DAO::createTestObject(CRM_Core_DAO_AllCoreTables::getFullName($entity), $record); + $dao = CRM_Core_DAO::createTestObject(CRM_Core_DAO_AllCoreTables::getFullName($entity), $record); + + // We're not using transactions, and truncating 'contact' seems problematic, so we roll up our sleeves and cleanup each record... + $autoClean[] = CRM_Utils_AutoClean::with(function() use ($entity, $dao) { + CRM_Core_DAO::deleteTestObjects(CRM_Core_DAO_AllCoreTables::getFullName($entity), ['id' => $dao->id]); + }); + + return $dao; }; $context = []; -- 2.25.1