Merge pull request #22826 from colemanw/api4EntityTypes
[civicrm-core.git] / tests / phpunit / CRM / Case / Form / EmailTest.php
1 <?php
2
3 /**
4 * @group headless
5 */
6 class CRM_Case_Form_EmailTest extends CiviCaseTestCase {
7
8 public function testOpeningEmailForm(): void {
9 $clientId = $this->individualCreate();
10 $caseObj = $this->createCase($clientId, $this->_loggedInUser);
11
12 $url = "civicrm/case/email/add?reset=1&action=add&atype=3&cid={$this->_loggedInUser}&caseid={$caseObj->id}";
13
14 $_SERVER['REQUEST_URI'] = $url;
15 $urlParts = explode('?', $url);
16 $_GET['q'] = $urlParts[0];
17
18 $parsed = [];
19 parse_str($urlParts[1], $parsed);
20 foreach ($parsed as $param => $value) {
21 $_REQUEST[$param] = $value;
22 }
23
24 $item = CRM_Core_Invoke::getItem([$_GET['q']]);
25 ob_start();
26 CRM_Core_Invoke::runItem($item);
27 $contents = ob_get_clean();
28
29 foreach ($parsed as $param => $dontcare) {
30 unset($_REQUEST[$param]);
31 }
32
33 // Anything here could be subject to change. Just tried to pick a few that
34 // might be less likely to. Really just trying to see if it opens the
35 // right form and with no errors.
36 $this->assertStringContainsString('name="from_email_address"', $contents);
37 $this->assertStringContainsString('name="subject"', $contents);
38 $this->assertStringContainsString('name="_qf_Email_upload"', $contents);
39 $this->assertStringContainsString('anthony_anderson@civicrm.org', $contents);
40 $this->assertStringContainsString('CRM_Case_Form_Task_Email', $contents);
41 }
42
43 public function testCaseTokenForRecipientAddedAfterOpeningForm(): void {
44 $clientId = $this->individualCreate();
45 $caseObj = $this->createCase($clientId, $this->_loggedInUser);
46
47 $anotherPersonId = $this->individualCreate([], 1);
48 $anotherPersonInfo = $this->callAPISuccess('Contact', 'getsingle', ['id' => $anotherPersonId]);
49
50 $senderEmail = $this->callAPISuccess('Email', 'getsingle', ['contact_id' => $this->_loggedInUser]);
51
52 $mut = new CiviMailUtils($this);
53
54 // Note we start by "clicking" on the link to send an email to the client
55 // but the "to" field below is where we've changed the recipient.
56 $_GET['cid'] = $_REQUEST['cid'] = $clientId;
57 $_GET['caseid'] = $_REQUEST['caseid'] = $caseObj->id;
58 $_GET['atype'] = $_REQUEST['atype'] = 3;
59 $_GET['action'] = $_REQUEST['action'] = 'add';
60
61 $form = $this->getFormObject('CRM_Case_Form_Task_Email', [
62 'to' => "{$anotherPersonId}::{$anotherPersonInfo['email']}",
63 'cc_id' => '',
64 'bcc_id' => '',
65 'subject' => 'abc',
66 // Note this is the civicrm_email.id
67 'from_email_address' => $senderEmail['id'],
68 'html_message' => '<p>Hello {contact.display_name}</p> <p>This is case id {case.id}</p>',
69 'text_message' => '',
70 'template' => '',
71 'saveTemplateName' => '',
72 'MAX_FILE_SIZE' => '2097152',
73 'attachDesc_1' => '',
74 'attachDesc_2' => '',
75 'attachDesc_3' => '',
76 'followup_date' => '',
77 'followup_assignee_contact_id' => '',
78 'followup_activity_type_id' => '',
79 'followup_activity_subject' => '',
80 ]);
81 $form->_contactIds = [$clientId];
82 $form->postProcess();
83
84 $mut->checkMailLog([
85 "Hello {$anotherPersonInfo['display_name']}",
86 "This is case id {$caseObj->id}",
87 ]);
88 $mut->stop();
89 }
90
91 }