#6752: ci ldap tests
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 22 Apr 2014 14:51:28 +0000 (16:51 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 22 Apr 2014 15:19:23 +0000 (17:19 +0200)
* adds some more fixes for ldap tests
* creates demo data users/contacts with configured email domain
* allows to fetch test email domain in TestCase

https://forge.tine20.org/mantisbt/view.php?id=6752

Change-Id: I5d562c03c8230a2ce754c01f36f310221ed38b6a
Reviewed-on: http://gerrit.tine20.com/customers/545
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Controller/EventNotificationsTests.php
tests/tine20/Calendar/Export/ICalTest.php
tests/tine20/Calendar/Frontend/WebDAV/EventTest.php
tests/tine20/Calendar/JsonTests.php
tests/tine20/Felamimail/JsonTest.php
tests/tine20/TestCase.php
tests/tine20/Tinebase/WebDav/PrincipalBackendTest.php
tine20/Admin/Setup/DemoData.php
tine20/Calendar/Export/Ical.php

index 484b68b..f761568 100644 (file)
@@ -9,11 +9,6 @@
  */
 
 /**
- * Test helper
- */
-require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
-
-/**
  * Test class for Calendar_Controller_EventNotifications
  * 
  * @package     Calendar
@@ -999,8 +994,8 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
     
         // create alarm reminder/snooze exception
         Calendar_Controller_EventNotificationsTests::flushMailer();
-        $vcalendarStream = fopen(dirname(__FILE__) . '/../Import/files/apple_ical_remind_part2.ics', 'r');
-        $event->put($vcalendarStream);
+        $vcalendar = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../Import/files/apple_ical_remind_part2.ics');
+        $event->put($vcalendar);
     
         // assert no reschedule mail
         $messages = Calendar_Controller_EventNotificationsTests::getMessages();
@@ -1129,6 +1124,7 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
         
         foreach (explode(',', $_personas) as $personaName) {
             $mailsForPersona = array();
+            $otherRecipients = array();
             $personaEmail = strstr($personaName, '@') ? 
                 $personaName : 
                 $this->_personas[trim($personaName)]->accountEmailAddress;
@@ -1136,13 +1132,15 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
             foreach ($messages as $message) {
                 if (array_value(0, $message->getRecipients()) == $personaEmail) {
                     array_push($mailsForPersona, $message);
+                } else {
+                    array_push($otherRecipients, $message->getRecipients());
                 }
             }
             
             if (! $_assertString) {
                 $this->assertEquals(0, count($mailsForPersona), 'No mail should be send for '. $personaName);
             } else {
-                $this->assertEquals(1, count($mailsForPersona), 'One mail should be send for '. $personaName);
+                $this->assertEquals(1, count($mailsForPersona), 'One mail should be send for '. $personaName . ' other recipients: ' . print_r($otherRecipients, true));
                 $this->assertEquals('UTF-8', $mailsForPersona[0]->getCharset());
                 
                 switch ($_location) {
index 4189f03..0c739e2 100644 (file)
@@ -4,17 +4,12 @@
  * 
  * @package     Calendar
  * @license     http://www.gnu.org/licenses/agpl.html
- * @copyright   Copyright (c) 2010 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2010-2014 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Cornelius Weiss <c.weiss@metaways.de>
  * 
  */
 
 /**
- * Test helper
- */
-require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
-
-/**
  * Test class for Calendar_ICalTests
  */
 class Calendar_Export_ICalTest extends Calendar_TestCase
@@ -129,18 +124,22 @@ class Calendar_Export_ICalTest extends Calendar_TestCase
         $this->assertEquals(2, preg_match_all('/BEGIN:VEVENT\r\n/', $ics, $matches), 'There should be exactly 2 VEVENT compontents');
     }
     
