2015-12-02 00:08:42 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Roeland Jago Douma <rullzer@owncloud.com>
|
2016-10-03 14:57:29 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-12-02 00:08:42 +03:00
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
2016-10-03 14:57:29 +03:00
|
|
|
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
2015-12-02 00:08:42 +03: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 10:27:21 +03:00
|
|
|
|
2019-01-20 13:13:41 +03:00
|
|
|
namespace Test\Avatar;
|
2016-05-19 10:27:21 +03:00
|
|
|
|
2019-01-20 13:13:41 +03:00
|
|
|
use OC\Avatar\AvatarManager;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OC\Avatar\UserAvatar;
|
2018-01-13 22:36:02 +03:00
|
|
|
use OC\User\Manager;
|
2016-10-04 14:11:33 +03:00
|
|
|
use OCP\Files\IAppData;
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFolder;
|
2016-10-03 14:57:29 +03:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IUser;
|
2015-12-02 00:08:42 +03:00
|
|
|
|
2016-02-15 22:49:07 +03:00
|
|
|
/**
|
|
|
|
* Class AvatarManagerTest
|
|
|
|
*/
|
2015-12-02 00:08:42 +03:00
|
|
|
class AvatarManagerTest extends \Test\TestCase {
|
2018-01-13 22:36:02 +03:00
|
|
|
/** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-10-03 14:57:29 +03:00
|
|
|
private $userManager;
|
2016-10-04 14:11:33 +03:00
|
|
|
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $appData;
|
2016-10-03 14:57:29 +03: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 13:28:41 +03:00
|
|
|
/** @var AvatarManager | \PHPUnit_Framework_MockObject_MockObject */
|
2015-12-02 00:08:42 +03:00
|
|
|
private $avatarManager;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
public function setUp(): void {
|
2015-12-02 00:08:42 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2018-01-13 22:36:02 +03:00
|
|
|
$this->userManager = $this->createMock(Manager::class);
|
2016-10-04 14:11:33 +03:00
|
|
|
$this->appData = $this->createMock(IAppData::class);
|
2016-10-03 14:57:29 +03:00
|
|
|
$this->l10n = $this->createMock(IL10N::class);
|
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2016-02-15 22:49:07 +03:00
|
|
|
|
2016-10-03 14:57:29 +03:00
|
|
|
$this->avatarManager = new AvatarManager(
|
|
|
|
$this->userManager,
|
2016-10-04 14:11:33 +03:00
|
|
|
$this->appData,
|
2016-10-03 14:57:29 +03:00
|
|
|
$this->l10n,
|
|
|
|
$this->logger,
|
|
|
|
$this->config
|
|
|
|
);
|
2015-12-02 00:08:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-19 10:27:21 +03:00
|
|
|
* @expectedException \Exception
|
2015-12-02 00:08:42 +03:00
|
|
|
* @expectedExceptionMessage user does not exist
|
|
|
|
*/
|
|
|
|
public function testGetAvatarInvalidUser() {
|
2016-10-03 14:57:29 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('invalidUser')
|
|
|
|
->willReturn(null);
|
|
|
|
|
2015-12-02 00:08:42 +03:00
|
|
|
$this->avatarManager->getAvatar('invalidUser');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAvatarValidUser() {
|
2016-10-03 14:57:29 +03: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 14:11:33 +03:00
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
|
|
|
$this->appData
|
2016-10-03 14:57:29 +03:00
|
|
|
->expects($this->once())
|
2016-10-04 14:11:33 +03:00
|
|
|
->method('getFolder')
|
|
|
|
->with('valid-user')
|
2016-10-03 14:57:29 +03:00
|
|
|
->willReturn($folder);
|
2015-12-02 00:08:42 +03:00
|
|
|
|
2019-01-20 13:13:41 +03:00
|
|
|
$expected = new UserAvatar($folder, $this->l10n, $user, $this->logger, $this->config);
|
2016-10-03 14:57:29 +03:00
|
|
|
$this->assertEquals($expected, $this->avatarManager->getAvatar('valid-user'));
|
2015-12-02 00:08:42 +03:00
|
|
|
}
|
|
|
|
|
2016-10-04 13:28:41 +03: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);
|
|
|
|
|
2019-01-20 13:13:41 +03:00
|
|
|
$expected = new UserAvatar($folder, $this->l10n, $user, $this->logger, $this->config);
|
2016-10-04 13:28:41 +03:00
|
|
|
$this->assertEquals($expected, $this->avatarManager->getAvatar('vaLid-USER'));
|
|
|
|
}
|
2015-12-02 00:08:42 +03:00
|
|
|
}
|