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 08591e088cabc0425f8c2e77453e1ad8fb742a72..56ff7da3135bcf349dd469136910a4afbfcad8ea 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 *