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