From 840a0db70cbcdc4b28dafcf974c9ea51cf6f0fbf Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Tue, 24 Sep 2024 17:42:47 +1200 Subject: [PATCH] ENH Use symfony/validation logic --- src/Tasks/ContentReviewEmails.php | 12 ++---------- tests/php/ContentReviewNotificationTest.php | 20 -------------------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/Tasks/ContentReviewEmails.php b/src/Tasks/ContentReviewEmails.php index f84846c..fe7520f 100644 --- a/src/Tasks/ContentReviewEmails.php +++ b/src/Tasks/ContentReviewEmails.php @@ -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 @@ 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; @@ -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); - } } diff --git a/tests/php/ContentReviewNotificationTest.php b/tests/php/ContentReviewNotificationTest.php index 241dd9c..d724012 100644 --- a/tests/php/ContentReviewNotificationTest.php +++ b/tests/php/ContentReviewNotificationTest.php @@ -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, ['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 *