class CRM_Case_Form_EmailTest extends CiviCaseTestCase {
public function testOpeningEmailForm() {
- $loggedInUserId = $this->createLoggedInUser();
$clientId = $this->individualCreate();
- $caseObj = $this->createCase($clientId, $loggedInUserId);
+ $caseObj = $this->createCase($clientId, $this->_loggedInUser);
- $url = "civicrm/case/email/add?reset=1&action=add&atype=3&cid={$loggedInUserId}&caseid={$caseObj->id}";
+ $url = "civicrm/case/email/add?reset=1&action=add&atype=3&cid={$this->_loggedInUser}&caseid={$caseObj->id}";
$_SERVER['REQUEST_URI'] = $url;
$urlParts = explode('?', $url);
$this->assertStringContainsString('CRM_Case_Form_Task_Email', $contents);
}
+ public function testCaseTokenForRecipientAddedAfterOpeningForm() {
+ $clientId = $this->individualCreate();
+ $caseObj = $this->createCase($clientId, $this->_loggedInUser);
+
+ $anotherPersonId = $this->individualCreate([], 1);
+ $anotherPersonInfo = $this->callAPISuccess('Contact', 'getsingle', ['id' => $anotherPersonId]);
+
+ $senderEmail = $this->callAPISuccess('Email', 'getsingle', ['contact_id' => $this->_loggedInUser]);
+
+ $mut = new CiviMailUtils($this);
+
+ // Note we start by "clicking" on the link to send an email to the client
+ // but the "to" field below is where we've changed the recipient.
+ $_GET['cid'] = $_REQUEST['cid'] = $clientId;
+ $_GET['caseid'] = $_REQUEST['caseid'] = $caseObj->id;
+ $_GET['atype'] = $_REQUEST['atype'] = 3;
+ $_GET['action'] = $_REQUEST['action'] = 'add';
+
+ $form = $this->getFormObject('CRM_Case_Form_Task_Email', [
+ 'to' => "{$anotherPersonId}::{$anotherPersonInfo['email']}",
+ 'cc_id' => '',
+ 'bcc_id' => '',
+ 'subject' => 'abc',
+ // Note this is the civicrm_email.id
+ 'from_email_address' => $senderEmail['id'],
+ 'html_message' => '<p>Hello {contact.display_name}</p> <p>This is case id {case.id}</p>',
+ 'text_message' => '',
+ 'template' => '',
+ 'saveTemplateName' => '',
+ 'MAX_FILE_SIZE' => '2097152',
+ 'attachDesc_1' => '',
+ 'attachDesc_2' => '',
+ 'attachDesc_3' => '',
+ 'followup_date' => '',
+ 'followup_assignee_contact_id' => '',
+ 'followup_activity_type_id' => '',
+ 'followup_activity_subject' => '',
+ ]);
+ $form->_contactIds = [$clientId];
+ $form->postProcess();
+
+ $mut->checkMailLog([
+ "Hello {$anotherPersonInfo['display_name']}",
+ "This is case id {$caseObj->id}",
+ ]);
+ $mut->stop();
+ }
+
}