Merge branch 'pu/2013.10-icsimport' into 2014.09
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 9 Oct 2014 08:24:19 +0000 (10:24 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 9 Oct 2014 08:24:19 +0000 (10:24 +0200)
1  2 
tests/tine20/Calendar/Import/ICalTest.php

@@@ -27,7 -27,7 +27,7 @@@ class Calendar_Import_ICalTest extends 
          $importer->importData($icalData);
          
          $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(
 -            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId())
 +            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId())
          )), NULL);
          
          $this->assertEquals(6, $events->count(), 'events was not imported');
          $this->assertEquals('2008-11-05 15:00:00', $startbucks->dtstart->format(Tinebase_Record_Abstract::ISO8601LONG));
      }
      
+     /**
+      * test simple import from file into a not existing container
+      * 
+      *  - the calendar should be created
+      */
+     public function testSimpleImportIntoNewContainer()
+     {
+         $importer = new Calendar_Import_Ical(array(
+             'container_id' => 'unittest_not_existing',
+         ));
+         $result = $importer->importFile(dirname(__FILE__) . '/files/simple.ics');
+         $importedContainerId = Tinebase_Container::getInstance()->getContainerByName(
+                     'Calendar',
+                     'unittest_not_existing',
+                     Tinebase_Model_Container::TYPE_PERSONAL,
+                     Tinebase_Core::getUser()->getId()
+                 )->getId();
+         $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(
+             array('field' => 'container_id', 'operator' => 'equals', 'value' => $importedContainerId)
+         )), NULL);
+         
+         $this->assertEquals($importedContainerId, Tinebase_Container::getInstance()->getContainerById($importedContainerId)->getId());
+         $this->assertEquals(6, $events->count(), 'events was not imported');
+     }
+     
      public function testImportSimpleFromFile()
      {
          $importer = new Calendar_Import_Ical(array(
@@@ -45,7 -73,7 +73,7 @@@
          
          $importer->importFile(dirname(__FILE__) . '/files/simple.ics');
          $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(
 -            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId())
 +            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId())
          )), NULL);
          
          $this->assertEquals(6, $events->count(), 'events where not imported');
@@@ -64,7 -92,7 +92,7 @@@
          $importer->importFile(dirname(__FILE__) . '/files/XMAS_DE.ics');
          
          $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(
 -            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
 +            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId()),
              array('field' => 'period', 'operator' => 'within', 'value' => array(
                  'from'  => '2015-12-23 22:00:00',
                  'until' => '2015-12-26 22:00:00'
      protected function _checkImport($failMessage = '', $assertNumber = 1)
      {
          $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(
 -            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId())
 +            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId())
          )), NULL);
          
          $this->assertEquals($assertNumber, $events->count(), 'events where not imported ' . $failMessage);
          
          $importer->importFile(dirname(__FILE__) . '/files/outlook12.ics');
          $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(
 -            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId())
 +            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId())
          )), NULL);
          
          $this->assertEquals(1, $events->count(), 'events where not imported');
          $from = new Tinebase_DateTime('2014-04-23 22:00:00');
          $until = new Tinebase_DateTime('2014-05-23 22:00:00');
          $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(
 -            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
 +            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId()),
              array('field' => 'period', 'operator' => 'within', 'value' => array(
                  'from'  => $from->toString(),
                  'until' => $until->toString()