From 710f2c7bb046b43ec9878ae795a181101f6d7515 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 5 Sep 2015 23:30:56 -0400 Subject: Improve unit tests --- tests/units/Auth/LdapTest.php | 122 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 tests/units/Auth/LdapTest.php (limited to 'tests/units/Auth') diff --git a/tests/units/Auth/LdapTest.php b/tests/units/Auth/LdapTest.php new file mode 100644 index 00000000..e861be98 --- /dev/null +++ b/tests/units/Auth/LdapTest.php @@ -0,0 +1,122 @@ +ldap_connect($hostname, $port); +} + +function ldap_set_option() +{ +} + +function ldap_bind($ldap, $ldap_username, $ldap_password) +{ + return LdapTest::$functions->ldap_bind($ldap, $ldap_username, $ldap_password); +} + +class LdapTest extends \Base +{ + public static $functions; + + public function setUp() + { + parent::setup(); + + self::$functions = $this + ->getMockBuilder('stdClass') + ->setMethods(array( + 'ldap_connect', + 'ldap_set_option', + 'ldap_bind', + )) + ->getMock(); + } + + public function tearDown() + { + parent::tearDown(); + self::$functions = null; + } + + public function testConnectSuccess() + { + self::$functions + ->expects($this->once()) + ->method('ldap_connect') + ->with( + $this->equalTo('my_ldap_server'), + $this->equalTo(389) + ) + ->willReturn(true); + + $ldap = new Ldap($this->container); + $this->assertNotFalse($ldap->connect()); + } + + public function testConnectFailure() + { + self::$functions + ->expects($this->once()) + ->method('ldap_connect') + ->with( + $this->equalTo('my_ldap_server'), + $this->equalTo(389) + ) + ->willReturn(false); + + $ldap = new Ldap($this->container); + $this->assertFalse($ldap->connect()); + } + + public function testBindAnonymous() + { + self::$functions + ->expects($this->once()) + ->method('ldap_bind') + ->with( + $this->equalTo('my_ldap_connection'), + $this->equalTo(null), + $this->equalTo(null) + ) + ->willReturn(true); + + $ldap = new Ldap($this->container); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'anonymous')); + } + + public function testBindUser() + { + self::$functions + ->expects($this->once()) + ->method('ldap_bind') + ->with( + $this->equalTo('my_ldap_connection'), + $this->equalTo('uid=my_user'), + $this->equalTo('my_password') + ) + ->willReturn(true); + + $ldap = new Ldap($this->container); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'user', 'uid=%s', 'something')); + } + + public function testBindProxy() + { + self::$functions + ->expects($this->once()) + ->method('ldap_bind') + ->with( + $this->equalTo('my_ldap_connection'), + $this->equalTo('someone'), + $this->equalTo('something') + ) + ->willReturn(true); + + $ldap = new Ldap($this->container); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'proxy', 'someone', 'something')); + } +} -- cgit v1.2.3