Merge branch '2013.03'
[tine20] / tests / tine20 / Calendar / JsonTests.php
index 3ae3581..9f6470b 100644 (file)
@@ -221,6 +221,8 @@ class Calendar_JsonTests extends Calendar_TestCase
         
         $filter = $this->_getEventFilterArray();
         $searchResultData = $this->_uit->searchEvents($filter, array());
+        
+        $this->assertTrue(! empty($searchResultData['results']));
         $resultEventData = $searchResultData['results'][0];
         
         $this->_assertJsonEvent($eventData, $resultEventData, 'failed to search event');
@@ -299,6 +301,7 @@ class Calendar_JsonTests extends Calendar_TestCase
         $filter[] = array('field' => 'organizer', 'operator' => 'equals', 'value' => Addressbook_Model_Contact::CURRENTCONTACT);
         
         $searchResultData = $this->_uit->searchEvents($filter, array());
+        $this->assertTrue(! empty($searchResultData['results']));
         $resultEventData = $searchResultData['results'][0];
         $this->_assertJsonEvent($eventData, $resultEventData, 'failed to search event');
         
@@ -310,7 +313,6 @@ class Calendar_JsonTests extends Calendar_TestCase
     
     /**
      * search event with alarm
-     *
      */
     public function testSearchEventsWithAlarm()
     {
@@ -318,6 +320,7 @@ class Calendar_JsonTests extends Calendar_TestCase
         $persistentEventData = $this->_uit->saveEvent($eventData);
         
         $searchResultData = $this->_uit->searchEvents($this->_getEventFilterArray(), array());
+        $this->assertTrue(! empty($searchResultData['results']));
         $resultEventData = $searchResultData['results'][0];
         
         $this->_assertJsonEvent($persistentEventData, $resultEventData, 'failed to search event with alarm');
@@ -581,18 +584,7 @@ class Calendar_JsonTests extends Calendar_TestCase
         $someRecurInstance['seq'] = 2;
         $this->_uit->updateRecurSeries($someRecurInstance, FALSE, FALSE);
         
-        $from = $recurSet[0]['dtstart'];
-        $until = new Tinebase_DateTime($from);
-        $until->addWeek(5)->addHour(10);
-        $until = $until->get(Tinebase_Record_Abstract::ISO8601LONG);
-        
-        $filter = array(
-            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
-            array('field' => 'period',       'operator' => 'within', 'value' => array('from' => $from, 'until' => $until)),
-        );
-        
-        $searchResultData = $this->_uit->searchEvents($filter, array());
-        
+        $searchResultData = $this->_searchRecurSeries($recurSet[0]);
         $this->assertEquals(6, count($searchResultData['results']));
         
         $summaryMap = array();
@@ -611,6 +603,27 @@ class Calendar_JsonTests extends Calendar_TestCase
     }
     
     /**
+     * search updated recur set
+     * 
+     * @param array $firstInstance
+     * @return array
+     */
+    protected function _searchRecurSeries($firstInstance)
+    {
+        $from = $firstInstance['dtstart'];
+        $until = new Tinebase_DateTime($from);
+        $until->addWeek(5)->addHour(10);
+        $until = $until->get(Tinebase_Record_Abstract::ISO8601LONG);
+        
+        $filter = array(
+            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
+            array('field' => 'period',       'operator' => 'within', 'value' => array('from' => $from, 'until' => $until)),
+        );
+        
+        return $this->_uit->searchEvents($filter, array());
+    }
+    
+    /**
      * testUpdateRecurExceptionsFromSeriesOverDstMove
      * 
      * @todo implement
@@ -671,6 +684,7 @@ class Calendar_JsonTests extends Calendar_TestCase
         ));
         
         $searchResultData = $this->_uit->searchEvents($filter, array());
+        $this->assertTrue(! empty($searchResultData['results']));
         $resultEventData = $searchResultData['results'][0];
         
         $this->_assertJsonEvent($eventData, $resultEventData, 'failed to filter for me as attender');
@@ -709,6 +723,7 @@ class Calendar_JsonTests extends Calendar_TestCase
         $eventData['organizer'] = $this->_personasContacts['sclever']->getId();
         $eventData = $this->_uit->saveEvent($eventData);
         $filter = $this->_getEventFilterArray($this->_personasDefaultCals['sclever']->getId());
+        $filter[] = array('field' => 'summary', 'operator' => 'equals', 'value' => 'Wakeup');
         $searchResultData = $this->_uit->searchEvents($filter, array());
         $this->assertTrue(! empty($searchResultData['results']), 'expected event in search result (search by sclever): ' 
             . print_r($eventData, TRUE) . 'search filter: ' . print_r($filter, TRUE));
@@ -747,7 +762,8 @@ class Calendar_JsonTests extends Calendar_TestCase
             'summary' => 'bla bla',
             'class'    => 'PUBLIC',
             'transp'    => 'OPAQUE',
-            'container_id' => $container['id']
+            'container_id' => $container['id'],
+            'organizer' => Tinebase_Core::getUser()->contact_id
             ));
         $event = Calendar_Controller_Event::getInstance()->create($event);
         $this->assertEquals($container['id'], $event->container_id);
@@ -1356,4 +1372,30 @@ class Calendar_JsonTests extends Calendar_TestCase
             $this->assertEquals('Calendar_Exception_AttendeeBusy', get_class($ceab));
         }
     }
+    
+    /**
+     * testAddAttachmentToRecurSeries
+     * 
+     * @see 0005024: allow to attach external files to records
+     */
+    public function testAddAttachmentToRecurSeries()
+    {
+        $tempFileBackend = new Tinebase_TempFile();
+        $tempFile = $tempFileBackend->createTempFile(dirname(dirname(__FILE__)) . '/Filemanager/files/test.txt');
+        
+        $recurSet = array_value('results', $this->testSearchRecuringIncludes());
+        // update recurseries 
+        $someRecurInstance = $recurSet[2];
+        $someRecurInstance['attachments'] = array(array('tempFile' => array('id' => $tempFile->getId())));
+        $someRecurInstance['seq'] = 2;
+        $this->_uit->updateRecurSeries($someRecurInstance, FALSE, FALSE);
+        
+        $searchResultData = $this->_searchRecurSeries($recurSet[0]);
+        foreach ($searchResultData['results'] as $recurInstance) {
+            $this->assertTrue(isset($recurInstance['attachments']), 'no attachments found in event: ' . print_r($recurInstance, TRUE));
+            $this->assertEquals(1, count($recurInstance['attachments']));
+            $attachment = $recurInstance['attachments'][0];
+            $this->assertEquals('text/plain', $attachment['contenttype'], print_r($attachment, TRUE));
+        }
+    }
 }