0009932: Parametrize references to e-mail application
authorFlávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
Thu, 22 May 2014 19:11:47 +0000 (16:11 -0300)
committerLars Kneschke <l.kneschke@metaways.de>
Mon, 20 Apr 2015 11:37:48 +0000 (13:37 +0200)
 - Decouples Calendar from e-mail application
 - Creates factory for recovering instance of e-mail application

Change-Id: I44cf8ce79751e2fc8f6f8f7d46e3dda217c69a27
Reviewed-on: https://gerrit.tine20.org/tine20/3070
Tested-by: jenkins user
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Reviewed-by: Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
Reviewed-by: Lars Kneschke <l.kneschke@metaways.de>
tests/tine20/AllTests.php
tests/tine20/Tinebase/AllTests.php
tests/tine20/Tinebase/EmailUser/FactoryTest.php [new file with mode: 0644]
tests/tine20/Tinebase/Frontend/JsonTest.php
tine20/Calendar/Frontend/iMIP.php
tine20/Tinebase/EmailUser/Factory.php [new file with mode: 0644]

index 5fba8bf..66474d1 100644 (file)
@@ -7,11 +7,10 @@
  * @copyright   Copyright (c) 2007-2013 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Matthias Greiling <m.greiling@metaways.de>
  */
  * @copyright   Copyright (c) 2007-2013 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Matthias Greiling <m.greiling@metaways.de>
  */
+
 /**
 /**
- * Test helper
+ * @package     Tinebase
  */
  */
-require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'TestHelper.php';
-
 class AllTests
 {
     public static function main()
 class AllTests
 {
     public static function main()
@@ -44,6 +43,7 @@ class AllTests
         $suite->addTest(Sipgate_AllTests::suite());
         $suite->addTest(SimpleFAQ_AllTests::suite());
         $suite->addTest(Zend_AllTests::suite());
         $suite->addTest(Sipgate_AllTests::suite());
         $suite->addTest(SimpleFAQ_AllTests::suite());
         $suite->addTest(Zend_AllTests::suite());
+        
         return $suite;
     }
 }
         return $suite;
     }
 }
index c102d3c..3c81a5c 100644 (file)
@@ -78,7 +78,7 @@ class Tinebase_AllTests
         $suite->addTest(Tinebase_Tree_AllTests::suite());
         $suite->addTest(Tinebase_Scheduler_AllTests::suite());
         $suite->addTest(Tinebase_WebDav_AllTests::suite());
         $suite->addTest(Tinebase_Tree_AllTests::suite());
         $suite->addTest(Tinebase_Scheduler_AllTests::suite());
         $suite->addTest(Tinebase_WebDav_AllTests::suite());
-        $suite->addTest(OpenDocument_AllTests::suite());        
+        $suite->addTest(OpenDocument_AllTests::suite());
         return $suite;
     }
 }
         return $suite;
     }
 }
diff --git a/tests/tine20/Tinebase/EmailUser/FactoryTest.php b/tests/tine20/Tinebase/EmailUser/FactoryTest.php
new file mode 100644 (file)
index 0000000..32bb7d9
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Tine 2.0 - http://www.tine20.org
+ *
+ * @package     Tinebase
+ * @subpackage  EmailUser
+ * @license     http://www.gnu.org/licenses/agpl.html
+ * @copyright   Copyright (c) 2015-2015 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Lars Kneschke <l.kneschke@metaways.de>
+ */
+
+/**
+ * Test class for Tinebase_EmailUser_Factory
+ * 
+ * @package     Tinebase
+ * @subpackage  EmailUser
+ */
+class Tinebase_EmailUser_FactoryTest extends TestCase
+{
+    /**
+     * 
+     */
+    public function testGetMailApplicationName()
+    {
+        $name = Tinebase_EmailUser_Factory::getMailApplicationName();
+        
+        $this->assertNotEmpty($name);
+    }
+    
+    /**
+     * 
+     */
+    public function testGetInstance()
+    {
+        $instance = Tinebase_EmailUser_Factory::getInstance('Controller_Message');
+        
+        $this->assertInstanceOf('Tinebase_Controller_Record_Abstract', $instance);
+    }
+}
index d023d52..3b81b23 100644 (file)
@@ -649,7 +649,9 @@ class Tinebase_Frontend_JsonTest extends TestCase
         $this->assertEquals('sclever', Tinebase_Core::getUser()->accountLoginName);
         $this->assertEquals('sclever', Tinebase_Session::getSessionNamespace()->currentAccount->accountLoginName);
         
         $this->assertEquals('sclever', Tinebase_Core::getUser()->accountLoginName);
         $this->assertEquals('sclever', Tinebase_Session::getSessionNamespace()->currentAccount->accountLoginName);
         
