mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Compare commits
7 Commits
0225181d88
...
590381482d
Author | SHA1 | Date | |
---|---|---|---|
|
590381482d | ||
|
e34463875a | ||
|
6b69db1e3b | ||
|
898ef9ba31 | ||
|
e9cd597a22 | ||
|
d448708fb3 | ||
|
4714a83333 |
@ -454,6 +454,13 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler
|
||||
|
||||
$gridState = $this->gridField->getState(false);
|
||||
$actions->push(HiddenField::create($manager->getStateKey($this->gridField), null, $gridState));
|
||||
if (ClassInfo::hasMethod($manager, 'getStateRequestVar')) {
|
||||
$stateRequestVar = $manager->getStateRequestVar();
|
||||
$stateValue = $this->getRequest()->requestVar($stateRequestVar);
|
||||
if ($stateValue) {
|
||||
$actions->push(HiddenField::create($stateRequestVar, '', $stateValue));
|
||||
}
|
||||
}
|
||||
|
||||
$actions->push($this->getRightGroupField());
|
||||
} else { // adding new record
|
||||
|
@ -85,7 +85,7 @@ class GridState extends HiddenField
|
||||
public function getData()
|
||||
{
|
||||
if (!$this->data) {
|
||||
$this->data = new GridState_Data();
|
||||
$this->data = new GridState_Data([], $this);
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
@ -99,6 +99,11 @@ class GridState extends HiddenField
|
||||
return $this->grid->getList();
|
||||
}
|
||||
|
||||
public function getGridField(): GridField
|
||||
{
|
||||
return $this->grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a json encoded string representation of this state.
|
||||
*
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace SilverStripe\Forms\GridField;
|
||||
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
|
||||
/**
|
||||
* Simple set of data, similar to stdClass, but without the notice-level
|
||||
* errors.
|
||||
@ -10,29 +12,33 @@ namespace SilverStripe\Forms\GridField;
|
||||
*/
|
||||
class GridState_Data
|
||||
{
|
||||
use GridFieldStateAware;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
protected ?GridState $state;
|
||||
|
||||
protected $defaults = [];
|
||||
|
||||
public function __construct($data = [])
|
||||
public function __construct($data = [], ?GridState $state = null)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->state = $state;
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->getData($name, new GridState_Data());
|
||||
return $this->getData($name, new GridState_Data([], $this->state));
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
// Assume first parameter is default value
|
||||
if (empty($arguments)) {
|
||||
$default = new GridState_Data();
|
||||
$default = new GridState_Data([], $this->state);
|
||||
} else {
|
||||
$default = $arguments[0];
|
||||
}
|
||||
@ -72,16 +78,25 @@ class GridState_Data
|
||||
$this->data[$name] = $default;
|
||||
} else {
|
||||
if (is_array($this->data[$name])) {
|
||||
$this->data[$name] = new GridState_Data($this->data[$name]);
|
||||
$this->data[$name] = new GridState_Data($this->data[$name], $this->state);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
public function storeData()
|
||||
{
|
||||
$stateManager = $this->getStateManager();
|
||||
if (ClassInfo::hasMethod($stateManager, 'storeState') && $this->state) {
|
||||
$stateManager->storeState($this->state->getGridField(), $this->state->Value());
|
||||
}
|
||||
}
|
||||
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->data[$name] = $value;
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
public function __isset($name)
|
||||
@ -92,6 +107,7 @@ class GridState_Data
|
||||
public function __unset($name)
|
||||
{
|
||||
unset($this->data[$name]);
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
|
101
src/Forms/GridField/SessionGridFieldStateManager.php
Normal file
101
src/Forms/GridField/SessionGridFieldStateManager.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Forms\GridField;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
|
||||
/**
|
||||
* Creates a unique key for managing GridField states in user Session, for both storage and retrieval.
|
||||
* Only stores states and generates a session key if a state is requested to be stored
|
||||
* (i.e. the state is changed from the default).
|
||||
* If a session state key is present in the request, it will always be used instead of generating a new one.
|
||||
*/
|
||||
class SessionGridFieldStateManager implements GridFieldStateManagerInterface
|
||||
{
|
||||
protected static $state_ids = [];
|
||||
|
||||
protected function getStateID(GridField $gridField, $create = false): ?string
|
||||
{
|
||||
$requestVar = $this->getStateRequestVar();
|
||||
$sessionStateID = $gridField->getForm()?->getRequestHandler()->getRequest()->requestVar($requestVar);
|
||||
if (!$sessionStateID) {
|
||||
$sessionStateID = Controller::curr()->getRequest()->requestVar($requestVar);
|
||||
}
|
||||
if ($sessionStateID) {
|
||||
return $sessionStateID;
|
||||
}
|
||||
$stateKey = $this->getStateKey($gridField);
|
||||
if (isset(self::$state_ids[$stateKey])) {
|
||||
$sessionStateID = self::$state_ids[$stateKey];
|
||||
} elseif ($create) {
|
||||
$sessionStateID = substr(md5(time()), 0, 8);
|
||||
// we don't want session state id to be strictly numeric, since this is used as a session key,
|
||||
// and session keys in php has to be usable as variable names
|
||||
if (is_numeric($sessionStateID)) {
|
||||
$sessionStateID .= 'a';
|
||||
}
|
||||
self::$state_ids[$stateKey] = $sessionStateID;
|
||||
}
|
||||
return $sessionStateID;
|
||||
}
|
||||
|
||||
public function storeState(GridField $gridField, $value = null)
|
||||
{
|
||||
$sessionStateID = $this->getStateID($gridField, true);
|
||||
$sessionState = Controller::curr()->getRequest()->getSession()->get($sessionStateID);
|
||||
if (!$sessionState) {
|
||||
$sessionState = [];
|
||||
}
|
||||
$stateKey = $this->getStateKey($gridField);
|
||||
$sessionState[$stateKey] = $value ?? $gridField->getState(false)->Value();
|
||||
Controller::curr()->getRequest()->getSession()->set($sessionStateID, $sessionState);
|
||||
}
|
||||
|
||||
public function getStateRequestVar(): string
|
||||
{
|
||||
return 'gridSessionState';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GridField $gridField
|
||||
* @return string
|
||||
*/
|
||||
public function getStateKey(GridField $gridField): string
|
||||
{
|
||||
$record = $gridField->getForm()?->getRecord();
|
||||
return $gridField->getName() . '-' . ($record ? $record->ID : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GridField $gridField
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
public function addStateToURL(GridField $gridField, string $url): string
|
||||
{
|
||||
$sessionStateID = $this->getStateID($gridField);
|
||||
if ($sessionStateID) {
|
||||
return Controller::join_links($url, '?' . $this->getStateRequestVar() . '=' . $sessionStateID);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GridField $gridField
|
||||
* @param HTTPRequest $request
|
||||
* @return string|null
|
||||
*/
|
||||
public function getStateFromRequest(GridField $gridField, HTTPRequest $request): ?string
|
||||
{
|
||||
$gridSessionStateID = $request->requestVar($this->getStateRequestVar());
|
||||
if ($gridSessionStateID) {
|
||||
$sessionState = $request->getSession()->get($gridSessionStateID);
|
||||
$stateKey = $this->getStateKey($gridField);
|
||||
if ($sessionState && isset($sessionState[$stateKey])) {
|
||||
return $sessionState[$stateKey];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -40,6 +40,7 @@ use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Exception\RfcComplianceException;
|
||||
use Closure;
|
||||
use RuntimeException;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
|
||||
/**
|
||||
* The member class which represents the users of the system
|
||||
@ -396,7 +397,7 @@ class Member extends DataObject
|
||||
public static function password_validator()
|
||||
{
|
||||
if (Injector::inst()->has(PasswordValidator::class)) {
|
||||
return Injector::inst()->get(PasswordValidator::class);
|
||||
return Deprecation::withSuppressedNotice(fn() => Injector::inst()->get(PasswordValidator::class));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace SilverStripe\Security;
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Core\Extensible;
|
||||
use SilverStripe\Core\Injector\Injectable;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\ValidationResult;
|
||||
|
||||
/**
|
||||
@ -19,6 +20,8 @@ use SilverStripe\ORM\ValidationResult;
|
||||
*
|
||||
* Member::set_password_validator($pwdValidator);
|
||||
* </code>
|
||||
*
|
||||
* @deprecated 5.4.0 Will be renamed to SilverStripe\Security\Validation\RulesPasswordValidator
|
||||
*/
|
||||
class PasswordValidator
|
||||
{
|
||||
@ -75,6 +78,15 @@ class PasswordValidator
|
||||
*/
|
||||
protected $historicalPasswordCount = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
Deprecation::notice(
|
||||
'5.4.0',
|
||||
'Will be renamed to SilverStripe\Security\Validation\RulesPasswordValidator',
|
||||
Deprecation::SCOPE_CLASS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
@ -14,6 +14,7 @@ use SilverStripe\Security\Member;
|
||||
use SilverStripe\Security\PasswordValidator;
|
||||
use SilverStripe\View\SSViewer;
|
||||
use Closure;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
|
||||
class ConfirmedPasswordFieldTest extends SapphireTest
|
||||
{
|
||||
@ -23,9 +24,11 @@ class ConfirmedPasswordFieldTest extends SapphireTest
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
PasswordValidator::singleton()
|
||||
Deprecation::withSuppressedNotice(
|
||||
fn() => PasswordValidator::singleton()
|
||||
->setMinLength(0)
|
||||
->setTestNames([]);
|
||||
->setTestNames([])
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetValue()
|
||||
|
140
tests/php/Forms/GridField/SessionGridFieldStateManagerTest.php
Normal file
140
tests/php/Forms/GridField/SessionGridFieldStateManagerTest.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Forms\Tests\GridField;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldStateManagerInterface;
|
||||
use SilverStripe\Forms\GridField\SessionGridFieldStateManager;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldPrintButtonTest\TestObject;
|
||||
|
||||
class SessionGridFieldStateManagerTest extends SapphireTest
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
// configure the injector to use the session grid field state manager
|
||||
Injector::inst()->registerService(new SessionGridFieldStateManager(), GridFieldStateManagerInterface::class);
|
||||
}
|
||||
|
||||
public function testStateKey()
|
||||
{
|
||||
$manager = new SessionGridFieldStateManager();
|
||||
$controller = new Controller();
|
||||
$form1 = new Form($controller, 'form1', new FieldList(), new FieldList());
|
||||
$testObject = new TestObject();
|
||||
$testObject->ID = 1;
|
||||
$form2 = new Form($controller, 'form2', new FieldList(), new FieldList());
|
||||
$form2->loadDataFrom($testObject);
|
||||
|
||||
$grid1 = new GridField('A');
|
||||
$grid2 = new GridField('B');
|
||||
$grid1->setForm($form1);
|
||||
$grid2->setForm($form2);
|
||||
$this->assertEquals('A-0', $manager->getStateKey($grid1));
|
||||
$this->assertEquals('B-1', $manager->getStateKey($grid2));
|
||||
}
|
||||
|
||||
public function testAddStateToURL()
|
||||
{
|
||||
$manager = new SessionGridFieldStateManager();
|
||||
$grid = new GridField('TestGrid');
|
||||
$grid->getState()->testValue = 'foo';
|
||||
$stateRequestVar = $manager->getStateRequestVar();
|
||||
$link = '/link-to/something';
|
||||
$this->assertTrue(
|
||||
preg_match(
|
||||
"|^$link\?{$stateRequestVar}=[a-zA-Z0-9]+$|",
|
||||
$manager->addStateToURL($grid, $link)
|
||||
) == 1
|
||||
);
|
||||
|
||||
$link = '/link-to/something-else?someParam=somevalue';
|
||||
$this->assertTrue(
|
||||
preg_match(
|
||||
"|^/link-to/something-else\?someParam=somevalue&{$stateRequestVar}=[a-zA-Z0-9]+$|",
|
||||
$manager->addStateToURL($grid, $link)
|
||||
) == 1
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetStateFromRequest()
|
||||
{
|
||||
$manager = new SessionGridFieldStateManager();
|
||||
|
||||
$session = new Session([]);
|
||||
$request = new HTTPRequest(
|
||||
'GET',
|
||||
'/link-to/something',
|
||||
[
|
||||
$manager->getStateRequestVar() => 'testGetStateFromRequest'
|
||||
]
|
||||
);
|
||||
$request->setSession($session);
|
||||
|
||||
$controller = new Controller();
|
||||
$controller->setRequest($request);
|
||||
$controller->pushCurrent();
|
||||
$form = new Form($controller, 'form1', new FieldList(), new FieldList());
|
||||
$grid = new GridField('TestGrid');
|
||||
$grid->setForm($form);
|
||||
|
||||
$grid->getState()->testValue = 'foo';
|
||||
$state = $grid->getState(false)->Value() ?? '{}';
|
||||
$result = $manager->getStateFromRequest($grid, $request);
|
||||
|
||||
$this->assertEquals($state, $result);
|
||||
$controller->popCurrent();
|
||||
}
|
||||
|
||||
public function testDefaultStateLeavesURLUnchanged()
|
||||
{
|
||||
$manager = new SessionGridFieldStateManager();
|
||||
$grid = new GridField('DefaultStateGrid');
|
||||
$grid->getState(false)->getData()->testValue->initDefaults(['foo' => 'bar']);
|
||||
$link = '/link-to/something';
|
||||
|
||||
$this->assertEquals('{}', $grid->getState(false)->Value());
|
||||
|
||||
$this->assertEquals(
|
||||
'/link-to/something',
|
||||
$manager->addStateToURL($grid, $link)
|
||||
);
|
||||
}
|
||||
|
||||
public function testStoreState()
|
||||
{
|
||||
$manager = new SessionGridFieldStateManager();
|
||||
|
||||
$session = new Session([]);
|
||||
$request = new HTTPRequest(
|
||||
'GET',
|
||||
'/link-to/something',
|
||||
[
|
||||
$manager->getStateRequestVar() => 'testStoreState'
|
||||
]
|
||||
);
|
||||
$request->setSession($session);
|
||||
|
||||
$controller = new Controller();
|
||||
$controller->setRequest($request);
|
||||
$controller->pushCurrent();
|
||||
$form = new Form($controller, 'form1', new FieldList(), new FieldList());
|
||||
$grid = new GridField('TestGrid');
|
||||
$grid->setForm($form);
|
||||
|
||||
$grid->getState()->testValue = 'foo';
|
||||
$state = $grid->getState(false)->Value() ?? '{}';
|
||||
|
||||
$manager->storeState($grid);
|
||||
$this->assertEquals($state, $session->get('testStoreState')['TestGrid-0']);
|
||||
|
||||
$controller->popCurrent();
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\NullHTTPRequest;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\ValidationResult;
|
||||
@ -44,9 +45,11 @@ class MemberAuthenticatorTest extends SapphireTest
|
||||
DefaultAdminService::setDefaultAdmin('admin', 'password');
|
||||
|
||||
// Enforce dummy validation (this can otherwise be influenced by recipe config)
|
||||
PasswordValidator::singleton()
|
||||
Deprecation::withSuppressedNotice(
|
||||
fn() => PasswordValidator::singleton()
|
||||
->setMinLength(0)
|
||||
->setTestNames([]);
|
||||
->setTestNames([])
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\Security\Tests;
|
||||
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Security\Group;
|
||||
use SilverStripe\Security\MemberCsvBulkLoader;
|
||||
@ -19,9 +20,11 @@ class MemberCsvBulkLoaderTest extends SapphireTest
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
PasswordValidator::singleton()
|
||||
Deprecation::withSuppressedNotice(
|
||||
fn() => PasswordValidator::singleton()
|
||||
->setMinLength(0)
|
||||
->setTestNames([]);
|
||||
->setTestNames([])
|
||||
);
|
||||
}
|
||||
|
||||
public function testNewImport()
|
||||
|
@ -8,6 +8,7 @@ use SilverStripe\Control\Cookie;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
@ -72,9 +73,11 @@ class MemberTest extends FunctionalTest
|
||||
|
||||
Member::config()->set('unique_identifier_field', 'Email');
|
||||
|
||||
PasswordValidator::singleton()
|
||||
Deprecation::withSuppressedNotice(
|
||||
fn() => PasswordValidator::singleton()
|
||||
->setMinLength(0)
|
||||
->setTestNames([]);
|
||||
->setTestNames([])
|
||||
);
|
||||
|
||||
i18n::set_locale('en_US');
|
||||
}
|
||||
@ -1742,7 +1745,7 @@ class MemberTest extends FunctionalTest
|
||||
public function testChangePasswordOnlyValidatesPlaintext()
|
||||
{
|
||||
// This validator requires passwords to be 17 characters long
|
||||
Member::set_password_validator(new MemberTest\VerySpecificPasswordValidator());
|
||||
Member::set_password_validator(Deprecation::withSuppressedNotice(fn() => new MemberTest\VerySpecificPasswordValidator()));
|
||||
|
||||
// This algorithm will never return a 17 character hash
|
||||
Security::config()->set('password_encryption_algorithm', 'blowfish');
|
||||
@ -1771,7 +1774,7 @@ class MemberTest extends FunctionalTest
|
||||
|
||||
public function testChangePasswordToBlankIsValidated()
|
||||
{
|
||||
Member::set_password_validator(new PasswordValidator());
|
||||
Member::set_password_validator(Deprecation::withSuppressedNotice(fn() => new PasswordValidator()));
|
||||
// override setup() function which setMinLength(0)
|
||||
PasswordValidator::singleton()->setMinLength(8);
|
||||
// 'test' member has a password defined in yml
|
||||
@ -1909,7 +1912,7 @@ class MemberTest extends FunctionalTest
|
||||
$password = $member->generateRandomPassword();
|
||||
$this->assertSame(20, strlen($password));
|
||||
// password validator
|
||||
$validator = new PasswordValidator();
|
||||
$validator = Deprecation::withSuppressedNotice(fn() => new PasswordValidator());
|
||||
Member::set_password_validator($validator);
|
||||
// Password length of 20 even if validator minLength is less than 20
|
||||
$validator->setMinLength(10);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\Security\Tests;
|
||||
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Security\PasswordValidator;
|
||||
@ -26,7 +27,7 @@ class PasswordValidatorTest extends SapphireTest
|
||||
|
||||
public function testValidate()
|
||||
{
|
||||
$v = new PasswordValidator();
|
||||
$v = Deprecation::withSuppressedNotice(fn() => new PasswordValidator());
|
||||
$r = $v->validate('', new Member());
|
||||
$this->assertTrue($r->isValid(), 'Empty password is valid by default');
|
||||
|
||||
@ -36,7 +37,7 @@ class PasswordValidatorTest extends SapphireTest
|
||||
|
||||
public function testValidateMinLength()
|
||||
{
|
||||
$v = new PasswordValidator();
|
||||
$v = Deprecation::withSuppressedNotice(fn() => new PasswordValidator());
|
||||
|
||||
$v->setMinLength(4);
|
||||
$r = $v->validate('123', new Member());
|
||||
@ -50,7 +51,7 @@ class PasswordValidatorTest extends SapphireTest
|
||||
public function testValidateMinScore()
|
||||
{
|
||||
// Set both score and set of tests
|
||||
$v = new PasswordValidator();
|
||||
$v = Deprecation::withSuppressedNotice(fn() => new PasswordValidator());
|
||||
$v->setMinTestScore(3);
|
||||
$v->setTestNames(["lowercase", "uppercase", "digits", "punctuation"]);
|
||||
|
||||
@ -61,7 +62,7 @@ class PasswordValidatorTest extends SapphireTest
|
||||
$this->assertTrue($r->isValid(), 'Passing enough tests');
|
||||
|
||||
// Ensure min score without tests works (uses default tests)
|
||||
$v = new PasswordValidator();
|
||||
$v = Deprecation::withSuppressedNotice(fn() => new PasswordValidator());
|
||||
$v->setMinTestScore(3);
|
||||
|
||||
$r = $v->validate('aA', new Member());
|
||||
@ -81,7 +82,7 @@ class PasswordValidatorTest extends SapphireTest
|
||||
*/
|
||||
public function testHistoricalPasswordCount()
|
||||
{
|
||||
$validator = new PasswordValidator;
|
||||
$validator = Deprecation::withSuppressedNotice(fn() => new PasswordValidator);
|
||||
$validator->setHistoricCount(3);
|
||||
Member::set_password_validator($validator);
|
||||
|
||||
|
@ -6,6 +6,7 @@ use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\NullHTTPRequest;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\ValidationResult;
|
||||
@ -43,9 +44,11 @@ class VersionedMemberAuthenticatorTest extends SapphireTest
|
||||
}
|
||||
|
||||
// Enforce dummy validation (this can otherwise be influenced by recipe config)
|
||||
PasswordValidator::singleton()
|
||||
Deprecation::withSuppressedNotice(
|
||||
fn() => PasswordValidator::singleton()
|
||||
->setMinLength(0)
|
||||
->setTestNames([]);
|
||||
->setTestNames([])
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
|
Loading…
Reference in New Issue
Block a user