diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-05-07 12:59:35 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-05-07 12:59:35 -0400 |
commit | 300dabe6b4e9e648c1111363fad8154def7cfb5f (patch) | |
tree | 1eb9cac2b56401e3c6f0fe8b46233f01909d4885 /tests/units/Subscriber/LdapUserPhotoSubscriberTest.php | |
parent | 94989663eca0d0dc2e9adb6d3190f0ab3cca9d2a (diff) |
Added support for LDAP user photo profile
Diffstat (limited to 'tests/units/Subscriber/LdapUserPhotoSubscriberTest.php')
-rw-r--r-- | tests/units/Subscriber/LdapUserPhotoSubscriberTest.php | 83 |
1 files changed, 83 insertions, 0 deletions
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']); + } +} |