Skip to content

Commit

Permalink
Merge pull request #21476 from eileenmcnaughton/part
Browse files Browse the repository at this point in the history
[REF] add test & static array to participant values tokens
  • Loading branch information
colemanw authored Sep 16, 2021
2 parents 09d6e80 + 3557107 commit 76343cb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 33 deletions.
57 changes: 24 additions & 33 deletions CRM/Core/SelectValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,41 +584,32 @@ public static function contactTokens(): array {
*
* @return array
*/
public static function participantTokens() {
static $tokens = NULL;
if (!$tokens) {
$exportFields = CRM_Event_BAO_Participant::exportableFields();

$values = array_merge(array_keys($exportFields));
unset($values[0]);

// skipping some tokens for time being.
$skipTokens = [
'event_id',
'participant_is_pay_later',
'participant_is_test',
'participant_contact_id',
'participant_fee_currency',
'participant_campaign_id',
'participant_status',
'participant_discount_name',
];

$customFields = CRM_Core_BAO_CustomField::getFields('Participant');
public static function participantTokens(): array {
$tokens = [
'{participant.participant_status_id}' => 'Status ID',
'{participant.participant_role_id}' => 'Participant Role (ID)',
'{participant.participant_register_date}' => 'Register date',
'{participant.participant_source}' => 'Participant Source',
'{participant.participant_fee_level}' => 'Fee level',
'{participant.participant_fee_amount}' => 'Fee Amount',
'{participant.participant_registered_by_id}' => 'Registered By Participant ID',
'{participant.transferred_to_contact_id}' => 'Transferred to Contact ID',
'{participant.participant_role}' => 'Participant Role (label)',
'{participant.event_title}' => 'Event Title',
'{participant.event_start_date}' => 'Event Start Date',
'{participant.event_end_date}' => 'Event End Date',
'{participant.fee_label}' => 'Fee Label',
'{participant.default_role_id}' => 'Default Role',
'{participant.template_title}' => 'Event Template Title',
'{participant.currency}' => 'Currency',
'{participant.participant_note}' => 'Participant Note',
];
$customFields = CRM_Core_BAO_CustomField::getFields('Participant');

foreach ($values as $key => $val) {
if (in_array($val, $skipTokens)) {
continue;
}
//keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) {
$tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
}
else {
$tokens["{participant.$val}"] = $exportFields[$val]['title'];
}
}
foreach ($customFields as $customField) {
$tokens['{participant.custom_' . $customField['id'] . '}'] = $customField['label'] . " :: " . $customField['groupTitle'];
}

return $tokens;
}

Expand Down
40 changes: 40 additions & 0 deletions tests/phpunit/CRM/Utils/TokenConsistencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,44 @@ protected function getExpectedMembershipTokenOutput(): string {
100.00';
}

/**
* Test that membership tokens are consistently rendered.
*
* @throws \API_Exception
*/
public function testParticipantTokenConsistency(): void {
$this->createLoggedInUser();
$this->createCustomGroupWithFieldOfType(['extends' => 'Participant']);
$tokens = CRM_Core_SelectValues::participantTokens();
$this->assertEquals($this->getParticipantTokens(), $tokens);
}

/**
* Get declared membership tokens.
*
* @return string[]
*/
public function getParticipantTokens(): array {
return [
'{participant.participant_status_id}' => 'Status ID',
'{participant.participant_role_id}' => 'Participant Role (ID)',
'{participant.participant_register_date}' => 'Register date',
'{participant.participant_source}' => 'Participant Source',
'{participant.participant_fee_level}' => 'Fee level',
'{participant.participant_fee_amount}' => 'Fee Amount',
'{participant.participant_registered_by_id}' => 'Registered By Participant ID',
'{participant.transferred_to_contact_id}' => 'Transferred to Contact ID',
'{participant.participant_role}' => 'Participant Role (label)',
'{participant.event_title}' => 'Event Title',
'{participant.event_start_date}' => 'Event Start Date',
'{participant.event_end_date}' => 'Event End Date',
'{participant.fee_label}' => 'Fee Label',
'{participant.default_role_id}' => 'Default Role',
'{participant.template_title}' => 'Event Template Title',
'{participant.currency}' => 'Currency',
'{participant.participant_note}' => 'Participant Note',
'{participant.' . $this->getCustomFieldName('text') . '}' => 'Enter text here :: Group with field text',
];
}

}

0 comments on commit 76343cb

Please sign in to comment.