adjust and add more unit tests

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2018-07-05 11:29:19 +02:00
parent 37a20cede1
commit 7f78958056
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
4 changed files with 114 additions and 18 deletions

View File

@ -567,7 +567,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.');

View File

@ -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']],

View File

@ -622,7 +622,7 @@ class UserTest extends \Test\TestCase {
$this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('jpegPhoto'))
$this->equalTo('jpegphoto'))
->will($this->returnValue(array('this is a photo')));
$image->expects($this->once())
@ -657,6 +657,10 @@ class UserTest extends \Test\TestCase {
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
$this->access->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@ -672,11 +676,11 @@ class UserTest extends \Test\TestCase {
->method('readAttribute')
->willReturnCallback(function($dn, $attr) {
if($dn === 'uid=alice,dc=foo,dc=bar'
&& $attr === 'jpegPhoto')
&& $attr === 'jpegphoto')
{
return false;
} elseif($dn === 'uid=alice,dc=foo,dc=bar'
&& $attr === 'thumbnailPhoto')
&& $attr === 'thumbnailphoto')
{
return ['this is a photo'];
}
@ -715,6 +719,10 @@ class UserTest extends \Test\TestCase {
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
$this->access->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@ -730,11 +738,11 @@ class UserTest extends \Test\TestCase {
->method('readAttribute')
->willReturnCallback(function($dn, $attr) {
if($dn === $dn
&& $attr === 'jpegPhoto')
&& $attr === 'jpegphoto')
{
return false;
} elseif($dn === $dn
&& $attr === 'thumbnailPhoto')
&& $attr === 'thumbnailphoto')
{
return ['this is a photo'];
}
@ -765,6 +773,10 @@ class UserTest extends \Test\TestCase {
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
$this->access->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@ -783,11 +795,11 @@ class UserTest extends \Test\TestCase {
->method('readAttribute')
->willReturnCallback(function($dn, $attr) {
if($dn === $dn
&& $attr === 'jpegPhoto')
&& $attr === 'jpegphoto')
{
return false;
} elseif($dn === $dn
&& $attr === 'thumbnailPhoto')
&& $attr === 'thumbnailphoto')
{
return ['this is a photo'];
}
@ -825,6 +837,11 @@ class UserTest extends \Test\TestCase {
->with($this->equalTo($uid))
->will($this->returnValue($avatar));
$this->access->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@ -867,6 +884,10 @@ class UserTest extends \Test\TestCase {
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
$this->access->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@ -931,6 +952,10 @@ class UserTest extends \Test\TestCase {
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
$this->access->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
@ -1003,8 +1028,12 @@ class UserTest extends \Test\TestCase {
$this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo('uid=alice,dc=foo,dc=bar'),
$this->equalTo('jpegPhoto'))
$this->equalTo('jpegphoto'))
->will($this->returnValue(array('this is a photo')));
$this->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
@ -1016,7 +1045,28 @@ class UserTest extends \Test\TestCase {
$this->assertSame('this is a photo', $photo);
//make sure readAttribute is not called again but the already fetched
//photo is returned
$photo = $user->getAvatarImage();
$user->getAvatarImage();
}
public function testGetAvatarImageDisabled() {
list(, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr) =
$this->getTestInstances();
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
$this->access->expects($this->never())
->method('readAttribute')
->with($this->equalTo($dn), $this->anything());
$this->access->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn([]);
$user = new User(
$uid, $dn, $this->access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$this->assertFalse($user->getAvatarImage());
}
public function imageDataProvider() {
@ -1062,16 +1112,20 @@ class UserTest extends \Test\TestCase {
}
return $name;
}));
$this->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$record = array(
strtolower($this->connection->ldapQuotaAttribute) => array('4096'),
strtolower($this->connection->ldapEmailAttribute) => array('alice@wonderland.org'),
strtolower($this->connection->ldapUserDisplayName) => array('Aaaaalice'),
$record = [
strtolower($this->connection->ldapQuotaAttribute) => ['4096'],
strtolower($this->connection->ldapEmailAttribute) => ['alice@wonderland.org'],
strtolower($this->connection->ldapUserDisplayName) => ['Aaaaalice'],
'uid' => array($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())

View File

@ -1663,4 +1663,45 @@ class User_LDAPTest extends TestCase {
$this->assertFalse($ldap->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) {
$pluginManager = $this->createMock(UserPluginManager::class);
$pluginManager->expects($this->once())
->method('getImplementedActions')
->willReturn(0);
$access = $this->getAccessMock();
$access->connection->expects($this->any())
->method('__get')
->willReturnMap([
[$configurable, $value],
]);
$config = $this->createMock(IConfig::class);
$noti = $this->createMock(INotificationManager::class);
$session = $this->createMock(Session::class);
$backend = new User_LDAP(
$access,
$config,
$noti,
$session,
$pluginManager
);
$this->assertSame($expected, $backend->implementsActions($actionCode));
}
}