From cd1b9ed9f27e7f3f10092555b9fa83a237b17568 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:40:25 +1300 Subject: [PATCH] ENH Use symfony/validation logic (#261) --- src/Tasks/ContentReviewEmails.php | 15 ++------------ tests/php/ContentReviewNotificationTest.php | 23 --------------------- 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/src/Tasks/ContentReviewEmails.php b/src/Tasks/ContentReviewEmails.php index 86414a7..d1ea47d 100644 --- a/src/Tasks/ContentReviewEmails.php +++ b/src/Tasks/ContentReviewEmails.php @@ -8,7 +8,6 @@ use SilverStripe\Control\Email\Email; 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; @@ -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( 'Provided sender email address is invalid: "%s".', @@ -124,7 +123,7 @@ class ContentReviewEmails extends BuildTask $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; @@ -196,14 +195,4 @@ class ContentReviewEmails extends BuildTask '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); - } } diff --git a/tests/php/ContentReviewNotificationTest.php b/tests/php/ContentReviewNotificationTest.php index 8fd1216..9a4a49e 100644 --- a/tests/php/ContentReviewNotificationTest.php +++ b/tests/php/ContentReviewNotificationTest.php @@ -12,7 +12,6 @@ use SilverStripe\ContentReview\Extensions\ContentReviewOwner; 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; @@ -145,28 +144,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(); - - Deprecation::withSuppressedNotice(function () use ($method, $task, $member) { - $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 *