Skip to content

Commit

Permalink
ENH Use symfony/validation logic (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Oct 2, 2024
1 parent 47245c3 commit cd1b9ed
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
15 changes: 2 additions & 13 deletions src/Tasks/ContentReviewEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SilverStripe\Dev\BuildTask;
use SilverStripe\PolyExecution\PolyOutput;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\Model\List\SS_List;
Expand All @@ -34,7 +33,7 @@ class ContentReviewEmails extends BuildTask
protected function execute(InputInterface $input, PolyOutput $output): int
{
$senderEmail = SiteConfig::current_site_config()->ReviewFrom;
if (!Deprecation::withSuppressedNotice(fn() => $this->isValidEmail($senderEmail))) {
if (!Email::is_valid_address($senderEmail)) {
$output->writeln(
sprintf(
'<error>Provided sender email address is invalid: "%s".</>',
Expand Down Expand Up @@ -124,7 +123,7 @@ protected function notifyOwner($ownerID, SS_List $pages)
$siteConfig = SiteConfig::current_site_config();
$owner = Member::get()->byID($ownerID);

if (!Deprecation::withSuppressedNotice(fn() => $this->isValidEmail($owner->Email))) {
if (!Email::is_valid_address($owner->Email)) {
$this->invalid_emails[] = $owner->Name . ': ' . $owner->Email;

return;
Expand Down Expand Up @@ -196,14 +195,4 @@ protected function getTemplateVariables($recipient, $config, $pages)
'ToEmail' => $recipient->Email,
];
}

/**
* Check validity of email
* @deprecated 5.4.0 Use SilverStripe\Control\Email\Email::is_valid_address() instead.
*/
protected function isValidEmail(?string $email): bool
{
Deprecation::notice('5.4.0', 'Use ' . Email::class . '::is_valid_address() instead.');
return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
}
}
23 changes: 0 additions & 23 deletions tests/php/ContentReviewNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use SilverStripe\ContentReview\Extensions\SiteTreeContentReview;
use SilverStripe\ContentReview\Tasks\ContentReviewEmails;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Group;
Expand Down Expand Up @@ -145,28 +144,6 @@ public function testContentReviewNeeded()
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();

Deprecation::withSuppressedNotice(function () use ($method, $task, $member) {
$this->assertTrue($method->invokeArgs($task, [$member->Email]));
$this->assertTrue($method->invokeArgs($task, ['[email protected]']));

$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
*
Expand Down

0 comments on commit cd1b9ed

Please sign in to comment.