From d51c3512ba70316460e8e068c4bb22bf9eb752d7 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 25 Sep 2014 16:21:17 -0400
Subject: [PATCH] More tests.

---
 .../src/VuFindTest/Auth/ManagerTest.php       | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php
index 08591e088ca..56ff7da3135 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php
@@ -299,6 +299,78 @@ class ManagerTest extends \VuFindTest\Unit\TestCase
         $this->assertEquals($user, $manager->isLoggedIn());
     }
 
+    /**
+     * Test successful login
+     *
+     * @return void
+     */
+    public function testSuccessfulLogin()
+    {
+        $user = $this->getMockUser();
+        $request = $this->getMockRequest();
+        $pm = $this->getMockPluginManager();
+        $db = $pm->get('Database');
+        $db->expects($this->once())->method('authenticate')->with($request)->will($this->returnValue($user));
+        $manager = $this->getManager(array(), null, null, $pm);
+        $this->assertFalse($manager->isLoggedIn());
+        $this->assertEquals($user, $manager->login($request));
+        $this->assertEquals($user, $manager->isLoggedIn());
+    }
+
+    /**
+     * Test unsuccessful login (\VuFind\Exception\PasswordSecurity)
+     *
+     * @return void
+     * @expectedException \VuFind\Exception\PasswordSecurity
+     * @expectedExceptionMessage Boom
+     */
+    public function testPasswordSecurityException()
+    {
+        $e = new \VuFind\Exception\PasswordSecurity('Boom');
+        $request = $this->getMockRequest();
+        $pm = $this->getMockPluginManager();
+        $db = $pm->get('Database');
+        $db->expects($this->once())->method('authenticate')->with($request)->will($this->throwException($e));
+        $manager = $this->getManager(array(), null, null, $pm);
+        $manager->login($request);
+    }
+
+    /**
+     * Test unsuccessful login (\VuFind\Exception\Auth)
+     *
+     * @return void
+     * @expectedException \VuFind\Exception\Auth
+     * @expectedExceptionMessage Blam
+     */
+    public function testAuthException()
+    {
+        $e = new \VuFind\Exception\Auth('Blam');
+        $request = $this->getMockRequest();
+        $pm = $this->getMockPluginManager();
+        $db = $pm->get('Database');
+        $db->expects($this->once())->method('authenticate')->with($request)->will($this->throwException($e));
+        $manager = $this->getManager(array(), null, null, $pm);
+        $manager->login($request);
+    }
+
+    /**
+     * Test that unexpected exceptions get mapped to technical errors.
+     *
+     * @return void
+     * @expectedException \VuFind\Exception\Auth
+     * @expectedExceptionMessage authentication_error_technical
+     */
+    public function testUnanticipatedException()
+    {
+        $e = new \Exception('What happened here?');
+        $request = $this->getMockRequest();
+        $pm = $this->getMockPluginManager();
+        $db = $pm->get('Database');
+        $db->expects($this->once())->method('authenticate')->with($request)->will($this->throwException($e));
+        $manager = $this->getManager(array(), null, null, $pm);
+        $manager->login($request);
+    }
+
     /**
      * Test update password
      *
-- 
GitLab