test demonstrating failure to resolve token
authordemeritcowboy <demeritcowboy@hotmail.com>
Fri, 8 Oct 2021 17:40:30 +0000 (13:40 -0400)
committerdemeritcowboy <demeritcowboy@hotmail.com>
Wed, 13 Oct 2021 13:12:10 +0000 (09:12 -0400)
CRM/Utils/Mail.php
tests/phpunit/CRM/Case/Form/EmailTest.php
tests/phpunit/CiviTest/CiviCaseTestCase.php

index e8eca02c72abbf302b505430b78ed493e0eacad1..2043f9494dfb6f58cbbd9d46e8737700444e1bd0 100644 (file)
@@ -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" <fred@example.org>
+   *   civicrm_email.id or formatted "From address", eg. 12 or "Fred Bloggs" <fred@example.org>
    * @return string
    *   The RFC822-formatted email header (display name + address)
    */
index 20fdbf50ce3395046937f14e1c7ad34c1cb8641e..21207c03b136b99e665d674e51862202d7f39c7c 100644 (file)
@@ -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' => '<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();
+  }
+
 }
index f13ee024d47b97185a09504fe0bba1dececa4f34..e0e4dcf1354f8b4b59912522e99b1a2faca51831 100644 (file)
@@ -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);
   }