standalone: password reset tests working
authorRich Lott / Artful Robot <code.commits@artfulrobot.uk>
Mon, 2 Oct 2023 11:25:44 +0000 (12:25 +0100)
committerRich Lott / Artful Robot <code.commits@artfulrobot.uk>
Mon, 2 Oct 2023 11:25:44 +0000 (12:25 +0100)
ext/standaloneusers/CRM/Standaloneusers/Upgrader.php
ext/standaloneusers/tests/phpunit/Civi/Standalone/SecurityTest.php

index d53b2721c0dd8f6e1e12428632d38898e163dc03..2cb14247c15348ef3872ffd9b0223e9e8e5e02e2 100644 (file)
@@ -81,16 +81,13 @@ class CRM_Standaloneusers_Upgrader extends CRM_Extension_Upgrader_Base {
     ];
 
     // Create a "reserved" template. This is a pristine copy provided for reference.
-    MessageTemplate::create(FALSE)
-      ->setValues([
-        'values' => $baseTpl + ['is_reserved' => 1, 'is_default' => 0],
-      ]);
-
-    // Create a default template. This is live. The administrator may edit/customize.
-    MessageTemplate::create(FALSE)
-      ->setValues([
-        'values' => $baseTpl + ['is_reserved' => 0, 'is_default' => 1],
-      ]);
+    MessageTemplate::save(FALSE)
+      ->setDefaults($baseTpl)
+      ->setRecords([
+        ['is_reserved' => TRUE, 'is_default' => FALSE],
+        ['is_reserved' => FALSE, 'is_default' => TRUE],
+      ])
+      ->execute()->getArrayCopy();
 
   }
 
index 7da17a2941e9f48870377cac4e3e65cb91fa7880..29a74ee8cd2cad51ae14c8f085aa20d9e0c2bc77 100644 (file)
@@ -418,11 +418,12 @@ class SecurityTest extends \PHPUnit\Framework\TestCase implements EndToEndInterf
     // Check the message template generation
     $token = \Civi\Api4\Action\User\SendPasswordReset::updateToken($userID);
     $workflow = $security->preparePasswordResetWorkflow($user, $token);
+    $this->assertNotNull($workflow);
     $result = $workflow->renderTemplate();
 
-    $this->assertStringContainsString($token, $result['text']);
-    $this->assertStringContainsString(htmlspecialchars($token), $result['html']);
-    $this->assertEquals('x', $result['subject']);
+    $this->assertMatchesRegularExpression(';https?://[^/]+/civicrm/login/password.*' . $token . ';', $result['text']);
+    $this->assertMatchesRegularExpression(';https?://[^/]+/civicrm/login/password.*' . $token . ';', $result['html']);
+    $this->assertEquals('Password reset link for Demonstrators Anonymous', $result['subject']);
   }
 
   protected function deleteStuffWeMade() {