1<?php 2/** 3 * Test the Horde_Auth_Kolab:: class. 4 * 5 * Copyright 2010-2017 Horde LLC (http://www.horde.org/) 6 * 7 * See the enclosed file COPYING for license information (LGPL). If you 8 * did not receive this file, see http://www.horde.org/licenses/lgpl21. 9 * 10 * @category Horde 11 * @package Auth 12 * @subpackage UnitTests 13 * @author Gunnar Wrobel <wrobel@pardus.de> 14 * @license http://www.horde.org/licenses/lgpl21 LGPL-2.1 15 * @link http://pear.horde.org/index.php?package=Auth 16 */ 17class Horde_Auth_Unit_KolabTest extends Horde_Auth_TestCase 18{ 19 public function setUp() 20 { 21 if (!interface_exists('Horde_Kolab_Session')) { 22 $this->markTestSkipped('The Kolab_Session package is apparently not installed (Interface Horde_Kolab_Session is unavailable).'); 23 } 24 $this->kolab = $this->getMock('Horde_Kolab_Session'); 25 $this->driver = new Horde_Auth_Kolab(array('kolab' => $this->kolab)); 26 } 27 28 public function testAuthenticate() 29 { 30 $this->kolab->expects($this->once()) 31 ->method('connect') 32 ->with('user', array('password' => 'password')) 33 ->will($this->returnValue(null)); 34 $this->assertTrue($this->driver->authenticate('user', array('password' => 'password'))); 35 } 36 37 public function testBadLogin() 38 { 39 $this->kolab->expects($this->once()) 40 ->method('connect') 41 ->with('user', array('password' => 'incorrect')) 42 ->will($this->throwException(new Horde_Kolab_Session_Exception_Badlogin())); 43 try { 44 $this->driver->authenticate('user', array('password' => 'incorrect')); 45 } catch (Horde_Auth_Exception $e) { 46 $this->assertEquals(Horde_Auth::REASON_BADLOGIN, $e->getCode()); 47 } 48 } 49 50 public function testFailure() 51 { 52 $this->kolab->expects($this->once()) 53 ->method('connect') 54 ->with('user', array('password' => '')) 55 ->will($this->throwException(new Horde_Kolab_Session_Exception())); 56 try { 57 $this->driver->authenticate('user', array('password' => '')); 58 } catch (Horde_Auth_Exception $e) { 59 $this->assertEquals(Horde_Auth::REASON_FAILED, $e->getCode()); 60 } 61 } 62 63 public function testUidRewrite() 64 { 65 $this->kolab->expects($this->once()) 66 ->method('connect') 67 ->with('user', array('password' => 'password')) 68 ->will($this->returnValue(null)); 69 $this->kolab->expects($this->once()) 70 ->method('getMail') 71 ->will($this->returnValue('user@example.com')); 72 $this->driver->authenticate('user', array('password' => 'password')); 73 $this->assertEquals( 74 'user@example.com', $this->driver->getCredential('userId') 75 ); 76 } 77} 78