dev/core#2834 Preliminary test on badge
[civicrm-core.git] / tests / phpunit / CRM / Event / Form / Task / BadgeTest.php
1 <?php
2
3 /**
4 * Test CRM_Event_Form_Registration functions.
5 *
6 * @package CiviCRM
7 * @group headless
8 */
9 class CRM_Event_Form_Task_BadgeTest extends CiviUnitTestCase {
10
11 use CRMTraits_Custom_CustomDataTrait;
12
13 /**
14 * Test the the submit function on the event participant submit function.
15 */
16 public function testSubmit(): void {
17 $this->createCustomGroupWithFieldOfType(['extends' => 'Participant']);
18 $contactID = $this->individualCreate();
19 $participantID = $this->participantCreate(['contact_id' => $contactID]);
20
21 $_REQUEST['context'] = 'view';
22 $_REQUEST['id'] = $participantID;
23 $_REQUEST['cid'] = $contactID;
24 /* @var CRM_Event_Form_Task_Badge $form */
25 $form = $this->getFormObject(
26 'CRM_Event_Form_Task_Badge',
27 ['badge_id' => 1],
28 NULL,
29 [
30 'task' => CRM_Core_Task::BATCH_UPDATE,
31 'radio_ts' => 'ts_sel',
32 'mark_x_' . $participantID => 1,
33 ]
34 );
35 $form->buildForm();
36 try {
37 $form->postProcess();
38 }
39 catch (CRM_Core_Exception_PrematureExitException $e) {
40 $tokens = $e->errorData['formattedRow']['token'];
41 $this->assertEquals([
42 1 => [
43 'value' => 'Annual CiviCRM meet',
44 'font_name' => 'dejavusans',
45 'font_size' => '9',
46 'font_style' => '',
47 'text_alignment' => 'L',
48 'token' => '{event.title}',
49 ],
50 2 =>
51 [
52 'value' => 'Mr. Anthony Anderson II',
53 'font_name' => 'dejavusans',
54 'font_size' => '20',
55 'font_style' => '',
56 'text_alignment' => 'C',
57 'token' => '{contact.display_name}',
58 ],
59 3 =>
60 [
61 'value' => NULL,
62 'font_name' => 'dejavusans',
63 'font_size' => '15',
64 'font_style' => '',
65 'text_alignment' => 'C',
66 'token' => '{contact.current_employer}',
67 ],
68 4 =>
69 [
70 'value' => 'October 21st',
71 'font_name' => 'dejavusans',
72 'font_size' => '9',
73 'font_style' => '',
74 'text_alignment' => 'R',
75 'token' => '{event.start_date}',
76 ],
77 ], $tokens);
78 return;
79 }
80 $this->fail('Should not be reached');
81 }
82
83 }