diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/Core/Ldap/LdapUserTest.php | 70 | ||||
-rw-r--r-- | tests/units/Subscriber/LdapUserPhotoSubscriberTest.php | 83 |
2 files changed, 153 insertions, 0 deletions
diff --git a/tests/units/Core/Ldap/LdapUserTest.php b/tests/units/Core/Ldap/LdapUserTest.php index d861871e..02b9331e 100644 --- a/tests/units/Core/Ldap/LdapUserTest.php +++ b/tests/units/Core/Ldap/LdapUserTest.php @@ -52,6 +52,7 @@ class LdapUserTest extends Base 'getAttributeEmail', 'getAttributeName', 'getAttributeGroup', + 'getAttributePhoto', 'getGroupUserFilter', 'getGroupAdminDn', 'getGroupManagerDn', @@ -136,10 +137,79 @@ class LdapUserTest extends Base $this->assertEquals('My LDAP user', $user->getName()); $this->assertEquals('user1@localhost', $user->getEmail()); $this->assertEquals(Role::APP_USER, $user->getRole()); + $this->assertSame('', $user->getPhoto()); $this->assertEquals(array(), $user->getExternalGroupIds()); $this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes()); } + public function testGetUserWithPhoto() + { + $entries = new Entries(array( + 'count' => 1, + 0 => array( + 'count' => 2, + 'dn' => 'uid=my_ldap_user,ou=People,dc=kanboard,dc=local', + 'displayname' => array( + 'count' => 1, + 0 => 'My LDAP user', + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 'samaccountname' => array( + 'count' => 1, + 0 => 'my_ldap_user', + ), + 'jpegPhoto' => array( + 'count' => 1, + 0 => 'my photo', + ), + 0 => 'displayname', + 1 => 'mail', + 2 => 'samaccountname', + ) + )); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('ou=People,dc=kanboard,dc=local'), + $this->equalTo('(uid=my_ldap_user)') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(true)); + + $this->query + ->expects($this->once()) + ->method('getEntries') + ->will($this->returnValue($entries)); + + $this->user + ->expects($this->any()) + ->method('getAttributePhoto') + ->will($this->returnValue('jpegPhoto')); + + $this->user + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); + + $user = $this->user->find('(uid=my_ldap_user)'); + $this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user); + $this->assertEquals('my photo', $user->getPhoto()); + } + public function testGetUserWithAdminRole() { $entries = new Entries(array( diff --git a/tests/units/Subscriber/LdapUserPhotoSubscriberTest.php b/tests/units/Subscriber/LdapUserPhotoSubscriberTest.php new file mode 100644 index 00000000..df44d232 --- /dev/null +++ b/tests/units/Subscriber/LdapUserPhotoSubscriberTest.php @@ -0,0 +1,83 @@ +<?php + +use Kanboard\Core\Security\Role; +use Kanboard\Event\UserProfileSyncEvent; +use Kanboard\Model\User; +use Kanboard\Subscriber\LdapUserPhotoSubscriber; +use Kanboard\User\DatabaseUserProvider; +use Kanboard\User\LdapUserProvider; + +require_once __DIR__.'/../Base.php'; + +class LdapUserPhotoSubscriberTest extends Base +{ + public function testWhenTheProviderIsNotLdap() + { + $userProvider = new DatabaseUserProvider(array()); + $subscriber = new LdapUserPhotoSubscriber($this->container); + $userModel = new User($this->container); + + $userModel->update(array('id' => 1, 'avatar_path' => 'my avatar')); + $user = $userModel->getById(1); + + $subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider)); + + $user = $userModel->getById(1); + $this->assertEquals('my avatar', $user['avatar_path']); + } + + public function testWhenTheUserHaveLdapPhoto() + { + $userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array(), 'my photo'); + $subscriber = new LdapUserPhotoSubscriber($this->container); + $userModel = new User($this->container); + $user = $userModel->getById(1); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), 'my photo'); + + + $subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider)); + + $user = $userModel->getById(1); + $this->assertStringStartsWith('avatars', $user['avatar_path']); + } + + public function testWhenTheUserDoNotHaveLdapPhoto() + { + $userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array()); + $subscriber = new LdapUserPhotoSubscriber($this->container); + $userModel = new User($this->container); + $user = $userModel->getById(1); + + $this->container['objectStorage'] + ->expects($this->never()) + ->method('put'); + + $subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider)); + + $user = $userModel->getById(1); + $this->assertEmpty($user['avatar_path']); + } + + public function testWhenTheUserAlreadyHaveAvatar() + { + $userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array(), 'my photo'); + $subscriber = new LdapUserPhotoSubscriber($this->container); + $userModel = new User($this->container); + + $userModel->update(array('id' => 1, 'avatar_path' => 'my avatar')); + $user = $userModel->getById(1); + + $this->container['objectStorage'] + ->expects($this->never()) + ->method('put'); + + $subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider)); + + $user = $userModel->getById(1); + $this->assertEquals('my avatar', $user['avatar_path']); + } +} |