normalizes test user mail and credentials fetching
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 12 Jan 2016 08:57:43 +0000 (09:57 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 13 Jan 2016 11:31:59 +0000 (12:31 +0100)
Change-Id: I5976b68f63f13b512520edf5d1609dec88e8e6ba
Reviewed-on: http://gerrit.tine20.com/customers/2573
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Frontend/ActiveSyncTest.php
tests/tine20/Calendar/Frontend/iMIPTest.php
tests/tine20/Expressomail/Controller/AccountTest.php
tests/tine20/Expressomail/Controller/MessageTest.php
tests/tine20/Felamimail/Controller/AccountTest.php
tests/tine20/Felamimail/Controller/MessageTest.php
tests/tine20/Tinebase/AuthTest.php

index f8ed75a..5ce39b2 100644 (file)
@@ -465,8 +465,7 @@ Zeile 3</AirSyncBase:Data>
         $xml = file_get_contents(__DIR__ . '/files/' . $filename);
 
         // replace email to make current user organizer and attendee
-        $testConfig = Zend_Registry::get('testConfig');
-        $email = ($testConfig->email) ? $testConfig->email : Tinebase_Core::getUser()->accountEmailAddress;
+        $email = $this->_getEmailAddress();
 
         $xml = str_replace(array(
             'lars@kneschke.de',
index 6f8fb03..209e9c7 100644 (file)
@@ -165,8 +165,7 @@ class Calendar_Frontend_iMIPTest extends TestCase
      */
     protected function _getiMIP($_method, $_addEventToiMIP = FALSE, $_testEmptyMethod = FALSE)
     {
-        $testConfig = Zend_Registry::get('testConfig');
-        $email = ($testConfig->email) ? $testConfig->email : Tinebase_Core::getUser()->accountEmailAddress;
+        $email = $this->_getEmailAddress();
         
         $event = $this->_getEvent();
         $event = Calendar_Controller_Event::getInstance()->create($event);
@@ -506,8 +505,7 @@ class Calendar_Frontend_iMIPTest extends TestCase
      */
     public function testInvitationExternalReply()
     {
-        $testConfig = Zend_Registry::get('testConfig');
-        $email = ($testConfig->email) ? $testConfig->email : Tinebase_Core::getUser()->accountEmailAddress;
+        $email = $email = $this->_getEmailAddress();
         
         $ics = file_get_contents(dirname(__FILE__) . '/files/invitation_reply_external_accepted.ics' );
         $ics = preg_replace('/unittest@tine20\.org/', $email, $ics);
index 083fe5f..3fe30f3 100755 (executable)
@@ -157,7 +157,7 @@ class Expressomail_Controller_AccountTest extends PHPUnit_Framework_TestCase
     public function testCreateTrashOnTheFly()
     {
         // make sure that the delimiter is correct / fetched from server
-        $capabilities = $this->_controller->updateCapabilities($this->_account);\r
+        $capabilities = $this->_controller->updateCapabilities($this->_account);
         
         // set another trash folder
         $this->_account->trash_folder = 'newtrash';
@@ -172,23 +172,23 @@ class Expressomail_Controller_AccountTest extends PHPUnit_Framework_TestCase
      */
     public function testChangePasswordAndUpdateCredentialCache()
     {
-        $testConfig = Zend_Registry::get('testConfig');
+        $testCredentials = TestServer::getInstance()->getTestCredentials();
         
         $account = clone($this->_account);
         unset($account->id);
         $account->type = Expressomail_Model_Account::TYPE_USER;
-        $account->user = $testConfig->username;
+        $account->user = $testCredentials['username'];
         $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray();
         if (isset($imapConfig['domain']) && ! empty($imapConfig['domain'])) {
             $account->user .= '@' . $imapConfig['domain'];
         }
-        $account->password = $testConfig->password;
+        $account->password = $testCredentials['password'];
         $account = $this->_controller->create($account);
         
         $testPw = 'testpwd';
         
         // change pw & update credential cache
-        $this->_setCredentials($testConfig->username, $testPw);
+        $this->_setCredentials($testCredentials['password'], $testPw);
         $account = $this->_controller->get($account->getId());
 
         // try to connect to imap
index 6ee08a1..96170e6 100755 (executable)
@@ -4,7 +4,7 @@
  *
  * @package     Expressomail
  * @license     http://www.gnu.org/licenses/agpl.html
- * @copyright   Copyright (c) 2009-2014 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2009-2016 Metaways Infosystems GmbH (http://www.metaways.de)
  * @copyright   Copyright (c) 2014 Serpro (http://www.serpro.gov.br)
  * @author      Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
  *
@@ -18,7 +18,7 @@ require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHe
 /**
  * Test class for Expressomail_Controller
  */
-class Expressomail_Controller_MessageTest extends PHPUnit_Framework_TestCase
+class Expressomail_Controller_MessageTest extends TestCase
 {
     /**
      * @var Felamimail_Controller_Message
@@ -61,18 +61,6 @@ class Expressomail_Controller_MessageTest extends PHPUnit_Framework_TestCase
     protected $_accountsToDelete = array();
     
     /**
-     * Runs the test methods of this class.
-     *
-     * @access public
-     * @static
-     */
-    public static function main()
-    {
-        $suite  = new PHPUnit_Framework_TestSuite('Tine 2.0 Expressomail Message Controller Tests');
-        PHPUnit_TextUI_TestRunner::run($suite);
-    }
-
-    /**
      * Sets up the fixture.
      * This method is called before a test is executed.
      *
@@ -1203,9 +1191,7 @@ class Expressomail_Controller_MessageTest extends PHPUnit_Framework_TestCase
      */
     protected function _getTestEmailAddress()
     {
-        $testConfig = Zend_Registry::get('testConfig');
-        $email = ($testConfig->email) ? $testConfig->email : 'unittest@tine20.org';
-        return $email;
+        return $this->_getEmailAddress();
     }
     
     /**
index 982b462..836d4d1 100644 (file)
@@ -88,8 +88,8 @@ class Felamimail_Controller_AccountTest extends PHPUnit_Framework_TestCase
         Tinebase_TransactionManager::getInstance()->rollBack();
         
         if ($this->_pwChanged) {
-            $testConfig = Zend_Registry::get('testConfig');
-            $this->_setCredentials($testConfig->username, $testConfig->password);
+            $testCredentials = TestServer::getInstance()->getTestCredentials();
+            $this->_setCredentials($testCredentials['username'], $testCredentials['password']);
         }
     }
     
@@ -188,24 +188,23 @@ class Felamimail_Controller_AccountTest extends PHPUnit_Framework_TestCase
     public function testChangePasswordAndUpdateCredentialCache()
     {
         $this->markTestSkipped('FIXME 0009250: fix test testChangePasswordAndUpdateCredentialCache');
-        
-        $testConfig = Zend_Registry::get('testConfig');
-        
+        $testCredentials = TestServer::getInstance()->getTestCredentials();
+
         $account = clone($this->_account);
         unset($account->id);
         $account->type = Felamimail_Model_Account::TYPE_USER;
-        $account->user = $testConfig->username;
+        $account->user = $testCredentials['username'];
         $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray();
         if (isset($imapConfig['domain']) && ! empty($imapConfig['domain'])) {
             $account->user .= '@' . $imapConfig['domain'];
         }
-        $account->password = $testConfig->password;
+        $account->password = $testCredentials['password'];
         $account = $this->_controller->create($account);
         
         $testPw = 'testpwd';
         
         // change pw & update credential cache
-        $this->_setCredentials($testConfig->username, $testPw);
+        $this->_setCredentials($testCredentials['username'], $testPw);
         $account = $this->_controller->get($account->getId());
 
         // try to connect to imap
index 628c449..f3de49e 100644 (file)
@@ -17,7 +17,7 @@ require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHe
 /**
  * Test class for Tinebase_Group
  */
-class Felamimail_Controller_MessageTest extends PHPUnit_Framework_TestCase
+class Felamimail_Controller_MessageTest extends TestCase
 {
     /**
      * @var Felamimail_Controller_Message
@@ -1157,8 +1157,7 @@ class Felamimail_Controller_MessageTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(0, $badLineEndCount);
         
         $badLineEndCount = preg_match_all("/\\x0d/", $smtpLog, $matches);
-        $this->assertTrue(preg_match_all("/\\x0d/", $smtpLog, $matches) > 70, 'unix line ends are missing');
-        
+        $this->assertTrue($badLineEndCount > 70, 'unix line ends are missing');
     }
     
    /**
@@ -1190,7 +1189,7 @@ class Felamimail_Controller_MessageTest extends PHPUnit_Framework_TestCase
         $event = $preparediMIPPart->getEvent();
         $this->assertTrue($event instanceof Calendar_Model_Event, 'is no event');
         $this->assertEquals($expectedEventSummary, $event->summary);
-        $this->assertEquals($expectedAttendeeCount, count($event->attendee));
+        $this->assertEquals($expectedAttendeeCount, count($event->attendee), 'attendee count mismatch: ' . print_r($event->attendee->toArray(), true));
     }
 
    /**
@@ -1239,9 +1238,7 @@ class Felamimail_Controller_MessageTest extends PHPUnit_Framework_TestCase
      */
     protected function _getTestEmailAddress()
     {
-        $testConfig = Zend_Registry::get('testConfig');
-        $email = ($testConfig->email) ? $testConfig->email : Tinebase_Core::getUser()->accountEmailAddress;
-        return $email;
+        return $this->_getEmailAddress();
     }
     
     /**
index 7428767..54da58a 100644 (file)
@@ -5,7 +5,7 @@
  * @package     Tinebase
  * @subpackage  Auth
  * @license     http://www.gnu.org/licenses/agpl.html
- * @copyright   Copyright (c) 2009-2011 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2009-2016 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Jonas Fischer <j.fischer@metaways.de>
  * 
  * @todo        split this
@@ -19,7 +19,7 @@ require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php'
 /**
  * Test class for Tinebase_Auth_Abstract
  */
-class Tinebase_AuthTest extends PHPUnit_Framework_TestCase
+class Tinebase_AuthTest extends TestCase
 {
     /**
      * @var array test objects
@@ -37,18 +37,6 @@ class Tinebase_AuthTest extends PHPUnit_Framework_TestCase
     protected $_originalBackendType = null;
 
     /**
-     * Runs the test methods of this class.
-     *
-     * @access public
-     * @static
-     */
-    public static function main()
-    {
-        $suite  = new PHPUnit_Framework_TestSuite('Tinebase_AuthTest');
-        PHPUnit_TextUI_TestRunner::run($suite);
-    }
-
-    /**
      * Sets up the fixture.
      * This method is called before a test is executed.
      *
@@ -56,7 +44,8 @@ class Tinebase_AuthTest extends PHPUnit_Framework_TestCase
      */
     protected function setUp()
     {
-        Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
+        parent::setUp();
+
         $this->_originalBackendConfiguration = Tinebase_Auth::getBackendConfiguration();
         $this->_originalBackendType = Tinebase_Auth::getConfiguredBackend();
     }
@@ -76,7 +65,7 @@ class Tinebase_AuthTest extends PHPUnit_Framework_TestCase
         Tinebase_Auth::saveBackendConfiguration();
         Tinebase_Auth::getInstance()->setBackend();
         
-        Tinebase_TransactionManager::getInstance()->rollBack();
+        parent::tearDown();
     }
 
     /**
@@ -182,19 +171,17 @@ class Tinebase_AuthTest extends PHPUnit_Framework_TestCase
         
         $this->assertEquals(Tinebase_Auth::IMAP, Tinebase_Auth::getConfiguredBackend());
 
-        $testConfig = Zend_Registry::get('testConfig');
+        $testCredentials = TestServer::getInstance()->getTestCredentials();
         
         // valid authentication
-        $authResult = Tinebase_Auth::getInstance()->authenticate($testConfig->username, $testConfig->password);
+        $authResult = Tinebase_Auth::getInstance()->authenticate($testCredentials['username'], $testCredentials['password']);
         $this->assertTrue($authResult->isValid());
         
         // invalid authentication
-        $authResult = Tinebase_Auth::getInstance()->authenticate($testConfig->username, 'some pw');
+        $authResult = Tinebase_Auth::getInstance()->authenticate($testCredentials['username'], 'some pw');
         $this->assertFalse($authResult->isValid());
         $this->assertEquals(Tinebase_Auth::FAILURE_CREDENTIAL_INVALID, $authResult->getCode());
-        if ($testConfig->email) {
-            $this->assertEquals(array('Invalid credentials for user ' . $testConfig->email, ''), $authResult->getMessages());
-        }
+        $this->assertEquals(array('Invalid credentials for user ' . $this->_getEmailAddress(), ''), $authResult->getMessages());
     }
     
     /**