Merge branch '2013.03' into 2013.10
[tine20] / tests / tine20 / Calendar / Controller / EventNotificationsTests.php
index 4eb1c5b..f544109 100644 (file)
@@ -99,6 +99,36 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
         $this->_assertMail('jsmith', NULL);
         $this->_assertMail('pwulf, sclever, jmcblack, rwright', 'cancel');
     }
+
+    /**
+     * testInvitationWithAttachment
+     * 
+     * @see 0008592: append event file attachments to invitation mail
+     */
+    public function testInvitationWithAttachment()
+    {
+        $event = $this->_getEvent(TRUE);
+        $event->attendee = $this->_getPersonaAttendee('pwulf');
+        
+        $tempFileBackend = new Tinebase_TempFile();
+        $tempFile = $tempFileBackend->createTempFile(dirname(dirname(dirname(__FILE__))) . '/Filemanager/files/test.txt');
+        $event->attachments = array(array('tempFile' => array('id' => $tempFile->getId())));
+        
+        self::flushMailer();
+        $persistentEvent = $this->_eventController->create($event);
+        
+        $messages = self::getMessages();
+        
+        $this->assertEquals(1, count($messages));
+        $parts = $messages[0]->getParts();
+        $this->assertEquals(2, count($parts));
+        $fileAttachment = $parts[1];
+        $this->assertEquals('text/plain; name="=?utf-8?Q?tempfile.tmp?="', $fileAttachment->type);
+        
+        // @todo assert attachment content (this seems to not work with array mailer, maybe we need a "real" email test here)
+//         $content = $fileAttachment->getDecodedContent();
+//         $this->assertEquals('test file content', $content);
+    }
     
     /**
      * testUpdateEmpty
@@ -301,8 +331,9 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
                 'attendee'      => $this->_getPersonaAttendee('jmcblack'),
         ));
         
+        self::flushMailer();
         $persistentEvent = $this->_eventController->create($event);
-        //$persistentSClever = Calendar_Model_Attender::getAttendee($persistentEvent->attendee, $event->attendee[1]);
+        $this->_assertMail('jmcblack', 'Recurrance rule:    Daily', 'body');
         
         $exceptions = new Tinebase_Record_RecordSet('Calendar_Model_Event');
         $recurSet = Calendar_Model_Rrule::computeRecurrenceSet($persistentEvent, $exceptions, $from, $until);
@@ -318,6 +349,7 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
         $recurSet[5]->last_modified_time = $updatedBaseEvent->last_modified_time;
         $recurSet[5]->summary = 'exceptional summary';
         $this->_eventController->createRecurException($recurSet[5], FALSE, FALSE); //2012-03-20
+        $this->_assertMail('jmcblack', 'This is an event series exception', 'body');
         $this->_assertMail('jmcblack', 'update');
         
         // reschedule instance
@@ -479,6 +511,8 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
      */
     public function testParallelAlarmTrigger()
     {
+        $this->markTestSkipped('TODO fixme: 0009116: fix Calendar_Controller_EventNotificationsTests::testParallelAlarmTrigger');
+        
         $this->_testNeedsTransaction();
         
         try {
@@ -1013,7 +1047,7 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
      * 
      * @see #6800: add message-id to notification mails
      */
-    protected function _assertMail($_personas, $_assertString = NULL)
+    protected function _assertMail($_personas, $_assertString = NULL, $_location = 'subject')
     {
         $messages = self::getMessages();
         
@@ -1031,10 +1065,33 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
                 $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);
-                $subject = $mailsForPersona[0]->getSubject();
-                $this->assertTrue(FALSE !== strpos($subject, $_assertString), 'Mail subject for ' . $personaName . ' should contain "' . $_assertString . '" but '. $subject . ' is given');
                 $this->assertEquals('UTF-8', $mailsForPersona[0]->getCharset());
                 
+                switch ($_location) {
+                    case 'subject':
+                        $subject = $mailsForPersona[0]->getSubject();
+                        $this->assertTrue(FALSE !== strpos($subject, $_assertString), 'Mail subject for ' . $personaName . ' should contain "' . $_assertString . '" but '. $subject . ' is given');
+                        break;
+                        
+                    case 'body':
+                        $bodyPart = $mailsForPersona[0]->getBodyText(FALSE);
+                        
+                        // so odd!
+                        $s = fopen('php://temp','r+');
+                        fputs($s, $bodyPart->getContent());
+                        rewind($s);
+                        $bodyPartStream = new Zend_Mime_Part($s);
+                        $bodyPartStream->encoding = $bodyPart->encoding;
+                        $bodyText = $bodyPartStream->getDecodedContent();
+                        
+                        $this->assertContains($_assertString, $bodyText);
+                        break;
+                        
+                    default:
+                        throw new Exception('no such location '. $_location);
+                        break;
+                }
+                
                 $headers = $mailsForPersona[0]->getHeaders();
                 $this->assertTrue(isset($headers['Message-Id']), 'message-id header not found');
                 $this->assertContains('@' . php_uname('n'), $headers['Message-Id'][0], 'hostname not in message-id');