+        // reset to original user
         Tinebase_Controller::getInstance()->initUser($this->_originalTestUser, /* $fixCookieHeader = */ false);
         Tinebase_Controller::getInstance()->initUser($this->_originalTestUser, /* $fixCookieHeader = */ false);
+        Tinebase_Session::getSessionNamespace()->userAccountChanged = false;
     }
     
     /**
     }
     
     /**
index b9995db..b8e64ce 100644 (file)
@@ -49,8 +49,8 @@ class Calendar_Frontend_iMIP
     public function process($_iMIP, $_status = NULL)
     {
         // client spoofing protection
     public function process($_iMIP, $_status = NULL)
     {
         // client spoofing protection
-        $iMIP = Felamimail_Controller_Message::getInstance()->getiMIP($_iMIP->getId());
-        
+        $iMIP = Tinebase_EmailUser_Factory::getInstance('Controller_Message')->getiMIP($_iMIP->getId());
+
         return $this->_process($_iMIP, $_status);
     }
     
         return $this->_process($_iMIP, $_status);
     }
     
diff --git a/tine20/Tinebase/EmailUser/Factory.php b/tine20/Tinebase/EmailUser/Factory.php
new file mode 100644 (file)
index 0000000..43f26f9
--- /dev/null
@@ -0,0 +1,116 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Tinebase
+ * @subpackage  EmailUser
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @copyright   Copyright (c) 2009-2015 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2014-2015 Serpro (http://www.serpro.gov.br)
+ * @author      Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
+ *
+ */
+
+/**
+ * class Tinebase_EmailUser_Factory
+ *
+ * @package    Tinebase
+ * @subpackage EmailUser
+ */
+class Tinebase_EmailUser_Factory
+{
+    /**
+     * 
+     * @var Tinebase_Model_Application
+     */
+    protected static $_emailApplication = NULL;
+    
+    /**
+     * Return name of configured mail application
+     * 
+     * @return string
+     */
+    public static function getMailApplicationName()
+    {
+        if (NULL === self::$_emailApplication){
+            $applications = Tinebase_Core::getUser()->getApplications();
+            
+            foreach (array('Felamimail', 'Expressomail') as $emailApplication) {
+                if (self::$_emailApplication = $applications->find('name', $emailApplication)) {
+                    break;
+                }
+            }
+        }
+        
+        return self::$_emailApplication->name;
+    }
+    
+    /**
+     * if class could be for instance Felamimail_Controller_Account,
+     * namespaceWithoutBasePrefix is only Controller_Account
+     * class must implements getInstance() method
+     *
+     * @param string $namespaceWithoutBasePrefix
+     * @return mixed
+     */
+    public static function getInstance($namespaceWithoutBasePrefix)
+    {
+        $class = self::getMailApplicationName() . '_' . $namespaceWithoutBasePrefix;
+        
+        return $class::getInstance();
+    }
+    
+    /**
+     * if class could be for instance Felamimail_Controller_Account,
+     * namespaceWithoutBasePrefix is only Controller_Account
+     * class must implements getInstance() method
+
+     * @param string $namespaceWithoutBasePrefix
+     * @param string $name constant name
+     * @return mixed
+     */
+    public static function getConstant($namespaceWithoutBasePrefix, $name)
+    {
+        $class = self::getMailApplicationName() . '_' . $namespaceWithoutBasePrefix;
+        
+        return constant($class . '::' . $name);
+    }
+    
+    /**
+     * Calls a static method from email application
+     *
+     * if class could be for instance Felamimail_Controller_Account,
+     * namespaceWithoutBasePrefix is only Controller_Account
+     * class must implements getInstance() method
+     * @param string $namespaceWithoutBasePrefix
+     * @param string $method
+     * @param array $args
+     * @return mixed
+     */
+    public static function callStatic($namespaceWithoutBasePrefix, $method, array $args)
+    {
+        $class = self::getMailApplicationName() . '_' . $namespaceWithoutBasePrefix;
+        
+        if (!class_exists($class)) {
+            $class = 'Tinebase_' . $namespaceWithoutBasePrefix;
+        }
+        
+        return call_user_func_array(array($class, $method), $args);
+    }
+    
+    /**
+     * Adds the properly filter according e-mail application
+     * @param Tinebase_DateTime $received
+     */
+    public static function getPeriodFilter($received)
+    {
+        $mailApplication = self::getMailApplicationName();
+        
+        if ($mailApplication !== 'Felamimail') {
+            $class = $mailApplication . '_Model_Filter_DateTime';
+            return new $class('received', 'after', $received->get(Tinebase_Record_Abstract::ISO8601LONG));
+        } else {
+            return new Tinebase_Model_Filter_DateTime('received', 'after', $received->get(Tinebase_Record_Abstract::ISO8601LONG));
+        }
+    }
+}
\ No newline at end of file