Skip to content

Commit

Permalink
fix BookingCodesMessage:sendMessage() wrong $attachment for prepareMail
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nelarsen committed Jul 1, 2024
1 parent b516275 commit 871f0c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Messages/BookingCodesMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
9 changes: 9 additions & 0 deletions tests/php/Service/BookingCodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
7 changes: 7 additions & 0 deletions tests/php/View/BookingCodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 871f0c7

Please sign in to comment.