Skip to content

Commit

Permalink
ENH Use symfony/validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Sep 24, 2024
1 parent 4b8f758 commit 840a0db
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 30 deletions.
12 changes: 2 additions & 10 deletions src/Tasks/ContentReviewEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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".',
Expand Down Expand Up @@ -116,7 +116,7 @@ protected function notifyOwner($ownerID, SS_List $pages)
$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;
Expand Down Expand Up @@ -188,12 +188,4 @@ protected function getTemplateVariables($recipient, $config, $pages)
'ToEmail' => $recipient->Email,
];
}

/**
* Check validity of email
*/
protected function isValidEmail(?string $email): bool
{
return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
}
}
20 changes: 0 additions & 20 deletions tests/php/ContentReviewNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,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();

$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 840a0db

Please sign in to comment.