+ /**
+ * Get tokens that are not advertised via listTokens.
+ *
+ * @return string[]
+ */
+ public function getUnadvertisedTokens(): array {
+ return [
+ '{membership.status_id}' => 'Status ID',
+ '{membership.membership_type_id}' => 'Membership Type ID',
+ '{membership.status_id:name}' => 'Machine name: Status',
+ '{membership.membership_type_id:name}' => 'Machine name: Membership Type',
+ '{contribution_recur.frequency_unit}' => 'Frequency Unit',
+ '{contribution_recur.contribution_status_id}' => 'Status',
+ '{contribution_recur.payment_processor_id}' => 'Payment Processor ID',
+ '{contribution_recur.financial_type_id}' => 'Financial Type ID',
+ '{contribution_recur.payment_instrument_id}' => 'Payment Method',
+ '{contribution_recur.frequency_unit:name}' => 'Machine name: Frequency Unit',
+ '{contribution_recur.payment_instrument_id:name}' => 'Machine name: Payment Method',
+ '{contribution_recur.contribution_status_id:name}' => 'Machine name: Status',
+ '{contribution_recur.payment_processor_id:name}' => 'Machine name: Payment Processor',
+ '{contribution_recur.financial_type_id:name}' => 'Machine name: Financial Type',
+ '{participant.status_id:name}' => 'Machine name: Status',
+ '{participant.role_id:name}' => 'Machine name: Participant Role',
+ '{participant.status_id}' => 'Status ID',
+ '{participant.role_id}' => 'Participant Role ID',
+ ];
+ }
+
+ /**
+ * Test tokens in 2 ways to ensure consistent handling.
+ *
+ * 1) as part of the greeting processing
+ * 2) via the token processor.
+ *
+ */
+ public function testOddTokens(): void {
+
+ $variants = [
+ [
+ 'string' => '{contact.individual_prefix}{ }{contact.first_name}{ }{contact.middle_name}{ }{contact.last_name}{ }{contact.individual_suffix}',
+ 'expected' => 'Mr. Anthony Anderson II',
+ ],
+ [
+ 'string' => '{contact.prefix_id:label}{ }{contact.first_name}{ }{contact.middle_name}{ }{contact.last_name}{ }{contact.suffix_id:label}',
+ 'expected' => 'Mr. Anthony Anderson II',
+ ],
+ ];
+ $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [
+ 'smarty' => FALSE,
+ 'schema' => ['contactId'],
+ ]);
+ $contactID = $this->individualCreate(['middle_name' => '']);
+ $tokenProcessor->addRow(['contactId' => $contactID]);
+ $tokenProcessor->evaluate();
+ foreach ($variants as $index => $variant) {
+ $tokenProcessor->addMessage($index, $variant['string'], 'text/plain');
+ }
+ $tokenProcessor->evaluate();
+ $result = $tokenProcessor->getRow(0);
+ foreach ($variants as $index => $variant) {
+ $greetingString = $variant['string'];
+ CRM_Utils_Token::replaceGreetingTokens($greetingString, $this->callAPISuccessGetSingle('Contact', ['id' => $contactID]), $contactID);
+ $this->assertEquals($variant['expected'], $greetingString);
+ $this->assertEquals($variant['expected'], $result->render($index));
+ }
+ }
+