summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-09-07 16:09:22 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-10-05 11:00:16 +0200
commit6807cb684f64587f1747b5168eb42e5172c889eb (patch)
tree8cd20e87f28693c1c4d2dc44ea9c6c43f597ceeb
parentac38a3a654df909d2c0c9d7c4d84e8e5ea2c587a (diff)
downloadnextcloud-server-6807cb684f64587f1747b5168eb42e5172c889eb.tar.gz
nextcloud-server-6807cb684f64587f1747b5168eb42e5172c889eb.zip
avatar to appdata
* Fix AvatarTest Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r--lib/private/Avatar.php16
-rw-r--r--lib/private/AvatarManager.php29
-rw-r--r--lib/private/Files/SimpleFS/SimpleFolder.php4
-rw-r--r--lib/private/Server.php2
-rw-r--r--lib/public/Files/SimpleFS/ISimpleFolder.php1
-rw-r--r--tests/lib/AvatarTest.php22
6 files changed, 36 insertions, 38 deletions
diff --git a/lib/private/Avatar.php b/lib/private/Avatar.php
index e7fd4da4615..c3a068701df 100644
--- a/lib/private/Avatar.php
+++ b/lib/private/Avatar.php
@@ -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;
diff --git a/lib/private/AvatarManager.php b/lib/private/AvatarManager.php
index df3247b8f00..b8c6c2a1eb6 100644
--- a/lib/private/AvatarManager.php
+++ b/lib/private/AvatarManager.php
@@ -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);
}
}
diff --git a/lib/private/Files/SimpleFS/SimpleFolder.php b/lib/private/Files/SimpleFS/SimpleFolder.php
index 8ce6c013c1f..5b55fe0f157 100644
--- a/lib/private/Files/SimpleFS/SimpleFolder.php
+++ b/lib/private/Files/SimpleFS/SimpleFolder.php
@@ -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);
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 838393b8507..cd2cce5cb0b 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -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()
diff --git a/lib/public/Files/SimpleFS/ISimpleFolder.php b/lib/public/Files/SimpleFS/ISimpleFolder.php
index c8d7f060fbe..406bb631159 100644
--- a/lib/public/Files/SimpleFS/ISimpleFolder.php
+++ b/lib/public/Files/SimpleFS/ISimpleFolder.php
@@ -51,6 +51,7 @@ interface ISimpleFolder {
public function fileExists($name);
/**
+ * Get the file named $name from the folder
*
* @param string $name
* @return ISimpleFile
diff --git a/tests/lib/AvatarTest.php b/tests/lib/AvatarTest.php
index 7f012c895fd..cea3f9bed1a 100644
--- a/tests/lib/AvatarTest.php
+++ b/tests/lib/AvatarTest.php
@@ -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],