+    /**
+     * testExportOrganizer
+     */
     public function testExportOrganizer()
     {
         $this->_testEvent->organizer = array_value('pwulf', Zend_Registry::get('personas'))->contact_id;
         
         $exporter = new Calendar_Export_Ical();
         $ics = $exporter->eventToIcal($this->_testEvent);
-//        echo $ics;
-
-        // assert organizer
-        $this->assertEquals(1, preg_match("/ORGANIZER;CN=\"Wulf, Paul\":mailto:pwulf@tine20.org\r\n/", $ics), 'ORGANIZER missing/broken');
+        
+        $this->assertEquals(1, preg_match("/ORGANIZER;CN=\"Wulf, Paul\":mailto:pwulf@" . $this->_getMailDomain() . "\r\n/", $ics), 'ORGANIZER missing/broken');
     }
     
+    /**
+     * testExportAttendee
+     */
     public function testExportAttendee()
     {
         $this->_testEvent->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
@@ -154,10 +153,8 @@ class Calendar_Export_ICalTest extends Calendar_TestCase
         
         $exporter = new Calendar_Export_Ical();
         $ics = $exporter->eventToIcal($this->_testEvent);
-//        echo $ics;
-
-        // assert organizer
-        $this->assertEquals(1, preg_match("/ATTENDEE;CN=\"Wulf, Paul\";CUTYPE=INDIVIDUAL;EMAIL=pwulf@tine20.org;PARTSTAT=\r\n ACCEPTED;ROLE=REQ-PARTICIPANT;RSVP=FALSE:mailto:pwulf@tine20.org\r\n/", $ics), 'ATTENDEE missing/broken');
+        
+        $this->assertContains("ATTENDEE;CN=\"Wulf, Paul\";CUTYPE=INDIVIDUAL;EMAIL=pwulf@" . $this->_getMailDomain(), (string) $ics, 'ATTENDEE missing/broken');
     }
     
     public function testExportAlarm()
index 56bbd1e..439a2e8 100644 (file)
@@ -733,6 +733,7 @@ class Calendar_Frontend_WebDAV_EventTest extends Calendar_TestCase
                 '/unittest@tine20.org/',
                 '/unittest@ti\n ne20.org/',
                 '/pwulf\n @tine20.org/',
+                '/sclever@tine20.org/',
             ), 
             array(
                 $unittestUserEmail,
@@ -741,6 +742,7 @@ class Calendar_Frontend_WebDAV_EventTest extends Calendar_TestCase
                 $unittestUserEmail,
                 $unittestUserEmail,
                 array_value('pwulf', Zend_Registry::get('personas'))->accountEmailAddress,
+                array_value('sclever', Zend_Registry::get('personas'))->accountEmailAddress,
             ), 
             $vcalendar
         );
index 7788edf..dc4b3c9 100644 (file)
@@ -879,6 +879,7 @@ class Calendar_JsonTests extends Calendar_TestCase
             'visibility'     => Tinebase_Model_Group::VISIBILITY_HIDDEN
         ));
         $hiddenGroup = Admin_Controller_Group::getInstance()->create($hiddenGroup);
+        $this->_groupIdsToDelete[] = $hiddenGroup->getId();
         
         $filter = array(array(
             'field'    => 'attender',
index e0d275a..8680df4 100644 (file)
@@ -1351,8 +1351,11 @@ class Felamimail_JsonTest extends PHPUnit_Framework_TestCase
     {
         $result = $this->_getVacationMessageWithTemplate();
         $sclever = Tinebase_User::getInstance()->getFullUserByLoginName('sclever');
-        $this->assertEquals("Ich bin vom 18.04.2012 bis zum 20.04.2012 im Urlaub. Bitte kontaktieren Sie<br /> Paul Wulf (pwulf@tine20.org) oder Susan Clever (" .
-            $sclever->accountEmailAddress . ").<br /><br />I am on vacation until Apr 20, 2012. Please contact Paul Wulf<br />(pwulf@tine20.org) or Susan Clever (" .
+        $pwulf = Tinebase_User::getInstance()->getFullUserByLoginName('pwulf');
+        $this->assertEquals("Ich bin vom 18.04.2012 bis zum 20.04.2012 im Urlaub. Bitte kontaktieren Sie<br /> Paul Wulf (" .
+            $pwulf->accountEmailAddress . ") oder Susan Clever (" .
+            $sclever->accountEmailAddress . ").<br /><br />I am on vacation until Apr 20, 2012. Please contact Paul Wulf<br />(" .
+            $pwulf->accountEmailAddress . ") or Susan Clever (" .
             $sclever->accountEmailAddress . ") instead.<br /><br />" .
             Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::getUser()->getId())->n_fn, $result['message']);
     }
index 9a46ddd..c7968c8 100644 (file)
@@ -156,4 +156,15 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
             Tinebase_Model_Grants::GRANT_EDIT
         )->getFirstRecord();
     }
