3 use Civi\Api4\PrintLabel
;
6 * Test CRM_Event_Form_Registration functions.
11 class CRM_Event_Form_Task_BadgeTest
extends CiviUnitTestCase
{
13 use CRMTraits_Custom_CustomDataTrait
;
15 public function tearDown(): void
{
16 $this->quickCleanup(['civicrm_participant', 'civicrm_print_label'], TRUE);
21 * Test the the submit function on the event participant submit function.
23 public function testSubmit(): void
{
24 $this->createCustomGroupWithFieldOfType(['extends' => 'Participant']);
25 $contactID = $this->individualCreate(['employer_id' => 1]);
26 $participantID = $this->participantCreate([
27 'contact_id' => $contactID,
31 $badgeLayout = PrintLabel
::get()->addSelect('data')->execute()->first();
33 'data' => array_merge($badgeLayout['data'], ['token' => [], 'font_name' => [''], 'font_size' => [], 'text_alignment' => []]),
35 foreach (array_keys($this->getAvailableTokens()) as $id => $token) {
37 $values['data']['token'][$index] = $token;
38 $values['data']['font_name'][$index] = 'dejavusans';
39 $values['data']['font_size'][$index] = '20';
40 $values['data']['font_style'][$index] = '';
41 $values['data']['text_alignment'][$index] = 'C';
43 PrintLabel
::update()->addWhere('id', '=', 1)->setValues($values)->execute();
45 $_REQUEST['context'] = 'view';
46 $_REQUEST['id'] = $participantID;
47 $_REQUEST['cid'] = $contactID;
48 /* @var CRM_Event_Form_Task_Badge $form */
49 $form = $this->getFormObject(
50 'CRM_Event_Form_Task_Badge',
54 'task' => CRM_Core_Task
::BATCH_UPDATE
,
55 'radio_ts' => 'ts_sel',
56 'mark_x_' . $participantID => 1,
63 catch (CRM_Core_Exception_PrematureExitException
$e) {
64 $tokens = $e->errorData
['formattedRow']['token'];
66 'value' => 'Annual CiviCRM meet',
67 'font_name' => 'dejavusans',
70 'text_alignment' => 'C',
71 'token' => '{event.title}',
74 foreach ($this->getAvailableTokens() as $token => $expected) {
75 $this->assertEquals($expected, $tokens[$index]['value'], 'failure in token ' . $token);
80 $this->fail('Should not be reached');
86 protected function getAvailableTokens(): array {
88 '{event.title}' => 'Annual CiviCRM meet',
89 '{contact.display_name}' => 'Mr. Anthony Anderson II',
90 '{contact.current_employer}' => 'Default Organization',
91 '{event.start_date}' => 'October 21st',
92 '{participant.status_id}' => 2,
93 '{participant.role_id}' => 1,
94 '{participant.register_date}' => 'February 19th, 2007 12:00 AM',
95 '{participant.source}' => 'Wimbeldon',
96 '{participant.fee_level}' => 'low',
97 '{participant.fee_amount}' => NULL,
98 '{participant.registered_by_id}' => NULL,
99 '{participant.transferred_to_contact_id}' => NULL,
100 '{participant.role_id:label}' => 'Attendee',
101 '{participant.fee_label}' => NULL,
102 '{event.end_date}' => 'October 23rd',