$this->assertEquals(1, $this->counts['onEvalTokens']);
}
- public function testFilter() {
+ public function testFilter(): void {
$exampleTokens['foo_bar']['whiz_bang'] = 'Some Text';
+ $exampleTokens['foo_bar']['whiz_bop'] = '';
$exampleMessages = [
'This is {foo_bar.whiz_bang}.' => 'This is Some Text.',
'This is {foo_bar.whiz_bang|lower}...' => 'This is some text...',
'This is {foo_bar.whiz_bang|upper}!' => 'This is SOME TEXT!',
+ 'This is {foo_bar.whiz_bang|boolean}!' => 'This is 1!',
+ 'This is {foo_bar.whiz_bop|boolean}!' => 'This is 0!',
];
- $expectExampleCount = /* {#msgs} x {smarty:on,off} */ 6;
+ // We expect 5 messages to be parsed 2 times each - ie 10 times.
+ $expectExampleCount = 10;
$actualExampleCount = 0;
foreach ($exampleMessages as $inputMessage => $expectOutput) {
*/
class api_v3_JobTest extends CiviUnitTestCase {
+ /**
+ * Entities to return to their original values during tearDown.
+ *
+ * The array is keyed by EntityName.
+ *
+ * @var array
+ */
+ private $originalValues = [];
+
/**
* Set up for tests.
*/
public function tearDown(): void {
$this->quickCleanUpFinancialEntities();
$this->quickCleanup(['civicrm_contact', 'civicrm_address', 'civicrm_email', 'civicrm_website', 'civicrm_phone', 'civicrm_job', 'civicrm_action_log', 'civicrm_action_schedule', 'civicrm_group', 'civicrm_group_contact'], TRUE);
+ $this->quickCleanup(['civicrm_contact', 'civicrm_address', 'civicrm_email', 'civicrm_website', 'civicrm_phone'], TRUE);
+ foreach ($this->originalValues as $entity => $entities) {
+ foreach ($entities as $values) {
+ $this->callAPISuccess($entity, 'create', $values);
+ }
+ }
parent::tearDown();
}
$this->assertAPIDeleted('Job', $createResult['id']);
}
+ /**
+ * Test processing strings with boolean's in them.
+ *
+ * e.g {if {contact.first_name|boolean}
+ *
+ * @dataProvider dataProviderNamesAndGreetings
+ */
+ public function testUpdateGreetingBooleanToken($params, $expectedEmailGreeting): void {
+ $this->setEmailGreetingTemplateToConditional();
+ $contactID = $this->individualCreate($params);
+ $this->assertEquals($expectedEmailGreeting, Contact::get()->addSelect('email_greeting_display')->addWhere('id', '=', $contactID)->execute()->first()['email_greeting_display']);
+ }
+
+ /**
+ * Data provider for testing email greeting template.
+ */
+ public function dataProviderNamesAndGreetings(): array {
+ return [
+ [
+ 'params' => ['first_name' => 'Anthony'],
+ 'expected' => 'Dear Anthony',
+ ],
+ [
+ 'params' => ['first_name' => ''],
+ 'expected' => 'Dear Friend',
+ ],
+ [
+ // This isn't really an issue with the |boolean provider
+ // but it would be without it - https://lab.civicrm.org/dev/core/-/issues/3962
+ 'params' => ['first_name' => "O'Shea"],
+ 'expected' => "Dear O'Shea",
+ ],
+ ];
+ }
+
+ /**
+ * Set the Individual email template to use {if {contact.first_name|boolean}.
+ */
+ protected function setEmailGreetingTemplateToConditional(): void {
+ $this->originalValues['OptionValue']['email'] = reset($this->callAPISuccess('OptionValue', 'get', [
+ 'option_group_id' => 'email_greeting',
+ 'is_default' => TRUE,
+ 'filter' => 1,
+ ])['values']);
+ $this->callAPISuccess('OptionValue', 'create', [
+ 'id' => $this->originalValues['OptionValue']['email']['id'],
+ 'label' => '{if {contact.first_name|boolean}}Dear {contact.first_name}{else}Dear Friend{/if}',
+ ]);
+ }
+
/**
* Test greeting update job.
*