From b21f024836f06291d206016aca283892bae98966 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Fri, 8 Oct 2021 13:40:30 -0400 Subject: [PATCH] test demonstrating failure to resolve token --- CRM/Utils/Mail.php | 2 +- tests/phpunit/CRM/Case/Form/EmailTest.php | 53 +++++++++++++++++++-- tests/phpunit/CiviTest/CiviCaseTestCase.php | 2 +- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/CRM/Utils/Mail.php b/CRM/Utils/Mail.php index e8eca02c72..2043f9494d 100644 --- a/CRM/Utils/Mail.php +++ b/CRM/Utils/Mail.php @@ -572,7 +572,7 @@ class CRM_Utils_Mail { * contact ID in RFC822 format. * * @param string $from - * contact ID or formatted "From address", eg. 12 or "Fred Bloggs" + * civicrm_email.id or formatted "From address", eg. 12 or "Fred Bloggs" * @return string * The RFC822-formatted email header (display name + address) */ diff --git a/tests/phpunit/CRM/Case/Form/EmailTest.php b/tests/phpunit/CRM/Case/Form/EmailTest.php index 20fdbf50ce..21207c03b1 100644 --- a/tests/phpunit/CRM/Case/Form/EmailTest.php +++ b/tests/phpunit/CRM/Case/Form/EmailTest.php @@ -6,11 +6,10 @@ 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); @@ -42,4 +41,52 @@ class CRM_Case_Form_EmailTest extends CiviCaseTestCase { $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' => '

Hello {contact.display_name}

This is case id {case.id}

', + '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(); + } + } diff --git a/tests/phpunit/CiviTest/CiviCaseTestCase.php b/tests/phpunit/CiviTest/CiviCaseTestCase.php index f13ee024d4..e0e4dcf135 100644 --- a/tests/phpunit/CiviTest/CiviCaseTestCase.php +++ b/tests/phpunit/CiviTest/CiviCaseTestCase.php @@ -111,8 +111,8 @@ class CiviCaseTestCase extends CiviUnitTestCase { * This method is called after a test is executed. */ public function tearDown(): void { - $this->quickCleanup($this->tablesToTruncate, TRUE); $this->customDirectories(array('template_path' => FALSE)); + $this->quickCleanup($this->tablesToTruncate, TRUE); CRM_Case_XMLRepository::singleton(TRUE); } -- 2.25.1