unload Tinebase_Acl_Roles in setup tests
authorPaul Mehrer <p.mehrer@metaways.de>
Thu, 6 Apr 2017 05:28:30 +0000 (07:28 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 6 Apr 2017 10:39:44 +0000 (12:39 +0200)
unload setupuser in setup tests

Change-Id: If6a42b5099f82267dcde29a49fc508b747fa861d
Reviewed-on: http://gerrit.tine20.com/customers/4509
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/setup/Setup/ControllerTest.php
tests/setup/files/2017-02-27-11-42-25/tine20_mysql.sql.bz2
tine20/Setup/Controller.php
tine20/Setup/Update/Abstract.php
tine20/Tinebase/Acl/Roles.php
tine20/Tinebase/Controller.php
tine20/Tinebase/Core.php
tine20/Tinebase/Frontend/Cli.php

index c2b9f40..49f73da 100644 (file)
@@ -324,6 +324,8 @@ class Setup_ControllerTest extends PHPUnit_Framework_TestCase
         $this->_uit->uninstallApplications($installedApplications->name);
         Tinebase_Core::unsetTinebaseId();
         Tinebase_Group::unsetInstance();
+        Tinebase_Acl_Roles::unsetInstance();
+        Tinebase_Core::unsetUser();
     }
     
     /**
index 5c33de0..360392d 100644 (file)
Binary files a/tests/setup/files/2017-02-27-11-42-25/tine20_mysql.sql.bz2 and b/tests/setup/files/2017-02-27-11-42-25/tine20_mysql.sql.bz2 differ
index 7377247..ec24199 100644 (file)
@@ -1444,6 +1444,11 @@ class Setup_Controller
         $this->_replaceTinebaseidInDump($mysqlBackupFile);
         $this->restore($options);
 
+        $setupUser = Setup_Update_Abstract::getSetupFromConfigOrCreateOnTheFly();
+        if (! Tinebase_Core::getUser() instanceof Tinebase_Model_User) {
+            Tinebase_Core::set(Tinebase_Core::USER, $setupUser);
+        }
+
         // set the replication master id
         $tinebase = Tinebase_Application::getInstance()->getApplicationByName('Tinebase');
         $state = $tinebase->state;
index afa455e..25a7f73 100644 (file)
@@ -426,6 +426,7 @@ class Setup_Update_Abstract
 
             $setupUser = Tinebase_User::createSystemUser('setupuser');
             if ($setupUser) {
+                Tinebase_Config::getInstance()->set(Tinebase_Config::SETUPUSERID, null);
                 Tinebase_Config::getInstance()->set(Tinebase_Config::SETUPUSERID, $setupUser->getId());
             }
         }
index 1bf5c35..b1e811b 100644 (file)
@@ -82,6 +82,11 @@ class Tinebase_Acl_Roles extends Tinebase_Controller_Record_Abstract
         
         return self::$_instance;
     }
+
+    public static function unsetInstance()
+    {
+        self::$_instance = NULL;
+    }
     
     /**
      * check if one of the roles the user is in has a given right for a given application
index e2beb77..b50180e 100644 (file)
@@ -805,7 +805,7 @@ class Tinebase_Controller extends Tinebase_Controller_Event
                     'options' => array('getRelations' => true),
                     'function' => 'rebuildPathsIteration',
                 ));
-                $result = $iterator->iterate($controller);
+                $result = $iterator->iterate();
 
                 if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                     if (false === $result) {
@@ -818,4 +818,25 @@ class Tinebase_Controller extends Tinebase_Controller_Event
 
         return true;
     }
+
+    /**
+     * rebuild paths for multiple records in an iteration
+     * @see Tinebase_Record_Iterator / self::rebuildPaths()
+     *
+     * @param Tinebase_Record_RecordSet $records
+     */
+    public function rebuildPathsIteration(Tinebase_Record_RecordSet $records)
+    {
+        /** @var Tinebase_Record_Interface $record */
+        foreach ($records as $record) {
+            try {
+                Tinebase_Record_Path::getInstance()->rebuildPaths($record);
+            } catch (Exception $e) {
+                Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' record path building failed: '
+                    . $e->getMessage() . PHP_EOL
+                    . $e->getTraceAsString() . PHP_EOL
+                    . $record->toArray());
+            }
+        }
+    }
 }
index 53b3d1a..c2aed2b 100644 (file)
@@ -1411,6 +1411,12 @@ class Tinebase_Core
         return self::get(self::USER);
     }
 
+    public static function unsetUser()
+    {
+        Zend_Registry::set(self::USER, null);
+        Tinebase_Log_Formatter::resetUsername();
+    }
+
     /**
      * get current users timezone
      *
index 42f91f4..26f35ab 100644 (file)
@@ -80,27 +80,6 @@ class Tinebase_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
     }
 
     /**
-     * rebuild paths for multiple records in an iteration
-     * @see Tinebase_Record_Iterator / self::rebuildPaths()
-     *
-     * @param Tinebase_Record_RecordSet $records
-     * @param Tinebase_Controller_Abstract $controller
-     */
-    public function rebuildPathsIteration(Tinebase_Record_RecordSet $records, Tinebase_Controller_Record_Abstract $controller)
-    {
-        foreach ($records as $record) {
-            try {
-                $controller->buildPath($record, true);
-            } catch (Exception $e) {
-                Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' record path building failed: '
-                    . $e->getMessage() . PHP_EOL
-                    . $e->getTraceAsString() . PHP_EOL
-                    . $record->toArray());
-            }
-        }
-    }
-
-    /**
      * forces containers that support sync token to resync via WebDAV sync tokens
      *
      * this will cause 2 BadRequest responses to sync token requests