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

More tests; more accurate comments.

parent 0899e752
No related merge requests found
......@@ -170,15 +170,14 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface
/**
* Send an email message representing a link.
*
* @param string $to Recipient email address
* @param string $from Sender email address
* @param string $msg User notes to include in
* @param string $to Recipient email address
* @param string $from Sender email address
* @param string $msg User notes to include in
* message
* @param string $url URL to share
* @param \Zend\View\Renderer\RendererInterface $view View object (used to
* render email templates)
* @param string $subject Subject for email
* (optional)
* @param string $url URL to share
* @param \Zend\View\Renderer\PhpRenderer $view View object (used to render
* email templates)
* @param string $subject Subject for email (optional)
*
* @throws MailException
* @return void
......@@ -201,13 +200,13 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface
/**
* Send an email message representing a record.
*
* @param string $to Recipient email address
* @param string $from Sender email address
* @param string $msg User notes to include in
* @param string $to Recipient email address
* @param string $from Sender email address
* @param string $msg User notes to include in
* message
* @param \VuFind\RecordDriver\AbstractBase $record Record being emailed
* @param \Zend\View\Renderer\RendererInterface $view View object (used to
* render email templates)
* @param \VuFind\RecordDriver\AbstractBase $record Record being emailed
* @param \Zend\View\Renderer\PhpRenderer $view View object (used to render
* email templates)
*
* @throws MailException
* @return void
......
......@@ -100,4 +100,67 @@ class MailerTest extends \VuFindTest\Unit\TestCase
$mailer = new Mailer($transport);
$mailer->send('to@example.com', 'from@example.com', 'subject', 'body');
}
/**
* Test sendLink
*
* @return void
*/
public function testSendLink()
{
$viewCallback = function ($in) {
return $in['msgUrl'] == 'http://foo'
&& $in['to'] == 'to@example.com'
&& $in['from'] == 'from@example.com'
&& $in['message'] == 'message';
};
$view = $this->getMock('Zend\View\Renderer\PhpRenderer', array('partial'));
$view->expects($this->once())->method('partial')
->with($this->equalTo('Email/share-link.phtml'), $this->callback($viewCallback))
->will($this->returnValue('body'));
$callback = function ($message) {
return '<to@example.com>' == $message->getTo()->current()->toString()
&& '<from@example.com>' == $message->getFrom()->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);
}
/**
* Test sendRecord
*
* @return void
*/
public function testSendRecord()
{
$driver = $this->getMock('VuFind\RecordDriver\AbstractBase');
$driver->expects($this->once())->method('getBreadcrumb')->will($this->returnValue('breadcrumb'));
$viewCallback = function ($in) use ($driver) {
return $in['driver'] == $driver
&& $in['to'] == 'to@example.com'
&& $in['from'] == 'from@example.com'
&& $in['message'] == 'message';
};
$view = $this->getMock('Zend\View\Renderer\PhpRenderer', array('partial'));
$view->expects($this->once())->method('partial')
->with($this->equalTo('Email/record.phtml'), $this->callback($viewCallback))
->will($this->returnValue('body'));
$callback = function ($message) {
return '<to@example.com>' == $message->getTo()->current()->toString()
&& '<from@example.com>' == $message->getFrom()->current()->toString()
&& 'body' == $message->getBody()
&& 'Library Catalog Record: breadcrumb' == $message->getSubject();
};
$transport = $this->getMock('Zend\Mail\Transport\TransportInterface');
$transport->expects($this->once())->method('send')->with($this->callback($callback));
$mailer = new Mailer($transport);
$mailer->sendRecord('to@example.com', 'from@example.com', 'message', $driver, $view);
}
}
\ No newline at end of file
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