avatar to appdata
* Fix AvatarTest Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
ac38a3a654
commit
6807cb684f
|
@ -29,10 +29,9 @@
|
|||
namespace OC;
|
||||
|
||||
use OC\User\User;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Files\File;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\Files\NotPermittedException;
|
||||
use OCP\Files\SimpleFS\ISimpleFile;
|
||||
use OCP\Files\SimpleFS\ISimpleFolder;
|
||||
use OCP\IAvatar;
|
||||
use OCP\IConfig;
|
||||
|
@ -99,7 +98,8 @@ class Avatar implements IAvatar {
|
|||
* @return bool
|
||||
*/
|
||||
public function exists() {
|
||||
return $this->folder->nodeExists('avatar.jpg') || $this->folder->nodeExists('avatar.png');
|
||||
|
||||
return $this->folder->fileExists('avatar.jpg') || $this->folder->fileExists('avatar.png');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,15 +171,15 @@ class Avatar implements IAvatar {
|
|||
}
|
||||
|
||||
try {
|
||||
$file = $this->folder->get($path);
|
||||
$file = $this->folder->getFile($path);
|
||||
} catch (NotFoundException $e) {
|
||||
if ($size <= 0) {
|
||||
throw new NotFoundException;
|
||||
}
|
||||
|
||||
$avatar = new OC_Image();
|
||||
/** @var File $file */
|
||||
$file = $this->folder->get('avatar.' . $ext);
|
||||
/** @var ISimpleFile $file */
|
||||
$file = $this->folder->getFile('avatar.' . $ext);
|
||||
$avatar->loadFromData($file->getContent());
|
||||
if ($size !== -1) {
|
||||
$avatar->resize($size);
|
||||
|
@ -202,9 +202,9 @@ class Avatar implements IAvatar {
|
|||
* @throws NotFoundException
|
||||
*/
|
||||
private function getExtension() {
|
||||
if ($this->folder->nodeExists('avatar.jpg')) {
|
||||
if ($this->folder->fileExists('avatar.jpg')) {
|
||||
return 'jpg';
|
||||
} elseif ($this->folder->nodeExists('avatar.png')) {
|
||||
} elseif ($this->folder->fileExists('avatar.png')) {
|
||||
return 'png';
|
||||
}
|
||||
throw new NotFoundException;
|
||||
|
|
|
@ -27,13 +27,12 @@
|
|||
|
||||
namespace OC;
|
||||
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Files\IAppData;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IAvatarManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\ILogger;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\IL10N;
|
||||
|
||||
/**
|
||||
|
@ -44,8 +43,8 @@ class AvatarManager implements IAvatarManager {
|
|||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
/** @var IAppData */
|
||||
private $appData;
|
||||
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
|
@ -60,19 +59,19 @@ class AvatarManager implements IAvatarManager {
|
|||
* AvatarManager constructor.
|
||||
*
|
||||
* @param IUserManager $userManager
|
||||
* @param IRootFolder $rootFolder
|
||||
* @param IAppData $appData
|
||||
* @param IL10N $l
|
||||
* @param ILogger $logger
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(
|
||||
IUserManager $userManager,
|
||||
IRootFolder $rootFolder,
|
||||
IAppData $appData,
|
||||
IL10N $l,
|
||||
ILogger $logger,
|
||||
IConfig $config) {
|
||||
$this->userManager = $userManager;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->appData = $appData;
|
||||
$this->l = $l;
|
||||
$this->logger = $logger;
|
||||
$this->config = $config;
|
||||
|
@ -95,20 +94,12 @@ class AvatarManager implements IAvatarManager {
|
|||
// sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below)
|
||||
$userId = $user->getUID();
|
||||
|
||||
/*
|
||||
* Fix for #22119
|
||||
* Basically we do not want to copy the skeleton folder.
|
||||
*
|
||||
* For unit test purposes this is ignored when run in PHPUnit.
|
||||
*/
|
||||
if(!defined('PHPUNIT_RUN')) {
|
||||
\OC\Files\Filesystem::initMountPoints($userId);
|
||||
try {
|
||||
$folder = $this->appData->getFolder($userId);
|
||||
} catch (NotFoundException $e) {
|
||||
$folder = $this->appData->newFolder($userId);
|
||||
}
|
||||
|
||||
$dir = '/' . $userId;
|
||||
/** @var Folder $folder */
|
||||
$folder = $this->rootFolder->get($dir);
|
||||
|
||||
return new Avatar($folder, $this->l, $user, $this->logger, $this->config);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,10 @@ class SimpleFolder implements ISimpleFolder {
|
|||
$this->folder->delete();
|
||||
}
|
||||
|
||||
public function fileExists($name) {
|
||||
return $this->folder->nodeExists($name);
|
||||
}
|
||||
|
||||
public function getFile($name) {
|
||||
$file = $this->folder->get($name);
|
||||
|
||||
|
|
|
@ -359,7 +359,7 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$this->registerService('AvatarManager', function (Server $c) {
|
||||
return new AvatarManager(
|
||||
$c->getUserManager(),
|
||||
$c->getRootFolder(),
|
||||
$c->getAppDataDir('avatar'),
|
||||
$c->getL10N('lib'),
|
||||
$c->getLogger(),
|
||||
$c->getConfig()
|
||||
|
|
|
@ -51,6 +51,7 @@ interface ISimpleFolder {
|
|||
public function fileExists($name);
|
||||
|
||||
/**
|
||||
* Get the file named $name from the folder
|
||||
*
|
||||
* @param string $name
|
||||
* @return ISimpleFile
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
namespace Test;
|
||||
|
||||
use OC\Files\SimpleFS\SimpleFolder;
|
||||
use OC\User\User;
|
||||
use OCP\Files\File;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\IConfig;
|
||||
|
@ -30,11 +32,11 @@ class AvatarTest extends \Test\TestCase {
|
|||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->folder = $this->createMock(Folder::class);
|
||||
$this->folder = $this->createMock(SimpleFolder::class);
|
||||
/** @var \OCP\IL10N | \PHPUnit_Framework_MockObject_MockObject $l */
|
||||
$l = $this->createMock(IL10N::class);
|
||||
$l->method('t')->will($this->returnArgument(0));
|
||||
$this->user = $this->getMockBuilder('OC\User\User')->disableOriginalConstructor()->getMock();
|
||||
$this->user = $this->createMock(User::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
|
||||
$this->avatar = new \OC\Avatar(
|
||||
|
@ -51,7 +53,7 @@ class AvatarTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGetAvatarSizeMatch() {
|
||||
$this->folder->method('nodeExists')
|
||||
$this->folder->method('fileExists')
|
||||
->will($this->returnValueMap([
|
||||
['avatar.jpg', true],
|
||||
['avatar.128.jpg', true],
|
||||
|
@ -61,13 +63,13 @@ class AvatarTest extends \Test\TestCase {
|
|||
|
||||
$file = $this->createMock(File::class);
|
||||
$file->method('getContent')->willReturn($expected->data());
|
||||
$this->folder->method('get')->with('avatar.128.jpg')->willReturn($file);
|
||||
$this->folder->method('getFile')->with('avatar.128.jpg')->willReturn($file);
|
||||
|
||||
$this->assertEquals($expected->data(), $this->avatar->get(128)->data());
|
||||
}
|
||||
|
||||
public function testGetAvatarSizeMinusOne() {
|
||||
$this->folder->method('nodeExists')
|
||||
$this->folder->method('fileExists')
|
||||
->will($this->returnValueMap([
|
||||
['avatar.jpg', true],
|
||||
]));
|
||||
|
@ -76,13 +78,13 @@ class AvatarTest extends \Test\TestCase {
|
|||
|
||||
$file = $this->createMock(File::class);
|
||||
$file->method('getContent')->willReturn($expected->data());
|
||||
$this->folder->method('get')->with('avatar.jpg')->willReturn($file);
|
||||
$this->folder->method('getFile')->with('avatar.jpg')->willReturn($file);
|
||||
|
||||
$this->assertEquals($expected->data(), $this->avatar->get(-1)->data());
|
||||
}
|
||||
|
||||
public function testGetAvatarNoSizeMatch() {
|
||||
$this->folder->method('nodeExists')
|
||||
$this->folder->method('fileExists')
|
||||
->will($this->returnValueMap([
|
||||
['avatar.png', true],
|
||||
['avatar.32.png', false],
|
||||
|
@ -95,7 +97,7 @@ class AvatarTest extends \Test\TestCase {
|
|||
$file = $this->createMock(File::class);
|
||||
$file->method('getContent')->willReturn($expected->data());
|
||||
|
||||
$this->folder->method('get')
|
||||
$this->folder->method('getFile')
|
||||
->will($this->returnCallback(
|
||||
function($path) use ($file) {
|
||||
if ($path === 'avatar.png') {
|
||||
|
@ -126,7 +128,7 @@ class AvatarTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testExiststJPG() {
|
||||
$this->folder->method('nodeExists')
|
||||
$this->folder->method('fileExists')
|
||||
->will($this->returnValueMap([
|
||||
['avatar.jpg', true],
|
||||
['avatar.png', false],
|
||||
|
@ -135,7 +137,7 @@ class AvatarTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testExistsPNG() {
|
||||
$this->folder->method('nodeExists')
|
||||
$this->folder->method('fileExists')
|
||||
->will($this->returnValueMap([
|
||||
['avatar.jpg', false],
|
||||
['avatar.png', true],
|
||||
|
|
Loading…
Reference in New Issue