X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCRM%2FUtils%2FTokenConsistencyTest.php;h=7e7f00c1f14beb690744372264e0320914d4d179;hb=d49e8eec43de89b0acef94e8c0fb5ef05507be23;hp=679cd0b4480799150bd03e6ee660ae41c8c02f8b;hpb=889b06177d5b8e2a81c94833deac3e24b5020872;p=civicrm-core.git diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index 679cd0b448..7e7f00c1f1 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -234,6 +234,45 @@ case.custom_1 :' . ' ]; } + /** + * 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)); + } + } + /** * Get the contribution recur tokens keyed by the token. *