From adb574401e905d3c637257d8a56f3c748b56a364 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 8 Jan 2024 13:07:50 +1300 Subject: [PATCH] dev/core#4893 Fix failure to send event emails on non-monetary evetns with no confirm page --- CRM/Event/Form/Registration.php | 2 +- Civi/Test/FormTrait.php | 3 +++ .../CRM/Event/Form/Registration/ConfirmTest.php | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 2f2086fc6c..6a5cff960f 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -1573,7 +1573,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { $this->set('participantInfo', $participantInfo); } - if ($this->getPaymentProcessorObject()->supports('noReturn') + if (!$this->getEventValue('is_monetary') || $this->getPaymentProcessorObject()->supports('noReturn') ) { // Send mail Confirmation/Receipt. $this->sendMails($params, $registerByID, $participantCount); diff --git a/Civi/Test/FormTrait.php b/Civi/Test/FormTrait.php index afd69ba6c0..1e6bccf628 100644 --- a/Civi/Test/FormTrait.php +++ b/Civi/Test/FormTrait.php @@ -76,6 +76,9 @@ trait FormTrait { * @param int $mailIndex */ protected function assertMailSentContainingString(string $string, int $mailIndex = 0): void { + if (!$this->form->getMail()) { + $this->fail('No mail sent'); + } $mail = $this->form->getMail()[$mailIndex]; $this->assertStringContainsString(preg_replace('/\s+/', '', $string), preg_replace('/\s+/', '', $mail['body']), 'String not found: ' . $string . "\n" . $mail['body']); } diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index 2b01254447..ccbc2fc2a0 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -613,6 +613,18 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { $this->sentMail = $mailUtil->getAllMessages(); } + /** + * Ensure an email is sent when confirm is disabled for unpaid events. + */ + public function testSubmitUnpaidEventNoConfirm(): void { + $this->eventCreateUnpaid(['is_confirm_enabled' => FALSE]); + $form = $this->getTestForm('CRM_Event_Form_Registration_Register', [ + 'email-Primary' => 'demo@example.com', + ], ['id' => $this->getEventID()]); + $form->processForm(); + $this->assertMailSentContainingStrings(['Event']); + } + public function testRegistrationWithoutCiviContributeEnabled(): void { $mut = new CiviMailUtils($this, TRUE); $event = $this->eventCreateUnpaid([ -- 2.25.1