From: Rich Lott / Artful Robot Date: Mon, 2 Oct 2023 11:25:44 +0000 (+0100) Subject: standalone: password reset tests working X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4400181599e085f10d93819b48771fd189520620;p=civicrm-core.git standalone: password reset tests working --- diff --git a/ext/standaloneusers/CRM/Standaloneusers/Upgrader.php b/ext/standaloneusers/CRM/Standaloneusers/Upgrader.php index d53b2721c0..2cb14247c1 100644 --- a/ext/standaloneusers/CRM/Standaloneusers/Upgrader.php +++ b/ext/standaloneusers/CRM/Standaloneusers/Upgrader.php @@ -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(); } diff --git a/ext/standaloneusers/tests/phpunit/Civi/Standalone/SecurityTest.php b/ext/standaloneusers/tests/phpunit/Civi/Standalone/SecurityTest.php index 7da17a2941..29a74ee8cd 100644 --- a/ext/standaloneusers/tests/phpunit/Civi/Standalone/SecurityTest.php +++ b/ext/standaloneusers/tests/phpunit/Civi/Standalone/SecurityTest.php @@ -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() {