skip modelconfig smd without valid user #2
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 19 Apr 2016 10:44:51 +0000 (12:44 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 20 Apr 2016 12:20:38 +0000 (14:20 +0200)
... and adds a (server) test for the case

see 0011760: create smd from model definition

Change-Id: I846eecb3279ec2be2fe8cf75c36ebbb448fa9d09
Reviewed-on: http://gerrit.tine20.com/customers/3058
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Tinebase/Server/JsonTests.php
tine20/Tinebase/Server/Json.php

index 2dffca2..782ea34 100644 (file)
@@ -15,6 +15,9 @@
  */
 class Tinebase_Server_JsonTests extends TestCase
 {
+    /**
+     * @group ServerTests
+     */
     public function testGetServiceMap()
     {
         $smd = Tinebase_Server_Json::getServiceMap();
@@ -65,4 +68,17 @@ class Tinebase_Server_JsonTests extends TestCase
             'returns' => 'string'
         ), $smdArray['services']['Inventory.deleteInventoryItems']);
     }
+
+    /**
+     * @group ServerTests
+     */
+    public function testGetAnonServiceMap()
+    {
+        // unset registry (and the user object)
+        Zend_Registry::_unsetInstance();
+
+        $smd = Tinebase_Server_Json::getServiceMap();
+        $smdArray = $smd->toArray();
+        $this->assertTrue(isset($smdArray['services']['Tinebase.ping']));
+    }
 }
index 2de5435..1a85e25 100644 (file)
@@ -373,7 +373,9 @@ class Tinebase_Server_Json extends Tinebase_Server_Abstract implements Tinebase_
             
         $smd = $server->getServiceMap();
 
-        self::_addModelConfigServices($smd);
+        if (Tinebase_Core::isRegistered(Tinebase_Core::USER)) {
+            self::_addModelConfigServices($smd);
+        }
 
         return $smd;
     }
@@ -385,13 +387,7 @@ class Tinebase_Server_Json extends Tinebase_Server_Abstract implements Tinebase_
      */
     protected static function _addModelConfigServices(Zend_Json_Server_Smd $smd)
     {
-        // this is only done for authenticated users
-        $user = Tinebase_Core::getUser();
-        if (! $user) {
-            return;
-        }
-
-        $userApplications = $user->getApplications(/* $_anyRight */ TRUE);
+        $userApplications = Tinebase_Core::getUser()->getApplications(/* $_anyRight */ TRUE);
 
         $cache = Tinebase_Core::getCache();
         $cacheId = '_addModelConfigServices' . sha1(Zend_Json_Encoder::encode($userApplications->getArrayOfIds()));