Commit | Line | Data |
---|---|---|
da9977bd AS |
1 | <?php |
2 | ||
3 | /** | |
4 | * Class CRM_Activity_Form_Task_PDFLetterCommonTest | |
5 | * @group headless | |
6 | */ | |
7 | class CRM_Activity_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { | |
8 | ||
9 | public function setUp() { | |
10 | $this->useTransaction(TRUE); | |
11 | parent::setUp(); | |
12 | } | |
13 | ||
14 | public function tearDown() { | |
15 | parent::tearDown(); | |
16 | } | |
17 | ||
18 | public function testCreateDocumentBasicTokens() { | |
19 | $activity = $this->activityCreate(); | |
20 | $data = [ | |
21 | ["Subject: {activity.subject}", "Subject: Discussion on warm beer"], | |
22 | ["Date: {activity.activity_date_time}", "Date: " . \CRM_Utils_Date::customFormat(date('Ymd')) . " 12:00 AM"], | |
23 | ["Duration: {activity.duration}", "Duration: 90"], | |
24 | ["Location: {activity.location}", "Location: Baker Street"], | |
25 | ["Details: {activity.details}", "Details: Lets schedule a meeting"], | |
26 | ["Status ID: {activity.status_id}", "Status ID: 1"], | |
27 | ["Status: {activity.status}", "Status: Scheduled"], | |
28 | ["Activity Type ID: {activity.activity_type_id}", "Activity Type ID: 1"], | |
29 | ["Activity Type: {activity.activity_type}", "Activity Type: Meeting"], | |
30 | ["Activity ID: {activity.activity_id}", "Activity ID: " . $activity['id']], | |
31 | ]; | |
32 | $html_message = "\n" . implode("\n", CRM_Utils_Array::collect('0', $data)) . "\n"; | |
33 | $output = CRM_Activity_Form_Task_PDFLetterCommon::createDocument([$activity['id']], $html_message, ['is_unit_test' => TRUE]); | |
34 | ||
35 | // Check some basic fields | |
36 | foreach ($data as $line) { | |
37 | $this->assertContains("\n" . $line[1] . "\n", $output[0]); | |
38 | } | |
39 | } | |
40 | ||
41 | public function testCreateDocumentCustomFieldTokens() { | |
42 | // Set up custom group, and field | |
43 | // returns custom_group_id, custom_field_id, custom_field_option_group_id, custom_field_group_options | |
44 | $cg = $this->entityCustomGroupWithSingleStringMultiSelectFieldCreate("MyCustomField", "ActivityTest.php"); | |
45 | $cf = 'custom_' . $cg['custom_field_id']; | |
46 | foreach (array_keys($cg['custom_field_group_options']) as $option) { | |
47 | $activity = $this->activityCreate([$cf => $option]); | |
48 | $activities[] = [ | |
49 | 'id' => $activity['id'], | |
50 | 'option' => $option, | |
51 | ]; | |
52 | } | |
53 | ||
54 | $html_message = "Custom: {activity.$cf}"; | |
55 | $activityIds = CRM_Utils_Array::collect('id', $activities); | |
56 | $output = CRM_Activity_Form_Task_PDFLetterCommon::createDocument($activityIds, $html_message, ['is_unit_test' => TRUE]); | |
57 | // Should have one row of output per activity | |
58 | $this->assertEquals(count($activities), count($output)); | |
59 | ||
60 | // Check each line has the correct substitution | |
61 | foreach ($output as $key => $line) { | |
62 | $this->assertEquals($line, "Custom: " . $cg['custom_field_group_options'][$activities[$key]['option']]); | |
63 | } | |
64 | } | |
65 | ||
66 | public function testCreateDocumentSpecialTokens() { | |
67 | $this->markTestIncomplete('special tokens not yet merged - see https://github.com/civicrm/civicrm-core/pull/12012'); | |
68 | $activity = $this->activityCreate(); | |
69 | $data = [ | |
70 | ["Source First Name: {activity.source_first_name}", "Source First Name: Anthony"], | |
71 | ["Target N First Name: {activity.target_N_first_name}", "Target N First Name: Julia"], | |
72 | ["Target 0 First Name: {activity.target_0_first_name}", "Target 0 First Name: Julia"], | |
73 | ["Target 1 First Name: {activity.target_1_first_name}", "Target 1 First Name: Julia"], | |
74 | ["Target 2 First Name: {activity.target_2_first_name}", "Target 2 First Name: "], | |
75 | ["Assignee N First Name: {activity.target_N_first_name}", "Assignee N First Name: Julia"], | |
76 | ["Assignee 0 First Name: {activity.target_0_first_name}", "Assignee 0 First Name: Julia"], | |
77 | ["Assignee 1 First Name: {activity.target_1_first_name}", "Assignee 1 First Name: Julia"], | |
78 | ["Assignee 2 First Name: {activity.target_2_first_name}", "Assignee 2 First Name: "], | |
79 | ["Assignee Count: {activity.assignees_count}", "Assignee Count: 1"], | |
80 | ["Target Count: {activity.targets_count}", "Target Count: 1"], | |
81 | ]; | |
82 | $html_message = "\n" . implode("\n", CRM_Utils_Array::collect('0', $data)) . "\n"; | |
83 | $output = CRM_Activity_Form_Task_PDFLetterCommon::createDocument([$activity['id']], $html_message, ['is_unit_test' => TRUE]); | |
84 | ||
85 | foreach ($data as $line) { | |
86 | $this->assertContains("\n" . $line[1] . "\n", $output[0]); | |
87 | } | |
88 | } | |
89 | ||
90 | public function testCreateDocumentUnknownTokens() { | |
91 | $activity = $this->activityCreate(); | |
92 | $html_message = "Unknown token: {activity.something_unknown}"; | |
93 | $output = CRM_Activity_Form_Task_PDFLetterCommon::createDocument([$activity['id']], $html_message, ['is_unit_test' => TRUE]); | |
94 | // Unknown tokens should be left alone | |
95 | $this->assertEquals($output[0], $html_message); | |
96 | } | |
97 | ||
98 | } |