From 871f0c7d82f159837a4f737b31012577f69f57b9 Mon Sep 17 00:00:00 2001 From: Nils Larsen Date: Mon, 1 Jul 2024 11:43:52 +0200 Subject: [PATCH] fix BookingCodesMessage:sendMessage() wrong $attachment for prepareMail prepareMail expects an associative array or null as $attachment, but sendMessage passed a associate array inside a array (which was actually working due to magic in Message::addStringAttachments) or null inside an array, for the case where an ical-attachment is not to be sent. The [null] was misunderstood by SendNotificationMail() as a mail with an attachment, calling phpmailer with illegal parameters and causing warnings. The mail was seemingly send anyway, totally expected without attachment. So the change is a fix to avoid warnings, but it does not change the behavior for the user in any way. Additionally, add two more tests to cover the (non-default) case when sending of ical-attachment for BookingCodes is ON --- src/Messages/BookingCodesMessage.php | 2 +- tests/php/Service/BookingCodesTest.php | 9 +++++++++ tests/php/View/BookingCodesTest.php | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Messages/BookingCodesMessage.php b/src/Messages/BookingCodesMessage.php index a646aa558..63263bdb3 100644 --- a/src/Messages/BookingCodesMessage.php +++ b/src/Messages/BookingCodesMessage.php @@ -95,7 +95,7 @@ public function sendMessage(): bool { 'item' => $timeframe->getItem(), 'location' => $timeframe->getLocation(), ], - [ $attachment] + $attachment ); add_action( 'commonsbooking_mail_sent',array($this,'updateEmailSent'), 5, 2 ); diff --git a/tests/php/Service/BookingCodesTest.php b/tests/php/Service/BookingCodesTest.php index 4cd78a544..20b2650fe 100644 --- a/tests/php/Service/BookingCodesTest.php +++ b/tests/php/Service/BookingCodesTest.php @@ -43,6 +43,15 @@ public function testSendBookingCodesMessage() { $this->assertMatchesRegularExpression('/' . implode('|',self::bookingCodes) . '/',$email->get_sent()->body); } + /* As testSendBookingCodesMessage but cover the case when Ical is attached */ + public function testSendBookingCodesMessageWithICal() { + + // enable sending of Ical attachment + Settings::updateOption( 'commonsbooking_options_bookingcodes', 'mail-booking-codes-attach-ical', 'on'); + + $this->testSendBookingCodesMessage(); + } + /* Tests some exceptional calculations for emailing booking codes (range and next event) */ public function testGetCronParams() { $this->setCronParams(strtotime("2020-02-29"),strtotime("2023-01-15")); diff --git a/tests/php/View/BookingCodesTest.php b/tests/php/View/BookingCodesTest.php index 5aca2d294..e026493a4 100644 --- a/tests/php/View/BookingCodesTest.php +++ b/tests/php/View/BookingCodesTest.php @@ -51,6 +51,13 @@ public function testEmailCodes() { $this->assertMatchesRegularExpression('/' . implode('|',self::bookingCodes) . '/',$email->get_sent()->body); } + /* As above but cover the case when ical is attached */ + public function testEmailCodesWithIcal() { + + Settings::updateOption( 'commonsbooking_options_bookingcodes', 'mail-booking-codes-attach-ical', 'on'); + + $this->testEmailCodes(); + } public function testInitialCronEmailEvent() { $todayDate = new \DateTime(self::CURRENT_DATE);