/** * Ensures everathing works as expected */ public function testOk() { $entity = new \Conjoon\Data\Entity\Mail\DefaultAttachmentEntity(); $entity->setMimeType('text/html'); $entity->setFileName('fileName'); $successResult = new GetAttachmentResult($entity, new \Conjoon\Mail\Client\Message\DefaultAttachmentLocation(new \Conjoon\Mail\Client\Message\DefaultMessageLocation(new \Conjoon\Mail\Client\Folder\Folder(new \Conjoon\Mail\Client\Folder\DefaultFolderPath('["1", "2"]')), "1"), "1")); $this->assertEquals(array('content' => "", 'contentId' => "", 'mimeType' => 'text/html', 'fileName' => 'fileName', 'key' => '', 'encoding' => ''), $successResult->toArray()); }
protected function setUp() { $attachment1 = new \Conjoon\Data\Entity\Mail\DefaultAttachmentEntity(); $attachment1->setKey('key1'); $attachment2 = new \Conjoon\Data\Entity\Mail\DefaultAttachmentEntity(); $attachment2->setKey('key2'); $this->input = array('groupwareEmailFolders' => new \Conjoon\Data\Entity\Mail\DefaultMailFolderEntity(), 'attachment' => array($attachment1, $attachment2), 'date' => new \DateTime(), 'subject' => "subject", 'from' => "from", 'replyTo' => "replyTo", 'to' => "To", 'cc' => "cc", 'bcc' => "bcc", 'inReplyTo' => "in_reply_to", 'references' => "References", 'contentTextPlain' => "content text plain", 'contentTextHtml' => "content text html", 'recipients' => "Recipients", 'sender' => "Sender"); }
/** * Ensures everything works as expected */ public function testOk() { $message = new ImapMessageEntity(); foreach ($this->input as $field => $value) { if ($field == 'attachments') { for ($i = 0, $len = count($value); $i < $len; $i++) { $attData =& $value[$i]; $attachment = new \Conjoon\Data\Entity\Mail\DefaultAttachmentEntity(); $attachment->setKey($attData['key']); $attachment->setFileName($attData['fileName']); $attachment->setMimeType($attData['mimeType']); $attachment->setEncoding($attData['encoding']); $attachment->setContentId($attData['contentId']); $mailAttachmentContent = new \Conjoon\Data\Entity\Mail\DefaultAttachmentContentEntity(); $mailAttachmentContent->setContent($attData['mailAttachmentContent']['content']); $attachment->setAttachmentContent($mailAttachmentContent); $message->addAttachment($attachment); } $this->assertSame(2, count($message->getAttachments())); for ($i = 0, $len = 2; $i < 2; $i++) { $attachment = $message->getAttachments(); $attachment = $attachment[$i]; $attData =& $value[$i]; $this->assertSame($attData['key'], $attachment->getKey()); $this->assertSame($attData['fileName'], $attachment->getFileName()); $this->assertSame($attData['mimeType'], $attachment->getMimeType()); $this->assertSame($attData['encoding'], $attachment->getEncoding()); $this->assertSame($attData['contentId'], $attachment->getContentId()); $mailAttachmentContent = $attachment->getAttachmentContent(); $this->assertSame($attData['mailAttachmentContent']['content'], $mailAttachmentContent->getContent()); } continue; } $methodSet = "set" . ucfirst($field); $methodGet = "get" . ucfirst($field); $message->{$methodSet}($value); $this->assertSame($value, $message->{$methodGet}()); } }
/** * @inheritdoc */ public function createFrom(array $options) { $stringEmptyCheck = array('type' => 'string', 'allowEmpty' => true); $stringCheck = array('type' => 'string', 'allowEmpty' => false); try { ArgumentCheck::check(array('mimeType' => $stringEmptyCheck, 'encoding' => $stringEmptyCheck, 'fileName' => $stringCheck, 'content' => $stringEmptyCheck, 'contentId' => $stringEmptyCheck), $options); $attachmentEntity = new \Conjoon\Data\Entity\Mail\DefaultAttachmentEntity(); $attachmentContent = new \Conjoon\Data\Entity\Mail\DefaultAttachmentContentEntity(); $attachmentEntity->setMimeType($options['mimeType']); $attachmentEntity->setEncoding($options['encoding']); $attachmentEntity->setFileName($options['fileName']); $attachmentEntity->setContentId($options['contentId']); $attachmentEntity->setKey(md5($options['content'])); $attachmentContent->setContent($options['content']); $attachmentEntity->setAttachmentContent($attachmentContent); return $attachmentEntity; } catch (\Exception $e) { throw new MailEntityCreatorException("Excpetion thrown by previous exception: " . $e->getMessage(), 0, $e); } }
/** * Ensures everything works as expected. */ public function testPersistCreateUsingMessageByFind() { $messageRepository = $this->_entityManager->getRepository('\\Conjoon\\Data\\Entity\\Mail\\DefaultMessageEntity'); $repository = $this->_entityManager->getRepository('\\Conjoon\\Data\\Entity\\Mail\\DefaultAttachmentEntity'); $message = $messageRepository->findById(1); $attachment = new \Conjoon\Data\Entity\Mail\DefaultAttachmentEntity(); $attachmentContent = new \Conjoon\Data\Entity\Mail\DefaultAttachmentContentEntity(); $attachmentContent->setContent('BLOB3'); $attachment->setKey('key3'); $attachment->setMimeType('mimetype'); $attachment->setFileName('filename'); $attachment->setEncoding('encoding'); $attachment->setContentId('contentid'); $attachment->setAttachmentContent($attachmentContent); $message->addAttachment($attachment); $messageRepository->register($message); $this->assertEquals(2, $this->getConnection()->getRowCount('groupware_email_items_attachments'), "Pre-Condition"); $messageRepository->flush(); $this->assertEquals(3, $this->getConnection()->getRowCount('groupware_email_items_attachments'), "Pre-Condition"); $queryTable = $this->getConnection()->createQueryTable('groupware_email_items_attachments', 'SELECT * FROM groupware_email_items_attachments'); $expectedTable = $this->createXmlDataSet(dirname(__FILE__) . '/fixtures/mysql/attachment.addbyfind.result.xml')->getTable("groupware_email_items_attachments"); $this->assertTablesEqual($expectedTable, $queryTable); $queryTable = $this->getConnection()->createQueryTable('mail_attachment_content', 'SELECT * FROM mail_attachment_content'); $expectedTable = $this->createXmlDataSet(dirname(__FILE__) . '/fixtures/mysql/attachment.add.result.xml')->getTable("mail_attachment_content"); $this->assertTablesEqual($expectedTable, $queryTable); }