2015-12-01 21:08:42 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Roeland Jago Douma <rullzer@owncloud.com>
|
2016-10-03 11:57:29 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-12-01 21:08:42 +00:00
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
2016-10-03 11:57:29 +00:00
|
|
|
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
2015-12-01 21:08:42 +00:00
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2016-05-19 07:27:21 +00:00
|
|
|
|
|
|
|
namespace Test;
|
|
|
|
|
2016-10-03 11:57:29 +00:00
|
|
|
use OC\Avatar;
|
2015-12-01 21:08:42 +00:00
|
|
|
use OC\AvatarManager;
|
2016-10-04 10:28:41 +00:00
|
|
|
use OC\Files\AppData\AppData;
|
2016-10-04 11:11:33 +00:00
|
|
|
use OCP\Files\IAppData;
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFolder;
|
2016-10-03 11:57:29 +00:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserManager;
|
2015-12-01 21:08:42 +00:00
|
|
|
|
2016-02-15 19:49:07 +00:00
|
|
|
/**
|
|
|
|
* Class AvatarManagerTest
|
|
|
|
*/
|
2015-12-01 21:08:42 +00:00
|
|
|
class AvatarManagerTest extends \Test\TestCase {
|
2016-10-03 11:57:29 +00:00
|
|
|
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $userManager;
|
2016-10-04 11:11:33 +00:00
|
|
|
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $appData;
|
2016-10-03 11:57:29 +00:00
|
|
|
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $l10n;
|
|
|
|
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $logger;
|
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $config;
|
2016-10-04 10:28:41 +00:00
|
|
|
/** @var AvatarManager | \PHPUnit_Framework_MockObject_MockObject */
|
2015-12-01 21:08:42 +00:00
|
|
|
private $avatarManager;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2016-10-03 11:57:29 +00:00
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
2016-10-04 11:11:33 +00:00
|
|
|
$this->appData = $this->createMock(IAppData::class);
|
2016-10-03 11:57:29 +00:00
|
|
|
$this->l10n = $this->createMock(IL10N::class);
|
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2016-02-15 19:49:07 +00:00
|
|
|
|
2016-10-03 11:57:29 +00:00
|
|
|
$this->avatarManager = new AvatarManager(
|
|
|
|
$this->userManager,
|
2016-10-04 11:11:33 +00:00
|
|
|
$this->appData,
|
2016-10-03 11:57:29 +00:00
|
|
|
$this->l10n,
|
|
|
|
$this->logger,
|
|
|
|
$this->config
|
|
|
|
);
|
2015-12-01 21:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-19 07:27:21 +00:00
|
|
|
* @expectedException \Exception
|
2015-12-01 21:08:42 +00:00
|
|
|
* @expectedExceptionMessage user does not exist
|
|
|
|
*/
|
|
|
|
public function testGetAvatarInvalidUser() {
|
2016-10-03 11:57:29 +00:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('invalidUser')
|
|
|
|
->willReturn(null);
|
|
|
|
|
2015-12-01 21:08:42 +00:00
|
|
|
$this->avatarManager->getAvatar('invalidUser');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAvatarValidUser() {
|
2016-10-03 11:57:29 +00:00
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$user
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('valid-user');
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('valid-user')
|
|
|
|
->willReturn($user);
|
2016-10-04 11:11:33 +00:00
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
|
|
|
$this->appData
|
2016-10-03 11:57:29 +00:00
|
|
|
->expects($this->once())
|
2016-10-04 11:11:33 +00:00
|
|
|
->method('getFolder')
|
|
|
|
->with('valid-user')
|
2016-10-03 11:57:29 +00:00
|
|
|
->willReturn($folder);
|
2015-12-01 21:08:42 +00:00
|
|
|
|
2016-10-04 10:28:41 +00:00
|
|
|
$expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);
|
2016-10-03 11:57:29 +00:00
|
|
|
$this->assertEquals($expected, $this->avatarManager->getAvatar('valid-user'));
|
2015-12-01 21:08:42 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 10:28:41 +00:00
|
|
|
public function testGetAvatarValidUserDifferentCasing() {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('vaLid-USER')
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
|
|
$user->expects($this->once())
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('valid-user');
|
|
|
|
|
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
|
|
|
$this->appData
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getFolder')
|
|
|
|
->with('valid-user')
|
|
|
|
->willReturn($folder);
|
|
|
|
|
|
|
|
$expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);
|
|
|
|
$this->assertEquals($expected, $this->avatarManager->getAvatar('vaLid-USER'));
|
|
|
|
}
|
2015-12-01 21:08:42 +00:00
|
|
|
}
|