public function test()
{
$filePath = DIR_FILES . '/mail';
$subject = 'Novinky září 2009 ... a kreslící soutěž';
$from = new Email\Address('[email protected]', 'Blog.cz');
$to = [new Email\Address('[email protected]', 'Test Test1'), new Email\Address('[email protected]')];
$cc = [new Email\Address('[email protected]', 'Test Test3'), new Email\Address('[email protected]')];
$bcc = [new Email\Address('[email protected]', 'Test Test5')];
$headers = [new Email\Header('Organization', 'Blog.cz')];
$inReplyTo = '[email protected]';
$references = ['[email protected]', '[email protected]'];
$html = file_get_contents($filePath . '/email.html');
$body = new Email\Body($html, \Jyxo\Html::toText($html));
$attachments = [new Email\Attachment\FileAttachment($filePath . '/logo.gif', 'logo.gif', 'image/gif'), new Email\Attachment\StringAttachment(file_get_contents($filePath . '/star.gif'), 'star.gif', 'image/gif')];
$inlineAttachments = [new Email\Attachment\InlineFileAttachment($filePath . '/logo.gif', 'logo.gif', 'logo.gif', 'image/gif'), new Email\Attachment\InlineStringAttachment(file_get_contents($filePath . '/star.gif'), 'star.gif', 'star.gif', 'image/gif')];
// Basic settings
$email = new Email();
$email->setSubject($subject)->setFrom($from)->addReplyTo($from)->setInReplyTo($inReplyTo, $references)->setConfirmReadingTo($from);
$this->assertEquals($subject, $email->getSubject());
$this->assertSame($from, $email->getFrom());
$this->assertSame([$from], $email->getReplyTo());
$this->assertSame($from, $email->getConfirmReadingTo());
$this->assertEquals($inReplyTo, $email->getInReplyTo());
$this->assertSame($references, $email->getReferences());
// Recipients
foreach ($to as $address) {
$email->addTo($address);
}
foreach ($cc as $address) {
$email->addCc($address);
}
foreach ($bcc as $address) {
$email->addBcc($address);
}
$this->assertSame($to, $email->getTo());
$this->assertSame($cc, $email->getCc());
$this->assertSame($bcc, $email->getBcc());
// Priority
$reflection = new \ReflectionClass(\Jyxo\Mail\Email::class);
foreach ($reflection->getConstants() as $name => $value) {
if (0 === strpos($name, 'PRIORITY_')) {
$email->setPriority($value);
$this->assertEquals($value, $email->getPriority());
}
}
// Headers
foreach ($headers as $header) {
$email->addHeader($header);
}
$this->assertSame($headers, $email->getHeaders());
// Body
$email->setBody($body);
$this->assertSame($body, $email->getBody());
// Attachments
foreach ($attachments as $attachment) {
$email->addAttachment($attachment);
}
$this->assertSame($attachments, $email->getAttachments());
$this->assertFalse($email->hasInlineAttachments());
foreach ($inlineAttachments as $attachment) {
$email->addAttachment($attachment);
}
$this->assertSame(array_merge($attachments, $inlineAttachments), $email->getAttachments());
$this->assertTrue($email->hasInlineAttachments());
}