From: demeritcowboy Date: Wed, 8 Sep 2021 01:06:27 +0000 (-0400) Subject: add test without tokens X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2676b35feb64269b135241693df17ca8309a8f55;p=civicrm-core.git add test without tokens --- diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index 036d4335f4..a7c9750100 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -1289,6 +1289,79 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $mut->stop(); } + /** + * This is different from SentEmailBasic to try to help prevent code that + * assumes an email always has tokens in it. + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + */ + public function testSendEmailBasicWithoutAnyTokens(): void { + $contactId = $this->individualCreate(); + + // create a logged in USER since the code references it for sendEmail user. + $loggedInUser = $this->createLoggedInUser(); + + $contactDetailsIntersectKeys = [ + 'contact_id' => '', + 'sort_name' => '', + 'display_name' => '', + 'do_not_email' => '', + 'preferred_mail_format' => '', + 'is_deceased' => '', + 'email' => '', + 'on_hold' => '', + ]; + + $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactId, 'return' => array_keys($contactDetailsIntersectKeys)]); + $contactDetailsIntersectKeys = [ + 'contact_id' => '', + 'sort_name' => '', + 'display_name' => '', + 'do_not_email' => '', + 'preferred_mail_format' => '', + 'is_deceased' => '', + 'email' => '', + 'on_hold' => '', + ]; + $contactDetails = [ + array_intersect_key($contact, $contactDetailsIntersectKeys), + ]; + + $subject = __FUNCTION__ . ' subject'; + $html = __FUNCTION__ . ' html'; + $text = __FUNCTION__ . ' text'; + + $mut = new CiviMailUtils($this, TRUE); + [$sent, $activity_ids] = CRM_Activity_BAO_Activity::sendEmail( + $contactDetails, + $subject, + $text, + $html, + $contact['email'], + $loggedInUser, + $from = __FUNCTION__ . '@example.com' + ); + + $activity = $this->callAPISuccessGetSingle('Activity', ['id' => $activity_ids[0], 'return' => ['details', 'subject']]); + $details = "-ALTERNATIVE ITEM 0- +$html +-ALTERNATIVE ITEM 1- +$text +-ALTERNATIVE END- +"; + $this->assertEquals($activity['details'], $details, 'Activity details does not match.'); + $this->assertEquals($activity['subject'], $subject, 'Activity subject does not match.'); + $mut->checkMailLog([ + "From: $from", + 'To: Anthony Anderson ', + "Subject: $subject", + $html, + $text, + ]); + $mut->stop(); + } + public function testSendEmailWithCampaign() { // Create a contact and contactDetails array. $contactId = $this->individualCreate();