Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Member form validator fix. #11395

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Security/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\TestMailer;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\ConfirmedPasswordField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
Expand Down Expand Up @@ -696,6 +697,20 @@ public function getValidator()
return $validator;
}

public function getCMSCompositeValidator(): CompositeValidator
{
// Add the member validator before extension point, so it's much easier to customise this
// via an extension
$this->beforeExtending(
'updateCMSCompositeValidator',
function (CompositeValidator $compositeValidator): void {
$memberValidator = $this->getValidator();
$compositeValidator->addValidator($memberValidator);
}
);

return parent::getCMSCompositeValidator();
}

/**
* Temporarily act as the specified user, limited to a $callback, but
Expand Down
21 changes: 21 additions & 0 deletions tests/php/Core/Validation/MemberValidatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace SilverStripe\Core\Tests\Validation;

use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Member;
use SilverStripe\Security\Member_Validator;

class MemberValidatorTest extends SapphireTest
{
protected $usesDatabase = false;

public function testMemberValidator(): void
{
$member = new Member();
$compositeValidator = $member->getCMSCompositeValidator();

$memberValidators = $compositeValidator->getValidatorsByType(Member_Validator::class);
$this->assertCount(1, $memberValidators, 'We expect exactly one member validator');
}
}
Loading