diff --git a/module/VuFind/src/VuFind/Mailer/Mailer.php b/module/VuFind/src/VuFind/Mailer/Mailer.php index 95b713510ad3ea342c91b1ac122885e02fc3be93..ad47a28b1729a1959919bcccad651c1ca61bb739 100644 --- a/module/VuFind/src/VuFind/Mailer/Mailer.php +++ b/module/VuFind/src/VuFind/Mailer/Mailer.php @@ -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 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 df6df8287f100b408cdac75c9854b8ead8df95e9..f18a6607e8785d68de9df5753f5b0378b71b63cb 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php @@ -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