1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

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
This commit is contained in:
epriestley 2019-01-21 15:15:52 -08:00
parent af71c51f0a
commit f69fbf5ea6

View file

@ -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');
}
}