From e3a34ebde9c77d9e960354dd2030d613cd3362cc Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 11 Nov 2021 20:08:16 -0800 Subject: [PATCH] Refine alignment of old/new token lists The prior commit means that `$context['participantId']` will activate `{event.*}` tokens - in contexts that use `TokenProcessor`. And the `TokenProcessor` is *somewhat* matched to the older functions. This twiddles the match-up: * Provide continuity for the deprecated `CRM_Core_SelectValues::participantTokens()` - so it still only returns `{participant.*}` tokens. Borrow the technique which excludes `{domain.*}` tokens. This should ensure better continuity for any callers that actually use `CRM_Utils_Token`. * Update the assertions for the `TokenProcessor` to show that the `{event.*}` tokens are presented in participant-related contexts. --- CRM/Core/SelectValues.php | 2 +- tests/phpunit/CRM/Utils/TokenConsistencyTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index c31dcdcdb6..83c177e3de 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -595,7 +595,7 @@ class CRM_Core_SelectValues { $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['participantId']]); $allTokens = $tokenProcessor->listTokens(); foreach (array_keys($allTokens) as $token) { - if (strpos($token, '{domain.') === 0) { + if (strpos($token, '{domain.') === 0 || strpos($token, '{event.') === 0) { unset($allTokens[$token]); } } diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index 672af5d059..a83fbc9477 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -639,7 +639,7 @@ December 21st, 2007 'smarty' => FALSE, 'schema' => ['participantId'], ]); - $this->assertEquals(array_merge($tokens, $this->getDomainTokens()), $tokenProcessor->listTokens()); + $this->assertEquals(array_merge($tokens, $this->getEventTokens(), $this->getDomainTokens()), $tokenProcessor->listTokens()); $this->callAPISuccess('job', 'send_reminder', []); $expected = $this->getExpectedParticipantTokenOutput(); -- 2.25.1