$returnBlankToken = FALSE,
$escapeSmarty = FALSE
) {
- $key = 'contact';
- if (self::$_tokens[$key] == NULL) {
- // This should come from UF
-
- self::$_tokens[$key]
- = array_merge(
- array_keys(CRM_Contact_BAO_Contact::exportableFields('All')),
- array('checksum', 'contact_id')
- );
- }
+ // Refresh contact tokens in case they have changed. There is heavy caching
+ // in exportable fields so there is no benefit in doing this conditionally.
+ self::$_tokens['contact'] = array_merge(
+ array_keys(CRM_Contact_BAO_Contact::exportableFields('All')),
+ array('checksum', 'contact_id')
+ );
+ $key = 'contact';
// here we intersect with the list of pre-configured valid tokens
// so that we remove anything we do not recognize
// I hope to move this step out of here soon and
$this->assertEquals('Alan\'s Show', $contact['addressee_display']);
}
+ /**
+ * Test that creating a contact with various contact greetings works.
+ */
+ public function testContactGreetingsCreateWithCustomField() {
+ $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
+ $contact = $this->callAPISuccess('Contact', 'create', array('first_name' => 'Alan', 'contact_type' => 'Individual', 'custom_' . $ids['custom_field_id'] => 'Mice'));
+
+ // Change postal greeting to involve a custom field.
+ $postalOption = $this->callAPISuccessGetSingle('OptionValue', array('option_group_id' => 'postal_greeting', 'filter' => 1, 'is_default' => 1));
+ $this->callAPISuccess('OptionValue', 'create', array(
+ 'id' => $postalOption['id'],
+ 'name' => 'Dear {contact.first_name} {contact.custom_' . $ids['custom_field_id'] . '}',
+ 'label' => 'Dear {contact.first_name} {contact.custom_' . $ids['custom_field_id'] . '}',
+ ));
+
+ // Update contact & see if postal greeting now reflects the new string.
+ $this->callAPISuccess('Contact', 'create', array('id' => $contact['id'], 'last_name' => 'MouseyMousey'));
+ $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $contact['id'], 'return' => 'postal_greeting'));
+ $this->assertEquals('Dear Alan Mice', $contact['postal_greeting_display']);
+
+ //Cleanup
+ $this->callAPISuccess('OptionValue', 'create', array('id' => $postalOption['id'], 'name' => 'Dear {contact.first_name}'));
+ $this->customFieldDelete($ids['custom_field_id']);
+ $this->customGroupDelete($ids['custom_group_id']);
+ }
+
}