From f69fbf5ea6d02d3fa7d1bbfb9089b2fb060845be Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 21 Jan 2019 15:15:52 -0800 Subject: [PATCH] Make the "Test" adapter support both SMS and email Summary: Depends on D20012. Ref T920. If you have a test adapter configured, it should swallow messages and prevent them from ever hitting a lower-priority adapter. Make the test adapter support SMS so this actually happens. Test Plan: Ran `bin/mail send-test --type sms ...` with a test adapter (first) and a Twilio adapter (second). Got SMS swallowed by test adapter instead of live SMS messages. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T920 Differential Revision: https://secure.phabricator.com/D20013 --- .../adapter/PhabricatorMailTestAdapter.php | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/applications/metamta/adapter/PhabricatorMailTestAdapter.php b/src/applications/metamta/adapter/PhabricatorMailTestAdapter.php index f0840ba7bf..a6258a8874 100644 --- a/src/applications/metamta/adapter/PhabricatorMailTestAdapter.php +++ b/src/applications/metamta/adapter/PhabricatorMailTestAdapter.php @@ -33,6 +33,7 @@ final class PhabricatorMailTestAdapter public function getSupportedMessageTypes() { return array( PhabricatorMailEmailMessage::MESSAGETYPE, + PhabricatorMailSMSMessage::MESSAGETYPE, ); } @@ -63,6 +64,28 @@ final class PhabricatorMailTestAdapter pht('Unit Test (Temporary)')); } + switch ($message->getMessageType()) { + case PhabricatorMailEmailMessage::MESSAGETYPE: + $guts = $this->newEmailGuts($message); + break; + case PhabricatorMailSMSMessage::MESSAGETYPE: + $guts = $this->newSMSGuts($message); + break; + } + + $guts['did-send'] = true; + $this->guts = $guts; + } + + public function getBody() { + return idx($this->guts, 'body'); + } + + public function getHTMLBody() { + return idx($this->guts, 'html-body'); + } + + private function newEmailGuts(PhabricatorMailExternalMessage $message) { $guts = array(); $from = $message->getFromAddress(); @@ -123,19 +146,16 @@ final class PhabricatorMailTestAdapter } $guts['attachments'] = $file_list; - $guts['did-send'] = true; - - $this->guts = $guts; + return $guts; } + private function newSMSGuts(PhabricatorMailExternalMessage $message) { + $guts = array(); - public function getBody() { - return idx($this->guts, 'body'); + $guts['to'] = $message->getToNumber(); + $guts['body'] = $message->getTextBody(); + + return $guts; } - public function getHTMLBody() { - return idx($this->guts, 'html-body'); - } - - }