The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit 73fea9a4 authored by Demian Katz's avatar Demian Katz
Browse files

Expanded test coverage to new functionality.

parent cd6f4d93
No related merge requests found
...@@ -72,6 +72,34 @@ class MailerTest extends \VuFindTest\Unit\TestCase ...@@ -72,6 +72,34 @@ class MailerTest extends \VuFindTest\Unit\TestCase
$mailer->send('bad@bad', 'from@example.com', 'subject', 'body'); $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. * Test bad from address.
* *
...@@ -110,7 +138,7 @@ class MailerTest extends \VuFindTest\Unit\TestCase ...@@ -110,7 +138,7 @@ class MailerTest extends \VuFindTest\Unit\TestCase
{ {
$viewCallback = function ($in) { $viewCallback = function ($in) {
return $in['msgUrl'] == 'http://foo' return $in['msgUrl'] == 'http://foo'
&& $in['to'] == 'to@example.com' && $in['to'] == 'to@example.com;to2@example.com'
&& $in['from'] == 'from@example.com' && $in['from'] == 'from@example.com'
&& $in['message'] == 'message'; && $in['message'] == 'message';
}; };
...@@ -120,15 +148,23 @@ class MailerTest extends \VuFindTest\Unit\TestCase ...@@ -120,15 +148,23 @@ class MailerTest extends \VuFindTest\Unit\TestCase
->will($this->returnValue('body')); ->will($this->returnValue('body'));
$callback = function ($message) { $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() && '<from@example.com>' == $message->getFrom()->current()->toString()
&& '<cc@example.com>' == $message->getCc()->current()->toString()
&& 'body' == $message->getBody() && 'body' == $message->getBody()
&& 'Library Catalog Search Result' == $message->getSubject(); && 'Library Catalog Search Result' == $message->getSubject();
}; };
$transport = $this->getMock('Zend\Mail\Transport\TransportInterface'); $transport = $this->getMock('Zend\Mail\Transport\TransportInterface');
$transport->expects($this->once())->method('send')->with($this->callback($callback)); $transport->expects($this->once())->method('send')->with($this->callback($callback));
$mailer = new Mailer($transport); $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'
);
} }
/** /**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment