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 === '') { if($attribute === '') {
return $defaultAttributes; return $defaultAttributes;
} }
return [$attribute]; return [strtolower($attribute)];
} }
if($value !== self::AVATAR_PREFIX_DEFAULT) { if($value !== self::AVATAR_PREFIX_DEFAULT) {
\OC::$server->getLogger()->warning('Invalid config value to ldapUserAvatarRule; falling back to 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 [ return [
['none', []], ['none', []],
['data:selfie', ['selfie']], ['data:selfie', ['selfie']],
['data:sELFie', ['selfie']],
['data:', ['jpegphoto', 'thumbnailphoto']], ['data:', ['jpegphoto', 'thumbnailphoto']],
['default', ['jpegphoto', 'thumbnailphoto']], ['default', ['jpegphoto', 'thumbnailphoto']],
['invalid#', ['jpegphoto', 'thumbnailphoto']], ['invalid#', ['jpegphoto', 'thumbnailphoto']],

View File

@ -503,7 +503,7 @@ class UserTest extends \Test\TestCase {
$this->access->expects($this->once()) $this->access->expects($this->once())
->method('readAttribute') ->method('readAttribute')
->with($this->equalTo($this->dn), ->with($this->equalTo($this->dn),
$this->equalTo('jpegPhoto')) $this->equalTo('jpegphoto'))
->will($this->returnValue(['this is a photo'])); ->will($this->returnValue(['this is a photo']));
$this->image->expects($this->once()) $this->image->expects($this->once())
@ -536,6 +536,11 @@ class UserTest extends \Test\TestCase {
->with($this->equalTo($this->uid)) ->with($this->equalTo($this->uid))
->will($this->returnValue($avatar)); ->will($this->returnValue($avatar));
$this->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$this->user->updateAvatar(); $this->user->updateAvatar();
} }
@ -544,11 +549,11 @@ class UserTest extends \Test\TestCase {
->method('readAttribute') ->method('readAttribute')
->willReturnCallback(function($dn, $attr) { ->willReturnCallback(function($dn, $attr) {
if($dn === $this->dn if($dn === $this->dn
&& $attr === 'jpegPhoto') && $attr === 'jpegphoto')
{ {
return false; return false;
} elseif($dn === $this->dn } elseif($dn === $this->dn
&& $attr === 'thumbnailPhoto') && $attr === 'thumbnailphoto')
{ {
return ['this is a photo']; return ['this is a photo'];
} }
@ -585,6 +590,11 @@ class UserTest extends \Test\TestCase {
->with($this->equalTo($this->uid)) ->with($this->equalTo($this->uid))
->will($this->returnValue($avatar)); ->will($this->returnValue($avatar));
$this->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$this->user->updateAvatar(); $this->user->updateAvatar();
} }
@ -593,11 +603,11 @@ class UserTest extends \Test\TestCase {
->method('readAttribute') ->method('readAttribute')
->willReturnCallback(function($dn, $attr) { ->willReturnCallback(function($dn, $attr) {
if($dn === $this->dn if($dn === $this->dn
&& $attr === 'jpegPhoto') && $attr === 'jpegphoto')
{ {
return false; return false;
} elseif($dn === $this->dn } elseif($dn === $this->dn
&& $attr === 'thumbnailPhoto') && $attr === 'thumbnailphoto')
{ {
return ['this is a photo']; return ['this is a photo'];
} }
@ -626,6 +636,11 @@ class UserTest extends \Test\TestCase {
$this->avatarManager->expects($this->never()) $this->avatarManager->expects($this->never())
->method('getAvatar'); ->method('getAvatar');
$this->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$this->user->updateAvatar(); $this->user->updateAvatar();
} }
@ -634,11 +649,11 @@ class UserTest extends \Test\TestCase {
->method('readAttribute') ->method('readAttribute')
->willReturnCallback(function($dn, $attr) { ->willReturnCallback(function($dn, $attr) {
if($dn === $this->dn if($dn === $this->dn
&& $attr === 'jpegPhoto') && $attr === 'jpegphoto')
{ {
return false; return false;
} elseif($dn === $this->dn } elseif($dn === $this->dn
&& $attr === 'thumbnailPhoto') && $attr === 'thumbnailphoto')
{ {
return ['this is a photo']; return ['this is a photo'];
} }
@ -676,6 +691,11 @@ class UserTest extends \Test\TestCase {
->with($this->equalTo($this->uid)) ->with($this->equalTo($this->uid))
->will($this->returnValue($avatar)); ->will($this->returnValue($avatar));
$this->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$this->assertFalse($this->user->updateAvatar()); $this->assertFalse($this->user->updateAvatar());
} }
@ -710,6 +730,11 @@ class UserTest extends \Test\TestCase {
$this->avatarManager->expects($this->never()) $this->avatarManager->expects($this->never())
->method('getAvatar'); ->method('getAvatar');
$this->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$this->user->updateAvatar(); $this->user->updateAvatar();
} }
@ -756,6 +781,11 @@ class UserTest extends \Test\TestCase {
$this->anything()) $this->anything())
->will($this->returnValue(true)); ->will($this->returnValue(true));
$this->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$this->user->update(); $this->user->update();
} }
@ -802,8 +832,12 @@ class UserTest extends \Test\TestCase {
$this->access->expects($this->once()) $this->access->expects($this->once())
->method('readAttribute') ->method('readAttribute')
->with($this->equalTo($this->dn), ->with($this->equalTo($this->dn),
$this->equalTo('jpegPhoto')) $this->equalTo('jpegphoto'))
->will($this->returnValue(['this is a photo'])); ->will($this->returnValue(['this is a photo']));
$this->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$photo = $this->user->getAvatarImage(); $photo = $this->user->getAvatarImage();
$this->assertSame('this is a photo', $photo); $this->assertSame('this is a photo', $photo);
@ -812,6 +846,18 @@ class UserTest extends \Test\TestCase {
$this->user->getAvatarImage(); $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() { public function imageDataProvider() {
return [ return [
[ false, false ], [ false, false ],
@ -859,16 +905,20 @@ class UserTest extends \Test\TestCase {
} }
return $name; return $name;
})); }));
$this->connection->expects($this->any())
->method('resolveRule')
->with('avatar')
->willReturn(['jpegphoto', 'thumbnailphoto']);
$record = array( $record = [
strtolower($this->connection->ldapQuotaAttribute) => array('4096'), strtolower($this->connection->ldapQuotaAttribute) => ['4096'],
strtolower($this->connection->ldapEmailAttribute) => array('alice@wonderland.org'), strtolower($this->connection->ldapEmailAttribute) => ['alice@wonderland.org'],
strtolower($this->connection->ldapUserDisplayName) => array('Aaaaalice'), strtolower($this->connection->ldapUserDisplayName) => ['Aaaaalice'],
'uid' => [$this->uid], 'uid' => [$this->uid],
'homedirectory' => array('Alice\'s Folder'), 'homedirectory' => ['Alice\'s Folder'],
'memberof' => array('cn=groupOne', 'cn=groupTwo'), 'memberof' => ['cn=groupOne', 'cn=groupTwo'],
'jpegphoto' => array('here be an image') 'jpegphoto' => ['here be an image']
); ];
foreach($requiredMethods as $method) { foreach($requiredMethods as $method) {
$userMock->expects($this->once()) $userMock->expects($this->once())

View File

@ -1396,4 +1396,31 @@ class User_LDAPTest extends TestCase {
$this->assertFalse($this->backend->createUser('uid', 'password')); $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));
}
} }