mirror of
https://github.com/silverstripe/silverstripe-contentreview
synced 2024-10-22 17:05:47 +02:00
ENH Use symfony/validation logic
This commit is contained in:
parent
4b8f7586d2
commit
840a0db70c
@ -30,7 +30,7 @@ class ContentReviewEmails extends BuildTask
|
||||
*/
|
||||
public function run($request)
|
||||
{
|
||||
if (!$this->isValidEmail($senderEmail = SiteConfig::current_site_config()->ReviewFrom)) {
|
||||
if (!Email::is_valid_address($senderEmail = SiteConfig::current_site_config()->ReviewFrom)) {
|
||||
throw new RuntimeException(
|
||||
sprintf(
|
||||
'Provided sender email address is invalid: "%s".',
|
||||
@ -116,7 +116,7 @@ class ContentReviewEmails extends BuildTask
|
||||
$siteConfig = SiteConfig::current_site_config();
|
||||
$owner = Member::get()->byID($ownerID);
|
||||
|
||||
if (!$this->isValidEmail($owner->Email)) {
|
||||
if (!Email::is_valid_address($owner->Email)) {
|
||||
$this->invalid_emails[] = $owner->Name . ': ' . $owner->Email;
|
||||
|
||||
return;
|
||||
@ -188,12 +188,4 @@ class ContentReviewEmails extends BuildTask
|
||||
'ToEmail' => $recipient->Email,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validity of email
|
||||
*/
|
||||
protected function isValidEmail(?string $email): bool
|
||||
{
|
||||
return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
}
|
||||
|
@ -133,26 +133,6 @@ class ContentReviewNotificationTest extends SapphireTest
|
||||
DBDatetime::clear_mock_now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that provided email is valid
|
||||
*/
|
||||
public function testIsValidEmail()
|
||||
{
|
||||
$class = new ReflectionClass(ContentReviewEmails::class);
|
||||
$method = $class->getMethod('isValidEmail');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$member = $this->objFromFixture(Member::class, 'author');
|
||||
$task = new ContentReviewEmails();
|
||||
|
||||
$this->assertTrue($method->invokeArgs($task, [$member->Email]));
|
||||
$this->assertTrue($method->invokeArgs($task, ['correct.email@example.com']));
|
||||
|
||||
$this->assertFalse($method->invokeArgs($task, [null]));
|
||||
$this->assertFalse($method->invokeArgs($task, ['broken.email']));
|
||||
$this->assertFalse($method->invokeArgs($task, ['broken@email']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all pages except those passes in to the $ids parameter
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user