Skip to content

Commit

Permalink
test demonstrating failure to resolve token
Browse files Browse the repository at this point in the history
  • Loading branch information
demeritcowboy committed Oct 13, 2021
1 parent 6b3753c commit b21f024
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CRM/Utils/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public static function format($fields) {
* contact ID in RFC822 format.
*
* @param string $from
* contact ID or formatted "From address", eg. 12 or "Fred Bloggs" <[email protected]>
* civicrm_email.id or formatted "From address", eg. 12 or "Fred Bloggs" <[email protected]>
* @return string
* The RFC822-formatted email header (display name + address)
*/
Expand Down
53 changes: 50 additions & 3 deletions tests/phpunit/CRM/Case/Form/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -42,4 +41,52 @@ public function testOpeningEmailForm() {
$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();
}

}
2 changes: 1 addition & 1 deletion tests/phpunit/CiviTest/CiviCaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function setUp(): void {
* 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);
}

Expand Down

0 comments on commit b21f024

Please sign in to comment.