From 52dd4e083e0e70a1ac691d7f1d889571a96f1798 Mon Sep 17 00:00:00 2001 From: Samuele Masetto Date: Mon, 24 Jan 2022 14:35:23 +0100 Subject: [PATCH] update doc block, work on `PDFLetterCommonTest` unit test compatibility with `contactId` parameter --- CRM/Contribute/Form/Task/PDFLetter.php | 2 +- CRM/Utils/Mail.php | 1 + tests/events/hook_civicrm_alterMailParams.evch.php | 2 +- .../CRM/Contribute/Form/Task/PDFLetterCommonTest.php | 10 ++++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/Form/Task/PDFLetter.php b/CRM/Contribute/Form/Task/PDFLetter.php index 00e4738897..a01c6fc8d1 100644 --- a/CRM/Contribute/Form/Task/PDFLetter.php +++ b/CRM/Contribute/Form/Task/PDFLetter.php @@ -465,7 +465,7 @@ class CRM_Contribute_Form_Task_PDFLetter extends CRM_Contribute_Form_Task { } $defaults = [ - 'contact_id' => $contact['id'], + 'contactId' => $contact['id'], 'toName' => $contact['display_name'], 'toEmail' => $contact['email'], 'text' => '', diff --git a/CRM/Utils/Mail.php b/CRM/Utils/Mail.php index 2043f9494d..65d4df06d9 100644 --- a/CRM/Utils/Mail.php +++ b/CRM/Utils/Mail.php @@ -159,6 +159,7 @@ class CRM_Utils_Mail { * fullPath : complete pathname to the file * mime_type: mime type of the attachment * cleanName: the user friendly name of the attachmment + * contactId : contact id to send the email to (optional) * * @param array $params * (by reference). diff --git a/tests/events/hook_civicrm_alterMailParams.evch.php b/tests/events/hook_civicrm_alterMailParams.evch.php index a5b69122f3..cc331f1aa2 100644 --- a/tests/events/hook_civicrm_alterMailParams.evch.php +++ b/tests/events/hook_civicrm_alterMailParams.evch.php @@ -27,6 +27,7 @@ return new class() extends EventCheck implements HookInterface { 'autoSubmitted' => ['type' => 'bool', 'for' => 'messageTemplate'], 'Message-ID' => ['type' => 'string', 'for' => ['messageTemplate', 'singleEmail']], 'messageId' => ['type' => 'string', 'for' => ['messageTemplate', 'singleEmail']], + 'contactId' => ['type' => 'int|NULL', 'for' => ['messageTemplate' /* deprecated in favor of tokenContext[contactId] */, 'singleEmail']], // ## Envelope: CiviMail/Flexmailer @@ -49,7 +50,6 @@ return new class() extends EventCheck implements HookInterface { 'tokenContext' => ['type' => 'array', 'for' => 'messageTemplate'], 'tplParams' => ['type' => 'array', 'for' => 'messageTemplate'], - 'contactId' => ['type' => 'int|NULL', 'for' => 'messageTemplate' /* deprecated in favor of tokenContext[contactId] */], 'workflow' => [ 'regex' => '/^([a-zA-Z_]+)$/', 'type' => 'string', diff --git a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php index 9dc66032a2..8bcc1826bf 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -39,6 +39,9 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { parent::setUp(); $this->_individualId = $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']); $this->_docTypes = CRM_Core_SelectValues::documentApplicationType(); + $hooks = \CRM_Utils_Hook::singleton(); + $hooks->setHook('civicrm_alterMailParams', + array($this, 'hook_alterMailParams')); } /** @@ -680,4 +683,11 @@ value=$contact_aggregate+$contribution.total_amount} return $this->callAPISuccess('Contribution', 'create', $contributionParams)['id']; } + /** + * @see CRM_Utils_Hook::alterMailParams + */ + public function hook_alterMailParams(&$params, $context = NULL) { + $this->assertTrue(isset($params['contactId'])); + } + } -- 2.25.1