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 343036e55c
commit 846ab25fc0
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
4 changed files with 95 additions and 17 deletions

View File

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

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

@ -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;
}));
$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' => [$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())

View File

@ -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));
}
}