From 73fea9a4bde2b1c3d2823423ba52f7b5f71a3a2f Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 13 Feb 2015 14:16:08 -0500
Subject: [PATCH] Expanded test coverage to new functionality.

---
 .../src/VuFindTest/Mailer/MailerTest.php      | 42 +++++++++++++++++--
 1 file changed, 39 insertions(+), 3 deletions(-)

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 f18a6607e87..becec6bda4b 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'
+        );
     }
 
     /**
-- 
GitLab