Merge branch '2013.10' into 2014.11
[tine20] / tests / tine20 / TestCase.php
index a20f38c..cfaa915 100644 (file)
@@ -126,6 +126,40 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
     }
     
     /**
+     * get tag
+     *
+     * @param string $tagType
+     * @param string $tagName
+     * @param array $contexts
+     * @return Tinebase_Model_Tag
+     */
+    protected function _getTag($tagType = Tinebase_Model_Tag::TYPE_SHARED, $tagName = NULL, $contexts = NULL)
+    {
+        if ($tagName) {
+            try {
+                $tag = Tinebase_Tags::getInstance()->getTagByName($tagName);
+                return $tag;
+            } catch (Tinebase_Exception_NotFound $tenf) {
+            }
+        } else {
+            $tagName = Tinebase_Record_Abstract::generateUID();
+        }
+    
+        $targ = array(
+            'type'          => $tagType,
+            'name'          => $tagName,
+            'description'   => 'testTagDescription',
+            'color'         => '#009B31',
+        );
+    
+        if ($contexts) {
+            $targ['contexts'] = $contexts;
+        }
+    
+        return new Tinebase_Model_Tag($targ);
+    }
+    
+    /**
      * delete groups and their members
      * 
      * - also deletes groups and users in sync backends
@@ -217,7 +251,18 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
     protected function _getMailDomain()
     {
         $testconfig = Zend_Registry::get('testConfig');
-        return ($testconfig && isset($testconfig->maildomain)) ? $testconfig->maildomain : 'tine20.org';
+        
+        if ($testconfig && isset($testconfig->maildomain)) {
+            return $testconfig->maildomain;
+        }
+        
+        if (!empty(Tinebase_Core::getUser()->accountEmailAddress)) {
+            list($user, $domain) = explode('@', Tinebase_Core::getUser()->accountEmailAddress, 2);
+            
+            return $domain;
+        }
+        
+        return 'tine20.org';
     }
     
     /**
@@ -333,4 +378,34 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
         $tempFile = $tempFileBackend->createTempFile(dirname(__FILE__) . '/Filemanager/files/test.txt');
         return $tempFile;
     }
+    
+    /**
+     * set grants for a persona
+     * 
+     * @param integer $containerId
+     * @param string $persona
+     * @param string $adminGrant
+     */
+    protected function _setPersonaGrantsForTestContainer($containerId, $persona, $adminGrant = false)
+    {
+        $grants = new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array(array(
+            'account_id'    => $this->_personas[$persona]->getId(),
+            'account_type'  => 'user',
+            Tinebase_Model_Grants::GRANT_READ     => true,
+            Tinebase_Model_Grants::GRANT_ADD      => true,
+            Tinebase_Model_Grants::GRANT_EDIT     => true,
+            Tinebase_Model_Grants::GRANT_DELETE   => true,
+            Tinebase_Model_Grants::GRANT_ADMIN    => $adminGrant,
+        ), array(
+            'account_id'    => Tinebase_Core::getUser()->getId(),
+            'account_type'  => 'user',
+            Tinebase_Model_Grants::GRANT_READ     => true,
+            Tinebase_Model_Grants::GRANT_ADD      => true,
+            Tinebase_Model_Grants::GRANT_EDIT     => true,
+            Tinebase_Model_Grants::GRANT_DELETE   => true,
+            Tinebase_Model_Grants::GRANT_ADMIN    => true,
+        )));
+        
+        Tinebase_Container::getInstance()->setGrants($containerId, $grants, TRUE);
+    }
 }