adds caldav event import test
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 27 Aug 2014 11:56:12 +0000 (13:56 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 4 Sep 2014 09:26:46 +0000 (11:26 +0200)
Change-Id: I43af954d96b830fd358a848645c52132daefb0df
Reviewed-on: http://gerrit.tine20.com/customers/1046
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Import/CalDAV/ClientMock.php
tests/tine20/Calendar/Import/CalDAVTest.php

index a659d7c..600135f 100644 (file)
@@ -26,6 +26,35 @@ class Calendar_Import_CalDAV_ClientMock extends Calendar_Import_CalDav_Client
         '{urn:ietf:params:xml:ns:caldav}calendar-home-set' => '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0',
     );
     
+    protected $_calendarICSResponse = array (
+      '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/' => 
+      array (
+      ),
+      '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/20E3E0E4-762D-42D6-A563-206161A9F1CA.ics' => 
+      array (
+      ),
+      '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/4971F93F-8657-412B-841A-A0FD9139CD61.ics' => 
+      array (
+      ),
+      '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/88F077A1-6F5B-4C6C-8D73-94C1F0127492.ics' => 
+      array (
+      ),
+      /*
+      '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/c6464fb6-6886-8861-11da-5240d50d2df9.ics' => 
+      array (
+      ),
+      '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/c6464fd0-016f-16f1-2bdd-9d79275458a3.ics' => 
+      array (
+      ),
+      '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/D02B2082-ED55-444F-886F-5509AFF4992F.ics' => 
+      array (
+      ),
+      '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/FDEB95A9-289E-48DD-98E7-661E188D1D05.ics' => 
+      array (
+      ),
+      */
+    );
+    
     protected function _findAllCalendarsResponse()
     {
         return array (
@@ -220,6 +249,128 @@ class Calendar_Import_CalDAV_ClientMock extends Calendar_Import_CalDav_Client
     }
     
     /**
+     * calendar data response
+     * 
+     * @return string
+     * 
+     * @todo make this dynamic (only return requested cal data) 
+     */
+    protected function _calendarDataResponse()
+    {
+        return array (
+  '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/20E3E0E4-762D-42D6-A563-206161A9F1CA.ics' => 
+  array (
+    '{urn:ietf:params:xml:ns:caldav}calendar-data' => 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 5.0.3//EN
+CALSCALE:GREGORIAN
+BEGIN:VTIMEZONE
+TZID:Europe/Berlin
+BEGIN:DAYLIGHT
+TZOFFSETFROM:+0100
+RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
+DTSTART:19810329T020000
+TZNAME:CEST
+TZOFFSETTO:+0200
+END:DAYLIGHT
+BEGIN:STANDARD
+TZOFFSETFROM:+0200
+RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
+DTSTART:19961027T030000
+TZNAME:CET
+TZOFFSETTO:+0100
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+CREATED:20140602T131852Z
+UID:20E3E0E4-762D-42D6-A563-206161A9F1CA
+DTEND;TZID=Europe/Berlin:20140604T171500
+TRANSP:OPAQUE
+SUMMARY:TEST06
+DTSTART;TZID=Europe/Berlin:20140604T161500
+DTSTAMP:20140602T131935Z
+SEQUENCE:3
+END:VEVENT
+END:VCALENDAR',
+      '{DAV:}getetag' => '"bcc36c611f0b60bfee64b4d42e44aa1d"',
+      ),
+      '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/4971F93F-8657-412B-841A-A0FD9139CD61.ics' =>
+      array (
+          '{urn:ietf:params:xml:ns:caldav}calendar-data' => 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 5.0.3//EN
+CALSCALE:GREGORIAN
+BEGIN:VTIMEZONE
+TZID:Europe/Berlin
+BEGIN:DAYLIGHT
+TZOFFSETFROM:+0100
+RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
+DTSTART:19810329T020000
+TZNAME:CEST
+TZOFFSETTO:+0200
+END:DAYLIGHT
+BEGIN:STANDARD
+TZOFFSETFROM:+0200
+RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
+DTSTART:19961027T030000
+TZNAME:CET
+TZOFFSETTO:+0100
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+CREATED:20140602T131707Z
+UID:4971F93F-8657-412B-841A-A0FD9139CD61
+DTEND;TZID=Europe/Berlin:20140604T153000
+TRANSP:OPAQUE
+SUMMARY:TEST05
+DTSTART;TZID=Europe/Berlin:20140604T143000
+DTSTAMP:20140602T131725Z
+SEQUENCE:3
+END:VEVENT
+END:VCALENDAR',
+    '{DAV:}getetag' => '"8b89914690ad7290fa9a2dc1da490489"',
+  ),
+  '/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/88F077A1-6F5B-4C6C-8D73-94C1F0127492.ics' => 
+  array (
+    '{urn:ietf:params:xml:ns:caldav}calendar-data' => 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 5.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VTIMEZONE
+TZID:Europe/Berlin
+BEGIN:DAYLIGHT
+TZOFFSETFROM:+0100
+RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
+DTSTART:19810329T020000
+TZNAME:CEST
+TZOFFSETTO:+0200
+END:DAYLIGHT
+BEGIN:STANDARD
+TZOFFSETFROM:+0200
+RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
+DTSTART:19961027T030000
+TZNAME:CET
+TZOFFSETTO:+0100
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+CREATED:20111207T143455Z
+UID:88F077A1-6F5B-4C6C-8D73-94C1F0127492
+DTEND;TZID=Europe/Berlin:20111207T170000
+TRANSP:OPAQUE
+SUMMARY:test
+DTSTART;TZID=Europe/Berlin:20111207T160000
+DTSTAMP:20111207T143502Z
+SEQUENCE:2
+END:VEVENT
+END:VCALENDAR
+',
+    '{DAV:}getetag' => '"0b3621a20e9045d8679075db57e881dd"',
+  ),
+        );
+    }
+    
+    /**
      * perform mocked calDavRequest
      *
      * @param string $method
@@ -257,10 +408,10 @@ class Calendar_Import_CalDAV_ClientMock extends Calendar_Import_CalDav_Client
             return $this->_resolvePrincipalResponse();
             
         } else if ($body == self::findAllCalendarICSsRequest) {
-            throw new Tinebase_Exception_NotImplemented('findAllCalendarICSsRequest to be implemented');
+            return $this->_calendarICSResponse;
             
-        } else if ($body == self::getAllCalendarDataRequest) {
-            throw new Tinebase_Exception_NotImplemented('getAllCalendarDataRequest to be implemented');
+        } else if (preg_match('/<b:calendar-data \/>/', $body)) {
+            return $this->_calendarDataResponse();
             
         } else {
             throw new Tinebase_Exception_InvalidArgument('request not supported by mock');
index 52e3b82..ae873f8 100644 (file)
@@ -49,25 +49,53 @@ class Calendar_Import_CalDAVTest extends Calendar_TestCase
     public function testImportCalendars()
     {
         $this->_getUit()->importAllCalendars();
-        $calendarUuid = sha1('/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/');
-        $importedCalendar = Tinebase_Container::getInstance()->getByProperty($calendarUuid, 'uuid');
+        
+        $importedCalendar = $this->_getImportCalendar();
         
         $this->assertEquals('calendar', $importedCalendar->name);
         $this->assertEquals('Calendar_Model_Event', $importedCalendar->model, print_r($importedCalendar->toArray(), true));
         $this->assertEquals( Tinebase_Core::getUser()->getId(), $importedCalendar->owner_id, print_r($importedCalendar->toArray(), true));
     }
     
+    /**
+     * fetch import calendar
+     * 
+     * @return Tinebase_Model_Container
+     */
+    protected function _getImportCalendar()
+    {
+        $calendarUuid = sha1('/calendars/__uids__/0AA03A3B-F7B6-459A-AB3E-4726E53637D0/calendar/');
+        return Tinebase_Container::getInstance()->getByProperty($calendarUuid, 'uuid');
+    }
+    
+    /**
+     * test import of events
+     */
     public function testImportEvents()
     {
-        $this->markTestIncomplete('TODO: finish test');
+        $this->testImportCalendars();
         $this->_getUit()->importAllCalendarData();
-        // @todo add assertions
+        
+        $importedCalendar = $this->_getImportCalendar();
+        
+        $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(
+            array('field' => 'container_id', 'operator' => 'in', 'value' => array($importedCalendar->getId()))
+        )));
+        $this->assertEquals(3, count($events));
+        $this->assertTrue(array(
+            '"bcc36c611f0b60bfee64b4d42e44aa1d"',
+            '"8b89914690ad7290fa9a2dc1da490489"',
+            '"0b3621a20e9045d8679075db57e881dd"'
+        ) == $events->etag);
     }
     
+    /**
+     * @todo implement
+     */
     public function testUpdateEvents()
     {
         $this->markTestIncomplete('TODO: finish test');
-        $this->testImport();
+        $this->testImportEvents();
         // @todo change some events
         $this->_getUit()->updateAllCalendarData();
         // @todo add assertions