diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php index f18a6607e8785d68de9df5753f5b0378b71b63cb..becec6bda4baace3c6612aa33d72d69c2e83e07b 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php @@ -72,6 +72,34 @@ class MailerTest extends \VuFindTest\Unit\TestCase $mailer->send('bad@bad', 'from@example.com', 'subject', 'body'); } + /** + * Test empty to address. + * + * @return void + * @expectedException VuFind\Exception\Mail + * @expectedExceptionMessage Invalid Recipient Email Address + */ + public function testEmptyTo() + { + $transport = $this->getMock('Zend\Mail\Transport\TransportInterface'); + $mailer = new Mailer($transport); + $mailer->send('', 'from@example.com', 'subject', 'body'); + } + + /** + * Test that we only accept one recipient by default + * + * @return void + * @expectedException VuFind\Exception\Mail + * @expectedExceptionMessage Too Many Email Recipients + */ + public function testTooManyRecipients() + { + $transport = $this->getMock('Zend\Mail\Transport\TransportInterface'); + $mailer = new Mailer($transport); + $mailer->send('one@test.com;two@test.com', 'from@example.com', 'subject', 'body'); + } + /** * Test bad from address. * @@ -110,7 +138,7 @@ class MailerTest extends \VuFindTest\Unit\TestCase { $viewCallback = function ($in) { return $in['msgUrl'] == 'http://foo' - && $in['to'] == 'to@example.com' + && $in['to'] == 'to@example.com;to2@example.com' && $in['from'] == 'from@example.com' && $in['message'] == 'message'; }; @@ -120,15 +148,23 @@ class MailerTest extends \VuFindTest\Unit\TestCase ->will($this->returnValue('body')); $callback = function ($message) { - return '<to@example.com>' == $message->getTo()->current()->toString() + $to = $message->getTo(); + return $to->has('to@example.com') + && $to->has('to2@example.com') + && 2 == count($to) && '<from@example.com>' == $message->getFrom()->current()->toString() + && '<cc@example.com>' == $message->getCc()->current()->toString() && 'body' == $message->getBody() && 'Library Catalog Search Result' == $message->getSubject(); }; $transport = $this->getMock('Zend\Mail\Transport\TransportInterface'); $transport->expects($this->once())->method('send')->with($this->callback($callback)); $mailer = new Mailer($transport); - $mailer->sendLink('to@example.com', 'from@example.com', 'message', 'http://foo', $view); + $mailer->setMaxRecipients(2); + $mailer->sendLink( + 'to@example.com;to2@example.com', 'from@example.com', 'message', 'http://foo', $view, null, + 'cc@example.com' + ); } /**