6 class CRM_Case_Form_EmailTest
extends CiviCaseTestCase
{
8 public function testOpeningEmailForm(): void
{
9 $clientId = $this->individualCreate();
10 $caseObj = $this->createCase($clientId, $this->_loggedInUser
);
12 $url = "civicrm/case/email/add?reset=1&action=add&atype=3&cid={$this->_loggedInUser}&caseid={$caseObj->id}";
14 $_SERVER['REQUEST_URI'] = $url;
15 $urlParts = explode('?', $url);
16 $_GET['q'] = $urlParts[0];
19 parse_str($urlParts[1], $parsed);
20 foreach ($parsed as $param => $value) {
21 $_REQUEST[$param] = $value;
24 $item = CRM_Core_Invoke
::getItem([$_GET['q']]);
26 CRM_Core_Invoke
::runItem($item);
27 $contents = ob_get_clean();
29 foreach ($parsed as $param => $dontcare) {
30 unset($_REQUEST[$param]);
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);
43 public function testCaseTokenForRecipientAddedAfterOpeningForm(): void
{
44 $clientId = $this->individualCreate();
45 $caseObj = $this->createCase($clientId, $this->_loggedInUser
);
47 $anotherPersonId = $this->individualCreate([], 1);
48 $anotherPersonInfo = $this->callAPISuccess('Contact', 'getsingle', ['id' => $anotherPersonId]);
50 $senderEmail = $this->callAPISuccess('Email', 'getsingle', ['contact_id' => $this->_loggedInUser
]);
52 $mut = new CiviMailUtils($this);
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';
61 $form = $this->getFormObject('CRM_Case_Form_Task_Email', [
62 'to' => "{$anotherPersonId}::{$anotherPersonInfo['email']}",
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>',
71 'saveTemplateName' => '',
72 'MAX_FILE_SIZE' => '2097152',
76 'followup_date' => '',
77 'followup_assignee_contact_id' => '',
78 'followup_activity_type_id' => '',
79 'followup_activity_subject' => '',
81 $form->_contactIds
= [$clientId];
85 "Hello {$anotherPersonInfo['display_name']}",
86 "This is case id {$caseObj->id}",