]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add FileAccess trait for commands
authorRobin Appelman <icewind@owncloud.com>
Mon, 23 Feb 2015 14:26:12 +0000 (15:26 +0100)
committerRobin Appelman <icewind@owncloud.com>
Wed, 25 Feb 2015 14:09:41 +0000 (15:09 +0100)
lib/private/command/fileaccess.php [new file with mode: 0644]
tests/lib/command/asyncbus.php

diff --git a/lib/private/command/fileaccess.php b/lib/private/command/fileaccess.php
new file mode 100644 (file)
index 0000000..5de0086
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Command;
+
+use OCP\IUser;
+
+trait FileAccess {
+       protected function getUserFolder(IUser $user) {
+               \OC_Util::setupFS($user->getUID());
+               return \OC::$server->getUserFolder($user->getUID());
+       }
+}
index 030c416953d02ec258ddbdf1ccb5befa0a0aa38a..d22ce34d83967b0e14f85ff47a59b69c16808230 100644 (file)
@@ -9,6 +9,7 @@
 
 namespace Test\Command;
 
+use OC\Command\FileAccess;
 use OCP\Command\ICommand;
 use Test\BackgroundJob\DummyJobList;
 use Test\TestCase;
@@ -31,6 +32,14 @@ class StateFullCommand implements ICommand {
        }
 }
 
+class FilesystemCommand implements ICommand {
+       use FileAccess;
+
+       public function handle() {
+               AsyncBus::$lastCommand = 'FileAccess';
+       }
+}
+
 function basicFunction() {
        AsyncBus::$lastCommand = 'function';
 }
@@ -133,6 +142,22 @@ class AsyncBus extends TestCase {
                $this->assertEquals('closure-bar', self::$lastCommand);
        }
 
+       public function testFileFileAccessCommand() {
+               $this->bus->push(new FilesystemCommand());
+               $this->assertEquals('', self::$lastCommand);
+               $this->runJobs();
+               $this->assertEquals('FileAccess', self::$lastCommand);
+       }
+
+       public function testFileFileAccessCommandSync() {
+               $this->bus->requireSync('\OC\Command\FileAccess');
+               $this->bus->push(new FilesystemCommand());
+               $this->assertEquals('FileAccess', self::$lastCommand);
+               self::$lastCommand = '';
+               $this->runJobs();
+               $this->assertEquals('', self::$lastCommand);
+       }
+
 
        private function runJobs() {
                $jobs = $this->jobList->getAll();