Permalink
Browse files

+ Modified LdapManager to be fulfill the Symfony CS

+ Added a UnitTest and fixed a bug ;)
  • Loading branch information...
1 parent cfca3d8 commit 656139b98892905abcc61986db08ed249eee69ee @uklawitter uklawitter committed Jun 18, 2012
Showing with 51 additions and 4 deletions.
  1. +5 −4 Ldap/LdapManager.php
  2. +41 −0 Tests/Ldap/LdapManagerTest.php
  3. +5 −0 Tests/TestUser.php
@@ -95,11 +95,12 @@ protected function hydrate(LdapUserInterface $user, array $entry)
$ldapValue = $entry[$attr['ldap_attr']];
$value = null;
- if ($ldapValue['count'] == 1) {
+ if ((array_key_exists('count', $ldapValue) && $ldapValue['count'] == 1)
+ || !array_key_exists('count', $ldapValue)) {
+
$value = $ldapValue[0];
- }
- else {
- $value = array_slice($ldapValue, 1, $ldapValue['count']);
+ } else {
+ $value = array_slice($ldapValue, 1);
}
call_user_func(array($user, $attr['user_method']), $value);
@@ -163,6 +163,47 @@ public function testHydrate()
}
/**
+ * @covers FR3D\LdapBundle\Ldap\LdapManager::hydrate
+ */
+ public function testHydrateArray()
+ {
+ $params = array(
+ 'baseDn' => 'ou=Groups,dc=example,dc=com',
+ 'filter' => '(attr0=value0)',
+ 'attributes' => array(
+ array(
+ 'ldap_attr' => 'roles',
+ 'user_method' => 'setRoles',
+ )
+ ),
+ );
+
+ $this->ldapManager = new LdapManager($this->connection, $this->userManager, $params);
+
+ $reflectionClass = new \ReflectionClass('FR3D\LdapBundle\Ldap\LdapManager');
+ $method = $reflectionClass->getMethod('hydrate');
+ $method->setAccessible(true);
+
+ $user = new TestUser();
+ $roles = array(
+ 'count' => 3,
+ 0 => 'ROLE1',
+ 1 => 'ROLE2',
+ 2 => 'ROLE3'
+ );
+
+ $entry = array(
+ 'dn' => 'ou=group, dc=host, dc=foo',
+ 'roles' => $roles,
+ );
+
+ $method->invoke($this->ldapManager, $user, $entry);
+
+ $this->assertEquals(array_slice($roles, 1), $user->getRoles());
+ $this->assertTrue($user->isEnabled());
+ }
+
+ /**
* @covers FR3D\LdapBundle\Ldap\LdapManager::bind
*/
public function testBind()
View
@@ -86,6 +86,11 @@ public function setLocked($locked)
$this->locked = $locked;
}
+ public function setRoles($roles)
+ {
+ $this->roles = $roles;
+ }
+
/**
* {@inheritDoc}
*/

0 comments on commit 656139b

Please sign in to comment.