]> source.dussan.org Git - nextcloud-server.git/commitdiff
Force test cases using background commands to handle setting up the filesystem
authorRobin Appelman <icewind@owncloud.com>
Tue, 24 Mar 2015 09:02:48 +0000 (10:02 +0100)
committerRobin Appelman <icewind@owncloud.com>
Thu, 26 Mar 2015 16:07:02 +0000 (17:07 +0100)
lib/private/command/fileaccess.php
lib/private/command/queuebus.php
tests/lib/testcase.php

index 5de00862facad2868bc7ed765e043dae35d7605a..b08fb1825eabbc86926439f8c426a3ee74efcb55 100644 (file)
@@ -11,8 +11,12 @@ namespace OC\Command;
 use OCP\IUser;
 
 trait FileAccess {
-       protected function getUserFolder(IUser $user) {
+       protected function setupFS(IUser $user){
                \OC_Util::setupFS($user->getUID());
+       }
+
+       protected function getUserFolder(IUser $user) {
+               $this->setupFS($user);
                return \OC::$server->getUserFolder($user->getUID());
        }
 }
index 29c769e01075ed74f03588d265e2fbf466cc5277..953479086ca942481aa19c5ec8f5e16f4a03ba4a 100644 (file)
@@ -15,7 +15,7 @@ class QueueBus implements IBus {
        /**
         * @var (ICommand|callable)[]
         */
-       private $queue;
+       private $queue = [];
 
        /**
         * Schedule a command to be fired
index 2b4540120d253daacca43ad1d13505385c9dcba3..f4bb847955967231f3df3341394e7c9737c77d7e 100644 (file)
@@ -23,6 +23,7 @@
 namespace Test;
 
 use OC\Command\QueueBus;
+use OC\Files\Filesystem;
 use OCP\Security\ISecureRandom;
 
 abstract class TestCase extends \PHPUnit_Framework_TestCase {
@@ -34,7 +35,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
        protected function setUp() {
                // overwrite the command bus with one we can run ourselves
                $this->commandBus = new QueueBus();
-               \OC::$server->registerService('AsyncCommandBus', function(){
+               \OC::$server->registerService('AsyncCommandBus', function () {
                        return $this->commandBus;
                });
        }
@@ -190,6 +191,20 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
         * Run all commands pushed to the bus
         */
        protected function runCommands() {
+               // get the user for which the fs is setup
+               $view = Filesystem::getView();
+               if ($view) {
+                       list(, $user) = explode('/', $view->getRoot());
+               } else {
+                       $user = null;
+               }
+
+               \OC_Util::tearDownFS(); // command cant reply on the fs being setup
                $this->commandBus->run();
+               \OC_Util::tearDownFS();
+
+               if ($user) {
+                       \OC_Util::setupFS($user);
+               }
        }
 }