dev/core#4893 Fix failure to send event emails on non-monetary evetns with no confirm...
authoreileen <emcnaughton@wikimedia.org>
Mon, 8 Jan 2024 00:07:50 +0000 (13:07 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 8 Jan 2024 00:07:50 +0000 (13:07 +1300)
CRM/Event/Form/Registration.php
Civi/Test/FormTrait.php
tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php

index 2f2086fc6c0501a5c1d5b487f0da6f3e15372aa0..6a5cff960fb36d31f037d67a8bba1fc0eb819882 100644 (file)
@@ -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);
index afd69ba6c09af28e57b9589cec4e748777b0cd51..1e6bccf628e4757a0daedec837ed1bf81c4d8904 100644 (file)
@@ -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']);
   }
index 2b012544471fbd2aaa2fdfdea0ee0b5065020934..ccbc2fc2a01126964b041189e7f837232ea6ba8d 100644 (file)
@@ -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([