diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-07-05 11:29:19 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-07-05 11:50:49 +0200 |
commit | 846ab25fc0dc34b2456d5a7914298006d06ddaee (patch) | |
tree | 77829c3060197f70112469c33449d28dd78e86ed /apps/user_ldap | |
parent | 343036e55c0b41891fc86aafc0cbb3077503ab64 (diff) | |
download | nextcloud-server-846ab25fc0dc34b2456d5a7914298006d06ddaee.tar.gz nextcloud-server-846ab25fc0dc34b2456d5a7914298006d06ddaee.zip |
adjust and add more unit tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/lib/Configuration.php | 2 | ||||
-rw-r--r-- | apps/user_ldap/tests/ConfigurationTest.php | 1 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/UserTest.php | 84 | ||||
-rw-r--r-- | apps/user_ldap/tests/User_LDAPTest.php | 27 |
4 files changed, 96 insertions, 18 deletions
diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index 3871003fae9..25d64859596 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -568,7 +568,7 @@ class Configuration { if($attribute === '') { return $defaultAttributes; } - return [$attribute]; + return [strtolower($attribute)]; } if($value !== self::AVATAR_PREFIX_DEFAULT) { \OC::$server->getLogger()->warning('Invalid config value to ldapUserAvatarRule; falling back to default.'); diff --git a/apps/user_ldap/tests/ConfigurationTest.php b/apps/user_ldap/tests/ConfigurationTest.php index 26217ea130c..ab1312860fa 100644 --- a/apps/user_ldap/tests/ConfigurationTest.php +++ b/apps/user_ldap/tests/ConfigurationTest.php @@ -112,6 +112,7 @@ class ConfigurationTest extends \Test\TestCase { return [ ['none', []], ['data:selfie', ['selfie']], + ['data:sELFie', ['selfie']], ['data:', ['jpegphoto', 'thumbnailphoto']], ['default', ['jpegphoto', 'thumbnailphoto']], ['invalid#', ['jpegphoto', 'thumbnailphoto']], diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php index aa6498be082..837c72a3a31 100644 --- a/apps/user_ldap/tests/User/UserTest.php +++ b/apps/user_ldap/tests/User/UserTest.php @@ -503,7 +503,7 @@ class UserTest extends \Test\TestCase { $this->access->expects($this->once()) ->method('readAttribute') ->with($this->equalTo($this->dn), - $this->equalTo('jpegPhoto')) + $this->equalTo('jpegphoto')) ->will($this->returnValue(['this is a photo'])); $this->image->expects($this->once()) @@ -536,6 +536,11 @@ class UserTest extends \Test\TestCase { ->with($this->equalTo($this->uid)) ->will($this->returnValue($avatar)); + $this->connection->expects($this->any()) + ->method('resolveRule') + ->with('avatar') + ->willReturn(['jpegphoto', 'thumbnailphoto']); + $this->user->updateAvatar(); } @@ -544,11 +549,11 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->willReturnCallback(function($dn, $attr) { if($dn === $this->dn - && $attr === 'jpegPhoto') + && $attr === 'jpegphoto') { return false; } elseif($dn === $this->dn - && $attr === 'thumbnailPhoto') + && $attr === 'thumbnailphoto') { return ['this is a photo']; } @@ -585,6 +590,11 @@ class UserTest extends \Test\TestCase { ->with($this->equalTo($this->uid)) ->will($this->returnValue($avatar)); + $this->connection->expects($this->any()) + ->method('resolveRule') + ->with('avatar') + ->willReturn(['jpegphoto', 'thumbnailphoto']); + $this->user->updateAvatar(); } @@ -593,11 +603,11 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->willReturnCallback(function($dn, $attr) { if($dn === $this->dn - && $attr === 'jpegPhoto') + && $attr === 'jpegphoto') { return false; } elseif($dn === $this->dn - && $attr === 'thumbnailPhoto') + && $attr === 'thumbnailphoto') { return ['this is a photo']; } @@ -626,6 +636,11 @@ class UserTest extends \Test\TestCase { $this->avatarManager->expects($this->never()) ->method('getAvatar'); + $this->connection->expects($this->any()) + ->method('resolveRule') + ->with('avatar') + ->willReturn(['jpegphoto', 'thumbnailphoto']); + $this->user->updateAvatar(); } @@ -634,11 +649,11 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->willReturnCallback(function($dn, $attr) { if($dn === $this->dn - && $attr === 'jpegPhoto') + && $attr === 'jpegphoto') { return false; } elseif($dn === $this->dn - && $attr === 'thumbnailPhoto') + && $attr === 'thumbnailphoto') { return ['this is a photo']; } @@ -676,6 +691,11 @@ class UserTest extends \Test\TestCase { ->with($this->equalTo($this->uid)) ->will($this->returnValue($avatar)); + $this->connection->expects($this->any()) + ->method('resolveRule') + ->with('avatar') + ->willReturn(['jpegphoto', 'thumbnailphoto']); + $this->assertFalse($this->user->updateAvatar()); } @@ -710,6 +730,11 @@ class UserTest extends \Test\TestCase { $this->avatarManager->expects($this->never()) ->method('getAvatar'); + $this->connection->expects($this->any()) + ->method('resolveRule') + ->with('avatar') + ->willReturn(['jpegphoto', 'thumbnailphoto']); + $this->user->updateAvatar(); } @@ -756,6 +781,11 @@ class UserTest extends \Test\TestCase { $this->anything()) ->will($this->returnValue(true)); + $this->connection->expects($this->any()) + ->method('resolveRule') + ->with('avatar') + ->willReturn(['jpegphoto', 'thumbnailphoto']); + $this->user->update(); } @@ -802,8 +832,12 @@ class UserTest extends \Test\TestCase { $this->access->expects($this->once()) ->method('readAttribute') ->with($this->equalTo($this->dn), - $this->equalTo('jpegPhoto')) + $this->equalTo('jpegphoto')) ->will($this->returnValue(['this is a photo'])); + $this->connection->expects($this->any()) + ->method('resolveRule') + ->with('avatar') + ->willReturn(['jpegphoto', 'thumbnailphoto']); $photo = $this->user->getAvatarImage(); $this->assertSame('this is a photo', $photo); @@ -812,6 +846,18 @@ class UserTest extends \Test\TestCase { $this->user->getAvatarImage(); } + public function testGetAvatarImageDisabled() { + $this->access->expects($this->never()) + ->method('readAttribute') + ->with($this->equalTo($this->dn), $this->anything()); + $this->connection->expects($this->any()) + ->method('resolveRule') + ->with('avatar') + ->willReturn([]); + + $this->assertFalse($this->user->getAvatarImage()); + } + public function imageDataProvider() { return [ [ false, false ], @@ -859,16 +905,20 @@ class UserTest extends \Test\TestCase { } return $name; })); - - $record = array( - strtolower($this->connection->ldapQuotaAttribute) => array('4096'), - strtolower($this->connection->ldapEmailAttribute) => array('alice@wonderland.org'), - strtolower($this->connection->ldapUserDisplayName) => array('Aaaaalice'), + $this->connection->expects($this->any()) + ->method('resolveRule') + ->with('avatar') + ->willReturn(['jpegphoto', 'thumbnailphoto']); + + $record = [ + strtolower($this->connection->ldapQuotaAttribute) => ['4096'], + strtolower($this->connection->ldapEmailAttribute) => ['alice@wonderland.org'], + strtolower($this->connection->ldapUserDisplayName) => ['Aaaaalice'], 'uid' => [$this->uid], - 'homedirectory' => array('Alice\'s Folder'), - 'memberof' => array('cn=groupOne', 'cn=groupTwo'), - 'jpegphoto' => array('here be an image') - ); + 'homedirectory' => ['Alice\'s Folder'], + 'memberof' => ['cn=groupOne', 'cn=groupTwo'], + 'jpegphoto' => ['here be an image'] + ]; foreach($requiredMethods as $method) { $userMock->expects($this->once()) diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 927a7550f60..447b91decff 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -1396,4 +1396,31 @@ class User_LDAPTest extends TestCase { $this->assertFalse($this->backend->createUser('uid', 'password')); } + + public function actionProvider() { + return [ + [ 'ldapUserAvatarRule', 'default', Backend::PROVIDE_AVATAR, true] , + [ 'ldapUserAvatarRule', 'data:selfiePhoto', Backend::PROVIDE_AVATAR, true], + [ 'ldapUserAvatarRule', 'none', Backend::PROVIDE_AVATAR, false], + [ 'turnOnPasswordChange', 0, Backend::SET_PASSWORD, false], + [ 'turnOnPasswordChange', 1, Backend::SET_PASSWORD, true], + ]; + } + + /** + * @dataProvider actionProvider + */ + public function testImplementsAction($configurable, $value, $actionCode, $expected) { + $this->pluginManager->expects($this->once()) + ->method('getImplementedActions') + ->willReturn(0); + + $this->connection->expects($this->any()) + ->method('__get') + ->willReturnMap([ + [$configurable, $value], + ]); + + $this->assertSame($expected, $this->backend->implementsActions($actionCode)); + } } |