+
+    /**
+     * get test mail domain
+     * 
+     * @return string
+     */
+    protected function _getMailDomain()
+    {
+        $testconfig = Zend_Registry::get('testConfig');
+        return ($testconfig && isset($testconfig->maildomain)) ? $testconfig->maildomain : 'tine20.org';
+    }
 }
index 44bc0c1..9913168 100644 (file)
@@ -88,15 +88,11 @@ class Tinebase_WebDav_PrincipalBackendTest extends PHPUnit_Framework_TestCase
     
     public function testSearchPrincipals()
     {
-        $uris = $this->_backend->searchPrincipals('principals/users/', array('{http://sabredav.org/ns}email-address' => Tinebase_Core::getUser()->accountEmailAddress));
+        $uris = $this->_backend->searchPrincipals('principals/users/', array(
+            '{http://sabredav.org/ns}email-address' => Tinebase_Core::getUser()->accountEmailAddress
+        ));
         
-        //var_dump($uris);
-        
-        $this->assertEquals(1, count($uris));
+        $this->assertEquals(1, count($uris), 'could not find user by email address ' . Tinebase_Core::getUser()->accountEmailAddress);
         $this->assertContains('principals/users/' . Tinebase_Core::getUser()->contact_id, $uris);
     }
 }
-
-if (PHPUnit_MAIN_METHOD == 'Tinebase_WebDav_PrincipalBackendTest::main') {
-    Tinebase_WebDav_PrincipalBackendTest::main();
-}
index cb18b6a..9f24a3b 100644 (file)
@@ -171,6 +171,10 @@ class Admin_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
 
                 $group   = Tinebase_Group::getInstance()->getGroupByName('Users');
                 $groupId = $group->getId();
+                
+                // TODO think about fetching this from IMAP config
+                $testconfig = Zend_Registry::get('testConfig');
+                $emailDomain = ($testconfig && isset($testconfig->maildomain)) ? $testconfig->maildomain : 'tine20.org';
 
                 $user = new Tinebase_Model_FullUser(array(
                     'accountLoginName'      => $login,
@@ -179,8 +183,7 @@ class Admin_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
                     'accountLastName'       => $last,
                     'accountFirstName'      => $given,
                     'accountFullName'       => $fullName,
-                    //'accountEmailAddress'   => $login . '@tine-publications.co.uk',
-                    'accountEmailAddress'   => $login . '@tine20.org'
+                    'accountEmailAddress'   => $login . '@' . $emailDomain,
                 ));
 
                 if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
@@ -205,7 +208,6 @@ class Admin_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
 
                 // give additional testusers the same password as the primary test account
                 try {
-                    $testconfig = Zend_Registry::get('testConfig');
                     Tinebase_User::getInstance()->setPassword($user, $testconfig->password);
                 } catch (Zend_Exception $e) {
                     Tinebase_User::getInstance()->setPassword($user, static::$_defaultPassword);
index ec17d45..403049f 100644 (file)
@@ -54,6 +54,12 @@ class Calendar_Export_Ical
         
     }
     
+    /**
+     * eventToIcal
+     * 
+     * @param Tinebase_Record_RecordSet|Calendar_Model_Event $_event
+     * @return qCal_Component_Vcalendar
+     */
     public function eventToIcal($_event)
     {
         if ($_event instanceof Tinebase_Record_RecordSet) {