From 71593061dfa40a1e6d30ffef3e6ae4a884c430b2 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Fri, 25 Jun 2021 18:03:03 -0400 Subject: [PATCH] fix time rollover --- CRM/Contact/BAO/Contact/Utils.php | 2 +- tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 70655e2ba1..84aa8fb09d 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -177,7 +177,7 @@ WHERE id IN ( $idString ) } if (!$ts) { - $ts = time(); + $ts = CRM_Utils_Time::time(); } if (!$live) { diff --git a/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php b/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php index 0da0b3cb7b..fa5003a2ea 100644 --- a/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php +++ b/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php @@ -139,6 +139,10 @@ London, 90210 * @throws \CiviCRM_API3_Exception */ public function testContactTokens(): void { + // Freeze the time at the start of the test, so checksums don't suffer from second rollovers. + putenv('TIME_FUNC=frozen'); + CRM_Utils_Time::setTime(date('Y-m-d H:i:s')); + $this->createCustomGroupWithFieldsOfAllTypes([]); $tokenData = $this->getAllContactTokens(); $address = $this->setupContactFromTokeData($tokenData); @@ -173,6 +177,10 @@ Default Domain Name $this->assertEquals($expected_parts[0], $returned_parts[0]); $this->assertApproxEquals($expected_parts[1], $returned_parts[1], 2); $this->assertEquals($expected_parts[2], $returned_parts[2]); + + // reset time + putenv('TIME_FUNC'); + CRM_Utils_Time::resetTime(); } /** -- 2.25.1