fix time rollover
authordemeritcowboy <demeritcowboy@hotmail.com>
Fri, 25 Jun 2021 22:03:03 +0000 (18:03 -0400)
committerdemeritcowboy <demeritcowboy@hotmail.com>
Fri, 25 Jun 2021 22:03:03 +0000 (18:03 -0400)
CRM/Contact/BAO/Contact/Utils.php
tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php

index 70655e2ba1b37f404d7aa1b53d92185dc331035d..84aa8fb09d4ac58981884712ccb434e07c33f592 100644 (file)
@@ -177,7 +177,7 @@ WHERE  id IN ( $idString )
     }
 
     if (!$ts) {
-      $ts = time();
+      $ts = CRM_Utils_Time::time();
     }
 
     if (!$live) {
index 0da0b3cb7b4d85a5c9dc79ec92ac37da6584a743..fa5003a2ea92c447bc6ad714c5119417b90c04b0 100644 (file)
@@ -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();
   }
 
   /**