$e->getTokenProcessor()->context['hookTokenCategories'] = $categories;
$messageTokens = $e->getTokenProcessor()->getMessageTokens();
+ $returnProperties = array_fill_keys($messageTokens['contact'] ?? [], 1);
+ $returnProperties = array_merge(\CRM_Contact_BAO_Query::defaultReturnProperties(), $returnProperties);
foreach ($e->getRows() as $row) {
if (empty($row->context['contactId'])) {
$params = [
['contact_id', '=', $contactId, 0, 0],
];
- [$contact] = \CRM_Contact_BAO_Query::apiQuery($params);
+ [$contact] = \CRM_Contact_BAO_Query::apiQuery($params, $returnProperties ?? NULL);
//CRM-4524
$contact = reset($contact);
+ // Test cover for greeting in CRM_Core_BAO_ActionScheduleTest::testMailer
+ $contact['email_greeting'] = $contact['email_greeting_display'] ?? '';
+ $contact['postal_greeting'] = $contact['postal_greeting_display'] ?? '';
+ $contact['addressee'] = $contact['address_display'] ?? '';
if (!$contact || is_a($contact, 'CRM_Core_Error')) {
// FIXME: Need to differentiate errors which kill the batch vs the individual row.
- \Civi::log()->debug("Failed to generate token data. Invalid contact ID: " . $row->context['contactId']);
+ \Civi::log()->debug('Failed to generate token data. Invalid contact ID: ' . $row->context['contactId']);
continue;
}
if (!empty($messageTokens['contact'])) {
foreach ($messageTokens['contact'] as $token) {
if (\CRM_Core_BAO_CustomField::getKeyID($token)) {
- $contact[$token] = civicrm_api3('Contact', 'getvalue', [
- 'return' => $token,
- 'id' => $contactId,
- ]);
+ $contact[$token] = \CRM_Core_BAO_CustomField::displayValue($contact[$token], \CRM_Core_BAO_CustomField::getKeyID($token));
}
}
}
public function testContactTokensRenderedByTokenProcessor(): void {
$this->createCustomGroupWithFieldsOfAllTypes([]);
$tokenData = $this->getAllContactTokens();
- // @todo - these 2 still need fixing/ syncing.
- unset($tokenData['preferred_communication_method'], $tokenData['addressee']);
$address = $this->setupContactFromTokeData($tokenData);
- $tokenString ='';
+ $tokenString = '';
foreach (array_keys($tokenData) as $key) {
$tokenString .= "{$key}:{contact.{$key}}\n";
}
$rendered = (string) $row->render('html');
}
$expected = $this->getExpectedContactOutput($address['id'], $tokenData, $rendered);
- // @todo - fix these 2 & stop stripping them out.
- $expected = str_replace(["preferred_communication_method:\n", "addressee:Mr. Robert Frank Smith II\n"], '', $expected);
+ // @todo - this works better in token processor than in CRM_Core_Token.
+ // once synced we can fix $this->getExpectedContactOutput to return the right thing.
+ $expected = str_replace("preferred_communication_method:\n", "preferred_communication_method:Phone\n", $expected);
$this->assertEquals($expected, $rendered);
}
'is_primary' => TRUE,
'name' => $tokenData['im'],
'provider_id' => $tokenData['im_provider'],
- 'contact_id' => $tokenData['contact_id']
+ 'contact_id' => $tokenData['contact_id'],
]);
$this->callAPISuccess('OpenID', 'create', array_merge($tokenData, [
'is_primary' => TRUE,
'contact_id' => $tokenData['contact_id'],
- 'openid' => $tokenData['openid']
+ 'openid' => $tokenData['openid'],
]));
return $address;
}
/**
- * @param array|null $contact
- * @param $id
+ * Get the expected rendered string.
+ *
+ * @param int $id
* @param array $tokenData
- * @param bool $checksum
+ * @param string $actualOutput
*
* @return string
+ * @throws \API_Exception
*/
protected function getExpectedContactOutput($id, array $tokenData, string $actualOutput): string {
$checksum = substr($actualOutput, (strpos($actualOutput, 'cs=') + 3), 47);