From 61fabc937354aff1b4098078a908fc50b4109112 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Fri, 21 Feb 2025 12:20:46 -0500 Subject: [PATCH] adjust test --- .../Civi/ScheduledCommunications/SendTest.php | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ext/scheduled_communications/tests/phpunit/Civi/ScheduledCommunications/SendTest.php b/ext/scheduled_communications/tests/phpunit/Civi/ScheduledCommunications/SendTest.php index f3863d307b20..553c2223a77f 100644 --- a/ext/scheduled_communications/tests/phpunit/Civi/ScheduledCommunications/SendTest.php +++ b/ext/scheduled_communications/tests/phpunit/Civi/ScheduledCommunications/SendTest.php @@ -71,33 +71,39 @@ public function testBirthdayMessage():void { 'body_html' => '

Your birthday is tomorrow!

', 'subject' => 'Happy birthday {contact.first_name}!', ]); - $this->assertCronRuns([ + $yearToUse = date('Y') + 1; + $cronRuns = [ [ // No birthdays tomorrow - 'time' => '2025-04-02 04:00:00', + 'time' => $yearToUse . '-04-02 04:00:00', 'to' => [], 'subjects' => [], ], [ - 'time' => '2025-02-18 04:00:00', + 'time' => $yearToUse . '-02-18 04:00:00', 'to' => [["b@$lastName"]], 'all_recipients' => ["b@$lastName;alt1@$lastName"], 'subjects' => ['Happy birthday B!'], ], [ // Upcoming birthday but contact is deceased - 'time' => '2025-02-08 04:00:00', + 'time' => $yearToUse . '-02-08 04:00:00', 'to' => [], 'subjects' => [], ], - [ + ]; + // We can only run this case if the current year is a leap year. + // CRM_Utils_Time doesn't change what mysql CURDATE returns, so it will fail. + if ((new \IntlGregorianCalendar())->isLeapYear(date('Y'))) { + $cronRuns[] = [ // On a non-leap-year, birthday is the 28th - 'time' => '2025-02-27 04:00:00', + 'time' => $yearToUse . '-02-27 04:00:00', 'to' => [["a@$lastName"], ["aa@$lastName"]], 'all_recipients' => ["a@$lastName;alt1@$lastName", "aa@$lastName;alt1@$lastName"], 'subjects' => ['Happy birthday A!', 'Happy birthday AA!'], - ], - ]); + ]; + } + $this->assertCronRuns($cronRuns); } public function testAlternateRecipients():void {